ListAllocError
pub enum ListAllocError = { OutOfMemory }Variants
OutOfMemory
fn copy_cstr_in[A: allocators.GeneralAllocator](ac: A, src: ref u8) option[ref u8]pub enum ListAllocError = { OutOfMemory }OutOfMemorytype PtrList = { ptr: ref void, len: usize, cap: usize }An unsafe list for storing values of any type as untyped pointers (ref void).
| Name | Type |
|---|---|
ptr | ref void |
len | usize |
cap | usize |
pub fn (PtrList) new[A: allocators.GeneralAllocator](ac: A, initial_cap: usize) result[ref void, ListAllocError]Allocate a new PtrList with the given initial capacity.
pub fn (PtrList) free[A: allocators.GeneralAllocator](ac: A, list: mut PtrList) voidFree a PtrList and its backing buffer.
pub fn (PtrList) len(list: PtrList) usizeReturn the number of elements in the list.
pub fn (PtrList) cap(list: PtrList) usizeReturn the current capacity.
fn (PtrList) grow[A: allocators.GeneralAllocator](ac: A, list: mut PtrList, new_cap: usize) result[void, ListAllocError]Grow the backing buffer to at least new_cap elements. Requires new_cap > 0 to avoid a zero-size allocation.
pub fn (PtrList) push[A: allocators.GeneralAllocator](ac: A, list: mut PtrList, value: usize) result[void, ListAllocError]Append a value to the end of the list. Requires the list pointer to be non-null (non-zero).
pub fn (PtrList) get(list: PtrList, i: usize) option[usize]Get the element at index i. Requires i < len to guarantee in-bounds access. Returns none if out of bounds (defensive, belt-and-suspenders).
pub fn (PtrList) set(list: PtrList, i: usize, value: usize) usizeSet the element at index i. Requires i < len to guarantee in-bounds write. Returns 1 on success, 0 if out of bounds (defensive).
pub fn (PtrList) pop(list: PtrList) option[usize]Pop the last element. Requires the list to be non-empty.
pub type Map = { header: ref void }| Name | Type |
|---|---|
header | ref void |
pub type StringMap = { header: ref void }| Name | Type |
|---|---|
header | ref void |
pub fn hash_identity(key: usize) usizeDefault identity hash for integer keys.
pub fn (Map) new[A: allocators.GeneralAllocator](ac: A, initial_cap: usize, hash_fn: ref void) MapAllocate a new Map with the given initial capacity and hash function. initial_cap must be > 0.
pub fn (Map) free[A: allocators.GeneralAllocator](ac: A, map: Map) voidFree the map and its backing bucket array.
pub fn (Map) len(map: Map) usizeReturn the number of live entries.
pub fn (Map) cap(map: Map) usize = trust { ... }Return the current bucket capacity.
fn (Map) grow[A: allocators.GeneralAllocator](ac: A, map: mut Map, new_cap: usize) voidInternal: grow the map to new_cap buckets and rehash all live entries.
pub fn (Map) set[A: allocators.GeneralAllocator](ac: A, map: mut Map, key: usize, value: usize) voidInsert or update a key-value pair. Grows the map (2x + 1) when load factor exceeds 70%.
pub fn (Map) get(map: Map, key: usize) option[usize]Look up a key. Returns some(value) if found, none otherwise.
pub fn (Map) delete(map: Map, key: usize) usize = trust { ... }Remove a key. Returns 1 if the key was present, 0 otherwise.
pub fn (Map) contains(map: Map, key: usize) boolCheck if a key exists in the map.
pub fn (Map) clear(map: Map) voidClear all entries (reset to empty, keep allocation).
pub fn hash_string(key: ref u8) usizeA hash map with ref u8 (C string) keys and usize values.
Built on top of Map using a djb2 string hash. Casts the string pointer to usize for use as a Map key seed, then hashes the actual bytes so distinct strings with the same address never collide.
fn str_eq(a: ref u8, b: ref u8) bool = trust { ... }Compare two null-terminated C strings for equality.
pub fn (StringMap) new[A: allocators.GeneralAllocator](ac: A, initial_cap: usize) StringMapAllocate a new StringMap with the given initial capacity.
pub fn (StringMap) set[A: allocators.GeneralAllocator](ac: A, map: StringMap, key: ref u8, value: usize) voidInsert or update a string key with a usize value.
The key is copied onto the heap; the copy is owned by the map.
pub fn (StringMap) get(map: StringMap, key: ref u8) option[usize]Look up a string key. Returns some(value) or none.
pub fn (StringMap) contains(map: StringMap, key: ref u8) boolCheck if a string key exists.
pub fn (StringMap) delete[A: allocators.GeneralAllocator](ac: A, map: StringMap, key: ref u8) usizeRemove a string key. Returns 1 if found and removed, 0 otherwise.
pub fn (StringMap) len(map: StringMap) usizeReturn the number of live entries.
pub fn (StringMap) free[A: allocators.GeneralAllocator](ac: A, map: StringMap) voidFree all heap-copied keys, then free the map itself.
type IndexMap = { inner_header: ref void, keys: ref void }An insertion-order preserving map with ref u8 keys and usize values.
Implemented as a StringMap for O(1) lookup plus a PtrList of keys to track insertion order.
| Name | Type |
|---|---|
inner_header | ref void |
keys | ref void |
type RawIndexMap = { }pub fn (IndexMap) new[A: allocators.GeneralAllocator](ac: A, initial_cap: usize) IndexMapAllocate a new IndexMap with the given initial capacity.
pub fn (IndexMap) set[A: allocators.GeneralAllocator](ac: A, map: IndexMap, key: ref u8, value: usize) voidInsert or update a key-value pair, preserving insertion order for new keys.
pub fn (IndexMap) get(map: IndexMap, key: ref u8) option[usize] = trust { ... }Look up a key. Returns some(value) or none.
pub fn (IndexMap) contains(map: IndexMap, key: ref u8) boolCheck if a key exists.
pub fn (IndexMap) delete[A: allocators.GeneralAllocator](ac: A, map: IndexMap, key: ref u8) usizeRemove a key. Returns 1 if found, 0 otherwise. Note: removal marks the key as a tombstone in the ordered list (sets to 0).
pub fn (IndexMap) len(map: IndexMap) usizeReturn the number of live entries.
pub fn (IndexMap) each(map: IndexMap, cb: fn(ref u8, usize) void) void = trust { ... }Iterate in insertion order. Calls callback(key, value) for each live entry.
pub fn (IndexMap) key_at(map: IndexMap, i: usize) option[ref u8]Get the i-th key in insertion order (skipping tombstones). Returns none if out of range.
pub fn (IndexMap) free[A: allocators.GeneralAllocator](ac: A, map: IndexMap) voidFree the IndexMap and all owned key copies.
pub fn (RawIndexMap) new(initial_cap: usize) ref void = trust { ... }pub fn (RawIndexMap) set(map: ref void, key: ref u8, value: usize) void = trust { ... }pub fn (RawIndexMap) get(map: ref void, key: ref u8) option[usize] = trust { ... }pub fn (RawIndexMap) contains(map: ref void, key: ref u8) boolpub fn (RawIndexMap) delete(map: ref void, key: ref u8) usize = trust { ... }pub fn (RawIndexMap) len(map: ref void) usizepub fn (RawIndexMap) each(map: ref void, cb: fn(ref u8, usize) void) void = trust { ... }pub fn (RawIndexMap) key_at(map: ref void, i: usize) option[ref u8]pub fn (RawIndexMap) free(map: ref void) void = trust { ... }