Deque API Reference

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

Import

U std/deque

Struct

S Deque { data: i64, head: i64, tail: i64, len: i64, cap: i64 }

Methods

MethodSignatureDescription
with_capacityF with_capacity(capacity: i64) -> DequeCreate with capacity
lenF len(&self) -> i64Number of elements
capacityF capacity(&self) -> i64Allocated capacity
is_emptyF is_empty(&self) -> i64Check if empty
push_frontF push_front(&self, value: i64) -> i64Push to front
push_backF push_back(&self, value: i64) -> i64Push to back
pop_frontF pop_front(&self) -> i64Pop from front (returns 0 if empty)
pop_front_optF pop_front_opt(&self) -> Option<i64>Pop from front using Option
pop_backF pop_back(&self) -> i64Pop from back (returns 0 if empty)
pop_back_optF pop_back_opt(&self) -> Option<i64>Pop from back using Option
frontF front(&self) -> i64Peek front (returns 0 if empty)
front_optF front_opt(&self) -> Option<i64>Peek front using Option
backF back(&self) -> i64Peek back (returns 0 if empty)
back_optF back_opt(&self) -> Option<i64>Peek back using Option
getF get(&self, index: i64) -> i64Access by index (returns 0 if out of bounds)
get_optF get_opt(&self, index: i64) -> Option<i64>Access by index using Option
setF set(&self, index: i64, value: i64) -> i64Set element at index (returns 1 on success)
clearF clear(&self) -> i64Remove all
dropF drop(&self) -> i64Free memory

Free Functions

FunctionSignatureDescription
deque_newF deque_new() -> DequeCreate new Deque with default capacity (8)

Usage

U std/deque

F main() -> i64 {
    dq := deque_new()
    dq.push_back(1)
    dq.push_front(0)

    # Using basic methods
    val := dq.pop_front()  # 0

    # Using Option methods
    opt_val := dq.pop_back_opt()  # Some(1)
    empty_val := dq.pop_front_opt()  # None

    # Index access
    dq.push_back(10)
    dq.set(0, 20)
    val := dq.get(0)  # 20

    dq.drop()
    0
}