Module 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
Sorted map maintaining entries in key order. Provides ordered iteration and O(log n) lookup via binary search. Insert is O(n).
Type Parameters
| Name | Type | Notes |
|---|---|---|
K | Type | comptime |
V | Type | comptime |
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 : Vindex : (fn(self: *(Self), idx: K, where(K <: Ord(K))) -> *(Self.Output))Parameters
| Name | Type | Notes |
|---|---|---|
idx | K |
Returns: *(Self.Output)
Value iterator for BTreeMap - yields BTreeEntry(K, V) in sorted key order
Type Parameters
| Name | Type | Notes |
|---|---|---|
K | Type | comptime |
V | Type | comptime |
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))
Pointer iterator for BTreeMap - yields pointers to BTreeEntry(K, V) in sorted key order
Type Parameters
| Name | Type | Notes |
|---|---|---|
K | Type | comptime |
V | Type | comptime |
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)))
Keys iterator - wraps BTreeMapIter and yields only keys in sorted order
Type Parameters
| Name | Type | Notes |
|---|---|---|
K | Type | comptime |
V | Type | comptime |
Trait Implementations
impl(forall(K : Type, V : Type), BTreeMapKeys(K, V), Iterator(...))
Item : Knext : (fn(self : *(Self)) -> Option(K))Returns: Option(K)
Values iterator - wraps BTreeMapIter and yields only values in sorted key order
Type Parameters
| Name | Type | Notes |
|---|---|---|
K | Type | comptime |
V | Type | comptime |
Trait Implementations
impl(forall(K : Type, V : Type), BTreeMapValues(K, V), Iterator(...))
Item : Vnext : (fn(self : *(Self)) -> Option(V))Returns: Option(V)