ImmutablePriorityQueue
Edit on GitHubAn immutable priority queue. A priority queue is a data structure that maintains elements in a priority order. Elements with higher priority are served before elements with lower priority when extracting from the priority queue.
Added in 0.5.3
No other changes yet.
Types
Type declarations included in the ImmutablePriorityQueue module.
ImmutablePriorityQueue.ImmutablePriorityQueue
Immutable data structure which maintains a priority order for its elements.
Values
Functions and constants for working with ImmutablePriorityQueues.
ImmutablePriorityQueue.empty
Added in 0.5.4
No other changes yet.
An empty priority queue with the default compare
comparator.
ImmutablePriorityQueue.make
Added in 0.5.3
No other changes yet.
Creates a new priority queue with a comparator function, which is used to determine priority of elements. The comparator function takes two elements and must return 0 if both share priority, a positive number if the first has greater priority, and a negative number if the first has less priority.
Parameters:
param | type | description |
---|---|---|
comp |
(a, a) -> Number |
The comparator function used to indicate priority order |
Returns:
type | description |
---|---|
ImmutablePriorityQueue<a> |
An empty priority queue |
Examples:
1 | ImmutablePriorityQueue.make(compare) // creates a min priority queue of numbers using the compare pervasive |
1 | ImmutablePriorityQueue.make((a, b) => String.length(b) - String.length(a)) // creates a priority queue by string length (longest to shortest) |
ImmutablePriorityQueue.size
Added in 0.5.3
No other changes yet.
Gets the number of elements in a priority queue.
Parameters:
param | type | description |
---|---|---|
pq |
ImmutablePriorityQueue<a> |
The priority queue to inspect |
Returns:
type | description |
---|---|
Number |
The number of elements in the priority queue |
ImmutablePriorityQueue.isEmpty
Added in 0.5.3
No other changes yet.
Determines if the priority queue contains no elements.
Parameters:
param | type | description |
---|---|---|
pq |
ImmutablePriorityQueue<a> |
The priority queue to check |
Returns:
type | description |
---|---|
Bool |
true if the priority queue is empty and false otherwise |
ImmutablePriorityQueue.push
Produces a new priority queue by inserting the given element into the given priority queue.
Parameters:
param | type | description |
---|---|---|
val |
a |
The value to add into the priority queue |
pq |
ImmutablePriorityQueue<a> |
The priority queue |
Returns:
type | description |
---|---|
ImmutablePriorityQueue<a> |
A new priority queue with the given element inserted |
ImmutablePriorityQueue.peek
Added in 0.5.3
No other changes yet.
Retrieves the highest priority element in the priority queue. It is not removed from the queue.
Parameters:
param | type | description |
---|---|---|
pq |
ImmutablePriorityQueue<a> |
The priority queue to inspect |
Returns:
type | description |
---|---|
Option<a> |
Some(value) containing the highest priority element or None if the priority queue is empty |
ImmutablePriorityQueue.pop
Added in 0.5.3
No other changes yet.
Produces a new priority queue without the highest priority element in the given priority queue. If the input priority queue is empty, this function will return it.
Parameters:
param | type | description |
---|---|---|
pq |
ImmutablePriorityQueue<a> |
The priority queue |
Returns:
type | description |
---|---|
ImmutablePriorityQueue<a> |
A new priority queue without the highest priority element |
ImmutablePriorityQueue.drain
Added in 0.5.3
No other changes yet.
Produces a list of all elements in the priority queue in priority order.
Parameters:
param | type | description |
---|---|---|
pq |
ImmutablePriorityQueue<a> |
The priority queue to drain |
Returns:
type | description |
---|---|
List<a> |
A list of all elements in the priority in priority order |
ImmutablePriorityQueue.fromList
Added in 0.5.3
No other changes yet.
Constructs a new priority queue initialized with the elements in the list using a custom comparator function, which is used to determine priority of elements. The comparator function takes two elements and must return 0 if both share priority, a positive number if the first has greater priority, and a negative number if the first has less priority.
Parameters:
param | type | description |
---|---|---|
list |
List<a> |
A list of values used to initialize the priority queue |
comp |
(a, a) -> Number |
A comparator function used to assign priority to elements |
Returns:
type | description |
---|---|
ImmutablePriorityQueue<a> |
A priority queue containing the elements from the list |
ImmutablePriorityQueue.fromArray
Added in 0.5.4
No other changes yet.
Constructs a new priority queue initialized with the elements in the array using a custom comparator function, which is used to determine priority of elements. The comparator function takes two elements and must return 0 if both share priority, a positive number if the first has greater priority, and a negative number if the first has less priority.
Parameters:
param | type | description |
---|---|---|
array |
Array<a> |
An array of values used to initialize the priority queue |
comp |
(a, a) -> Number |
A comparator function used to assign priority to elements |
Returns:
type | description |
---|---|
ImmutablePriorityQueue<a> |
A priority queue containing the elements from the array |