Skip to content

std::collections

Status: experimental

Built-in container types.

API details and source

The implementation source contains the complete declarations and implementation notes. The table below lists canonical Gossamer call signatures; every item name links directly to its implementation file.

Item Canonical signature or declaration Description
BTreeMap type BTreeMap Ordered key-value map backed by BTreeMap.
BTreeSet type BTreeSet Ordered unique-value set backed by BTreeSet.
MaxHeap type MaxHeap Max-priority heap; use MaxHeap::new() or MaxHeap::from([1, 2, 3]).
MinHeap type MinHeap Min-priority heap; use MinHeap::new() or MinHeap::from([1, 2, 3]).
Map type Map Key-value map backed by the swiss-table layout; literals use {key: value}.
Set type Set Unique-value set backed by a hash table; literals use #{a, b}.
Vec type Vec Growable contiguous sequence.
Deque type Deque Double-ended queue with explicit front/back methods such as push_back and pop_front; use Deque::new() or Deque::from([1, 2, 3]).
Queue type Queue FIFO-only queue; use Queue::new() or Queue::from([1, 2, 3]), then push, pop, peek, len, is_empty, and clear.
Stack type Stack LIFO-only stack; use Stack::new() or Stack::from([1, 2, 3]), then push, pop, peek, len, is_empty, and clear.
len fn len(xs: Vec<i64>) -> i64 Element count.
peek_back fn peek_back(xs: Vec<i64>) -> Option<i64> Back element, if present.
peek_front fn peek_front(xs: Vec<i64>) -> Option<i64> Front element, if present.
pop_back fn pop_back(xs: Vec<i64>) -> Vec<i64> Drop the back.
pop_front fn pop_front(xs: Vec<i64>) -> Vec<i64> Drop the front.
push_back fn push_back(xs: Vec<i64>, value: i64) -> Vec<i64> Append to the back.
push_front fn push_front(xs: Vec<i64>, value: i64) -> Vec<i64> Prepend to the front.
len fn len(xs: Vec<i64>) -> i64 Element count.
peek fn peek(xs: Vec<i64>) -> Option<i64> Smallest element of the heap, if present.
pop fn pop(xs: Vec<i64>) -> Vec<i64> Drop the root from the heap; returns the new heap (use peek first to read the value).
push fn push(xs: Vec<i64>, value: i64) -> Vec<i64> Push an i64 onto the min-heap; returns the new heap.
contains_key fn contains_key(map: OrderedMap<String, i64>, key: String) -> bool Key-membership test.
get fn get(map: OrderedMap<String, i64>, key: String) -> Option<i64> Lookup; returns 0 if absent.
insert fn insert(map: OrderedMap<String, i64>, key: String, value: i64) -> OrderedMap<String, i64> Set key => value.
len fn len(map: OrderedMap<String, i64>) -> i64 Pair count.
remove fn remove(map: OrderedMap<String, i64>, key: String) -> OrderedMap<String, i64> Remove a key.
contains fn contains(xs: OrderedSet<i64>, value: i64) -> bool Membership test.
insert fn insert(xs: OrderedSet<i64>, value: i64) -> OrderedSet<i64> Insert (sorted, no duplicates).
len fn len(xs: OrderedSet<i64>) -> i64 Element count.
remove fn remove(xs: OrderedSet<i64>, value: i64) -> OrderedSet<i64> Remove a value.
contains fn contains(xs: Vec<i64>, value: i64) -> bool Return true iff value is present.
index_of fn index_of(xs: Vec<i64>, value: i64) -> Option<i64> Return the index of value, or -1.
insert fn insert(xs: Vec<i64>, value: i64) -> Vec<i64> Insert at the unique sorted position.
len fn len(xs: Vec<i64>) -> i64 Element count.
peek_max fn peek_max(xs: Vec<i64>) -> i64 Largest element, or 0.
peek_min fn peek_min(xs: Vec<i64>) -> i64 Smallest element, or 0.
remove_at fn remove_at(xs: Vec<i64>, index: i64) -> Vec<i64> Remove the element at index i.
len fn len(xs: Vec<i64>) -> i64 Element count.
peek fn peek(xs: Vec<i64>) -> Option<i64> Front element, if present.
pop fn pop(xs: Vec<i64>) -> Vec<i64> Drop the front element; returns the new queue.
push fn push(xs: Vec<i64>, value: i64) -> Vec<i64> Append an i64 to the back; returns the new queue.
len fn len(xs: Vec<i64>) -> i64 Element count.
peek fn peek(xs: Vec<i64>) -> Option<i64> Top element, if present.
pop fn pop(xs: Vec<i64>) -> Vec<i64> Drop the top; returns the new stack.
push fn push(xs: Vec<i64>, value: i64) -> Vec<i64> Push an i64 onto the top; returns the new stack.

Set<T> methods

Set provides new, insert, remove, contains, len, is_empty, clear, iter, to_vec, union, intersection, difference, symmetric_difference, is_subset, is_superset, and is_disjoint. Use #{a, b, c} for a Set literal.

As in Rust, map is an iterator method rather than a Set method. Use set.iter().map(f). Calling set.map(f) is a type error.

BTreeSet<T> methods

BTreeSet provides the same set method surface as Set, but iteration and to_vec return values in sorted order. Use an expected type to shape a set literal:

let ordered: BTreeSet<i64> = #{3, 1, 2, 1}
println(ordered.to_vec())