Manuscript Documentation
v2026.12.0

@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.

Manuscript
type HeapEntry[T] {
    value T
    order Int
}

HeapEntry.order#

Enqueue sequence number; the smaller dequeues first among equal priorities. Internal state.

Manuscript
order Int

HeapEntry.value#

The waiting value. Internal state of PriorityQueue.

Manuscript
value T

PriorityQueue 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.

Manuscript
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.

Manuscript
capacity Int? = null

PriorityQueue.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.

Manuscript
heap List[HeapEntry[T]] = []

PriorityQueue.next_order#

Next enqueue sequence number. Internal state.

Manuscript
next_order Int = 0

PriorityQueue.dequeue#

Removes and returns the next value by priority, or null when empty.

Manuscript
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.

Manuscript
var fn enqueue(move value T) Bool

PriorityQueue.is_empty#

Reports whether the queue has no values to peek or dequeue.

Manuscript
fn is_empty() Bool

PriorityQueue.length#

Returns the number of enqueued values, independent of their priorities.

Manuscript
fn length() Int

PriorityQueue.peek#

Returns the next value by priority without removing it, or null when empty.

Manuscript
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.

Manuscript
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.

Manuscript
capacity Int? = null

Queue.head#

Index in items of the oldest value. Internal state.

Manuscript
head Int = 0

Queue.items#

Pending values from head; null marks consumed slots. Internal state: use the operations, not this field.

Manuscript
items List[T?] = []

Queue.dequeue#

Removes and returns the oldest value, or null when empty.

Manuscript
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.

Manuscript
var fn enqueue(move value T) Bool

Queue.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.

Manuscript
fn get(index Int) T?

Queue.is_empty#

Reports whether dequeue and peek would return null.

Manuscript
fn is_empty() Bool

Queue.length#

Returns the number of values currently waiting in the queue.

Manuscript
fn length() Int

Queue.peek#

Returns the oldest value without removing it, or null when the queue is empty.

Manuscript
fn peek() T?