Manuscript Documentation
v2026.12.0

@std/collections/deque.ms#

Import each required symbol with import Name from "@std/collections/deque.ms".

Deque Type#

A growable double-ended queue: O(1) amortized push and pop at both ends and O(1) indexed reads. Use .clone() for an independent deque when its elements are Clonable; assigning a deque moves it. Use Queue for plain first-in, first-out work, and Deque when either end is pushed or popped, such as a sliding window or work stealing.

Manuscript
type Deque[T] {
    slots List[T?] = []
    start Int = 0
    size Int = 0
}

Deque.size#

Number of values held. Internal state; read it with length().

Manuscript
size Int = 0

Deque.slots#

Ring-buffer storage; null marks unused slots. Internal state: use the operations, not this field.

Manuscript
slots List[T?] = []

Deque.start#

Index in slots of the front value. Internal state.

Manuscript
start Int = 0

Deque.back#

Returns the last value without removing it, or null when empty.

Manuscript
fn back() T?

Deque.clear#

Removes every value and releases the storage.

Manuscript
var fn clear() Void

Deque.front#

Returns the first value without removing it, or null when empty.

Manuscript
fn front() T?

Deque.get#

Returns the value at index counted from the front, or null when out of range; negative indexes count from the back, as xs[i] does.

Manuscript
fn get(index Int) T?

Deque.is_empty#

Reports whether the deque holds no values.

Manuscript
fn is_empty() Bool

Deque.length#

Returns the number of values in the deque.

Manuscript
fn length() Int

Deque.pop_back#

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

Manuscript
var fn pop_back() T?

Deque.pop_front#

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

Manuscript
var fn pop_front() T?

Deque.push_back#

Adds a value after the last one.

Manuscript
var fn push_back(move value T) Void

Deque.push_front#

Adds a value before the first one.

Manuscript
var fn push_front(move value T) Void

Deque.rotate#

Turns the deque like a ring buffer. Moves by values from the front to the back, one at a time, so the value by places in becomes the front; a negative by moves values from the back to the front. Any magnitude is reduced modulo the length, and an empty deque is unchanged. Example: with 1, 2, 3, 4 queued, rotate(1) leaves 2, 3, 4, 1.

Manuscript
var fn rotate(by Int) Void

Deque.to_list#

Returns a new list of copies of the values from front to back.

Manuscript
// Receiver: Deque[T]; T Clonable
fn to_list() List[T]