Collections API Reference

Unified re-export of all collection types plus LinkedList

Import

U std/collections

Re-exported Modules

Importing std/collections gives access to:

  • Vec<T> from std/vec
  • HashMap<K,V> from std/hashmap
  • BTreeMap<K,V> from std/btreemap
  • HashSet<T> from std/set
  • Deque<T> from std/deque
  • PriorityQueue from std/priority_queue

LinkedList

Doubly-linked list included directly in this module.

S LinkedList { head: i64, tail: i64, len: i64 }
MethodSignatureDescription
newF new() -> LinkedListCreate empty list
push_frontF push_front(&self, value: i64) -> i64Add to front
push_backF push_back(&self, value: i64) -> i64Add to back
pop_frontF pop_front(&self) -> i64Remove from front
pop_backF pop_back(&self) -> i64Remove from back
frontF front(&self) -> i64Peek at front value
backF back(&self) -> i64Peek at back value
lenF len(&self) -> i64Get length
is_emptyF is_empty(&self) -> i64Check if empty
clearF clear(&self) -> i64Remove all elements
containsF contains(&self, value: i64) -> i64Check if value exists

RingBuffer

Fixed-capacity circular buffer included directly in this module.

S RingBuffer { data: i64, capacity: i64, head: i64, tail: i64, len: i64 }
MethodSignatureDescription
newF new(capacity: i64) -> RingBufferCreate with fixed capacity
pushF push(&self, value: i64) -> i64Push to back (returns 1 if full)
popF pop(&self) -> i64Pop from front (returns 0 if empty)
frontF front(&self) -> i64Peek at front value
lenF len(&self) -> i64Get current length
is_emptyF is_empty(&self) -> i64Check if empty
is_fullF is_full(&self) -> i64Check if full
capacityF capacity(&self) -> i64Get capacity
clearF clear(&self) -> i64Remove all elements

Usage

U std/collections

F main() -> i64 {
    list := LinkedList::new()
    list.push_back(1)
    list.push_back(2)
    val := list.pop_front()  # 1
    0
}