@std/collections/queue.ms#
Import each required symbol with import Name from "@std/collections/queue.ms".
HeapEntry Type#
A waiting value and its enqueue sequence number.
type HeapEntry[T] {
value T
order Int
}HeapEntry.order#
Enqueue sequence number; the smaller dequeues first among equal priorities. Internal state.
order IntHeapEntry.value#
The waiting value. Internal state of PriorityQueue.
value TPriorityQueue Type#
A queue whose values dequeue in their Comparable order, smallest first; equal
priorities stay first in, first out. To order by something else, wrap the value in a
record that implements Comparable. Assigning a priority queue moves it; .clone()
makes an independent queue when its elements are Clonable.
type PriorityQueue[T Comparable] {
capacity Int? = null
heap List[HeapEntry[T]] = []
next_order Int = 0
}PriorityQueue.capacity#
Maximum number of items. Omitted or null means unbounded; a capacity of zero
or below is always full.
capacity Int? = nullPriorityQueue.heap#
Binary heap of waiting values, each with its enqueue sequence number (the smaller breaks ties between equal priorities). One list, so the two never fall out of step. Internal state: use the operations, not this field.
heap List[HeapEntry[T]] = []PriorityQueue.next_order#
Next enqueue sequence number. Internal state.
next_order Int = 0PriorityQueue.dequeue#
Removes and returns the next value by priority, or null when empty.
var fn dequeue() T?PriorityQueue.enqueue#
Adds a value and returns true, or returns false when a bounded queue is full. A capacity of zero or below is always full.
var fn enqueue(move value T) BoolPriorityQueue.is_empty#
Reports whether the queue has no values to peek or dequeue.
fn is_empty() BoolPriorityQueue.length#
Returns the number of enqueued values, independent of their priorities.
fn length() IntPriorityQueue.peek#
Returns the next value by priority without removing it, or null when empty.
fn peek() T?Queue Type#
A mutable first-in, first-out queue. Assigning it moves it; .clone() makes an
independent queue when its elements are Clonable. An omitted or null capacity
means the queue grows as needed and has no limit.
type Queue[T] {
capacity Int? = null
items List[T?] = []
head Int = 0
}Queue.capacity#
Maximum number of items. Omitted or null means unbounded; a capacity of zero
or below is always full.
capacity Int? = nullQueue.head#
Index in items of the oldest value. Internal state.
head Int = 0Queue.items#
Pending values from head; null marks consumed slots. Internal state: use the
operations, not this field.
items List[T?] = []Queue.dequeue#
Removes and returns the oldest value, or null when empty.
var fn dequeue() T?Queue.enqueue#
Adds a value and returns true, or returns false when a bounded queue is full. A capacity of zero or below is always full.
var fn enqueue(move value T) BoolQueue.get#
Returns the value index places after the oldest, or null when out of range;
negative indexes count from the newest, as xs[i] does.
fn get(index Int) T?Queue.is_empty#
Reports whether dequeue and peek would return null.
fn is_empty() BoolQueue.length#
Returns the number of values currently waiting in the queue.
fn length() IntQueue.peek#
Returns the oldest value without removing it, or null when the queue is empty.
fn peek() T?