Module collections/deque

collections/deque

Double-ended queue (ring buffer) with O(1) push/pop at both ends.

Example

{ Deque } :: import "std/collections/deque";

d := Deque(i32).new();
d.push_back(1);
d.push_front(0);
x := d.pop_front().unwrap();  // 0

Types

Deque type-function
fn(T : Type) -> Type

Circular buffer supporting efficient push/pop at both front and back.

Type Parameters

NameTypeNotes
TTypecomptime

Trait Implementations

Dispose Index Trace
impl(generic(T : Type), Deque(T), ...)
new : (fn() -> Self)

Returns: Self

len : (fn(self : Self) -> usize)

Returns: usize

is_empty : (fn(self : Self) -> bool)

Returns: bool

_grow : (fn(self : Self, min_cap : usize) -> unit)

Returns: unit

push_back : (fn(self : Self, val : T) -> unit)

Returns: unit

push_front : (fn(self : Self, val : T) -> unit)

Returns: unit

pop_front : (fn(self : Self) -> ?(T))

Returns: ?(T)

pop_back : (fn(self : Self) -> ?(T))

Returns: ?(T)

get : (fn(self : Self, index : usize) -> ?(T))

Returns: ?(T)

impl(generic(T : Type), Deque(T), Dispose(...))
dispose : (fn(self : Self) -> unit)

Returns: unit

impl(generic(T : Type), Deque(T), ...)
into_iter : (fn(self : Self) -> DequeIter(T))

Returns: DequeIter(T)

impl(generic(T : Type), Deque(T), ...)
iter : (fn(self : Self) -> DequeIterPtr(T))

Returns: DequeIterPtr(T)

impl(generic(T : Type), Deque(T), Index(usize)(...))
Output : T
index : (fn(inout(self) : Self, idx : usize) -> *(Self.Output))

Parameters

NameTypeNotes
idxusize

Returns: *(Self.Output)

impl(generic(T : Type), Deque(T), Trace(...))
trace : (fn(self : Self, tracer : GcTracer) -> unit)

Cycle-GC tracing. The elements live in a malloc'd ring buffer the compiler's auto-derived field walk cannot reach, so trace each live element's buffer slot. Logical element k (0 = front) sits at physical slot (_head + k) % _capacity. tracer.visit takes the slot POINTER and reads it WITHOUT touching the element's reference count (a by-value managed handle would be dup'd then dropped, freeing a live element mid-collection). Mirrors the ArrayList Trace impl.

Parameters

NameTypeNotes
tracerGcTracer

Returns: unit

DequeIter type-function
fn(T : Type) -> Type

Value iterator for Deque - yields elements by value (T) Traverses the circular buffer in logical order.

Type Parameters

NameTypeNotes
TTypecomptime

Trait Implementations

Iterator
impl(generic(T : Type), DequeIter(T), Iterator(...))
Item : T
next : (fn(inout(self) : Self) -> Option(T))

Returns: Option(T)

DequeIterPtr type-function
fn(T : Type) -> Type

Pointer iterator for Deque - yields pointers to elements (*(T)) Yields pointers into the circular buffer. Pointers are valid as long as the deque is not modified during iteration.

Type Parameters

NameTypeNotes
TTypecomptime

Trait Implementations

Iterator
impl(generic(T : Type), DequeIterPtr(T), Iterator(...))
Item : *(T)
next : (fn(inout(self) : Self) -> Option(*(T)))

Returns: Option(*(T))