Module collections/btree_map

collections/btree_map

Sorted map backed by a sorted array with O(log n) lookup via binary search.

Example

{ BTreeMap } :: import "std/collections/btree_map";

m := BTreeMap(String, i32).new();
m.set(String.from("b"), 2);
m.set(String.from("a"), 1);
// Iteration order: a, b

Types

BTreeEntry type-function
fn(comptime(K) : Type, comptime(V) : Type) -> (comptime(fn_return_yo26359338_id_33) : Type)

Key-value pair entry stored in a BTreeMap.

Type Parameters

NameTypeNotes
KTypecomptime
VTypecomptime
BTreeMap type-function
fn(comptime(K) : Type, comptime(V) : Type) -> (comptime(fn_return_yo26359338_id_105) : Type)

Sorted map maintaining entries in key order. Provides ordered iteration and O(log n) lookup via binary search. Insert is O(n).

Type Parameters

NameTypeNotes
KTypecomptime
VTypecomptime

Trait Implementations

impl(forall(K : Type, V : Type), BTreeMap(K, V), ...)
new : (fn() -> Self)

Returns: Self

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

Returns: usize

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

Returns: bool

_find : (fn(self: Self, k: K, where(K <: Ord(K))) -> _FindResult)

Returns: _FindResult

get : (fn(self: Self, k: K, where(K <: Ord(K))) -> ?V)

Returns: ?V

set : (fn(self: Self, k: K, v: V, where(K <: Ord(K))) -> unit)

Returns: unit

remove : (fn(self: Self, k: K, where(K <: Ord(K))) -> ?V)

Returns: ?V

min : (fn(self: Self) -> ?BTreeEntry(K, V))

Returns: ?BTreeEntry(K, V)

max : (fn(self: Self) -> ?BTreeEntry(K, V))

Returns: ?BTreeEntry(K, V)

impl(forall(K : Type, V : Type), BTreeMap(K, V), ...)
into_iter : (fn(self : Self) -> BTreeMapIter(K, V))

Returns: BTreeMapIter(K, V)

impl(forall(K : Type, V : Type), BTreeMap(K, V), ...)
iter : (fn(self : *(Self)) -> BTreeMapIterPtr(K, V))

Returns: BTreeMapIterPtr(K, V)

impl(forall(K : Type, V : Type), BTreeMap(K, V), ...)
keys : (fn(self : Self) -> BTreeMapKeys(K, V))

Returns: BTreeMapKeys(K, V)

impl(forall(K : Type, V : Type), BTreeMap(K, V), ...)
values : (fn(self : Self) -> BTreeMapValues(K, V))

Returns: BTreeMapValues(K, V)

impl(forall(K : Type, V : Type), BTreeMap(K, V), Index(K)(...))
Output : V
index : (fn(self: *(Self), idx: K, where(K <: Ord(K))) -> *(Self.Output))

Parameters

NameTypeNotes
idxK

Returns: *(Self.Output)

BTreeMapIter type-function
fn(comptime(K) : Type, comptime(V) : Type) -> (comptime(fn_return_yo26359338_id_265) : Type)

Value iterator for BTreeMap - yields BTreeEntry(K, V) in sorted key order

Type Parameters

NameTypeNotes
KTypecomptime
VTypecomptime

Trait Implementations

impl(forall(K : Type, V : Type), BTreeMapIter(K, V), Iterator(...))
Item : BTreeEntry(K, V)
next : (fn(self : *(Self)) -> Option(BTreeEntry(K, V)))

Returns: Option(BTreeEntry(K, V))

BTreeMapIterPtr type-function
fn(comptime(K) : Type, comptime(V) : Type) -> (comptime(fn_return_yo26359338_id_486) : Type)

Pointer iterator for BTreeMap - yields pointers to BTreeEntry(K, V) in sorted key order

Type Parameters

NameTypeNotes
KTypecomptime
VTypecomptime

Trait Implementations

impl(forall(K : Type, V : Type), BTreeMapIterPtr(K, V), Iterator(...))
Item : *(BTreeEntry(K, V))
next : (fn(self : *(Self)) -> Option(*(BTreeEntry(K, V))))

Returns: Option(*(BTreeEntry(K, V)))

BTreeMapKeys type-function
fn(comptime(K) : Type, comptime(V) : Type) -> (comptime(fn_return_yo26359338_id_707) : Type)

Keys iterator - wraps BTreeMapIter and yields only keys in sorted order

Type Parameters

NameTypeNotes
KTypecomptime
VTypecomptime

Trait Implementations

impl(forall(K : Type, V : Type), BTreeMapKeys(K, V), Iterator(...))
Item : K
next : (fn(self : *(Self)) -> Option(K))

Returns: Option(K)

BTreeMapValues type-function
fn(comptime(K) : Type, comptime(V) : Type) -> (comptime(fn_return_yo26359338_id_994) : Type)

Values iterator - wraps BTreeMapIter and yields only values in sorted key order

Type Parameters

NameTypeNotes
KTypecomptime
VTypecomptime

Trait Implementations

impl(forall(K : Type, V : Type), BTreeMapValues(K, V), Iterator(...))
Item : V
next : (fn(self : *(Self)) -> Option(V))

Returns: Option(V)