@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.
type Deque[T] {
slots List[T?] = []
start Int = 0
size Int = 0
}Deque.size#
Number of values held. Internal state; read it with length().
size Int = 0Deque.slots#
Ring-buffer storage; null marks unused slots. Internal state: use the
operations, not this field.
slots List[T?] = []Deque.start#
Index in slots of the front value. Internal state.
start Int = 0Deque.back#
Returns the last value without removing it, or null when empty.
fn back() T?Deque.clear#
Removes every value and releases the storage.
var fn clear() VoidDeque.front#
Returns the first value without removing it, or null when empty.
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.
fn get(index Int) T?Deque.is_empty#
Reports whether the deque holds no values.
fn is_empty() BoolDeque.length#
Returns the number of values in the deque.
fn length() IntDeque.pop_back#
Removes and returns the last value, or null when empty.
var fn pop_back() T?Deque.pop_front#
Removes and returns the first value, or null when empty.
var fn pop_front() T?Deque.push_back#
Adds a value after the last one.
var fn push_back(move value T) VoidDeque.push_front#
Adds a value before the first one.
var fn push_front(move value T) VoidDeque.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.
var fn rotate(by Int) VoidDeque.to_list#
Returns a new list of copies of the values from front to back.
// Receiver: Deque[T]; T Clonable
fn to_list() List[T]