Module collections/hash_map
Hash map using SwissTable algorithm with SIMD-accelerated lookup.
Types
High-performance hash map using SwissTable algorithm.
Keys must implement Eq and Hash. Provides O(1) average lookup, insert, and delete.
Type Parameters
| Name | Type | Notes |
|---|---|---|
K | Type | comptime |
V | Type | comptime |
Trait Implementations
impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMap(K, V), ...)
_alloc_with_capacity : (fn(capacity: usize) -> Result(Self, HashMapError))Allocate memory for HashMap with given capacity Initializes all control bytes to EMPTY
Returns: Result(Self, HashMapError)
new : (fn() -> Self)Create a new empty HashMap with default capacity
Returns: Self
with_capacity : (fn(requested_capacity: usize) -> Self)Create a HashMap with a specific initial capacity Capacity will be rounded up to next power of 2
Returns: Self
_ctrl_ptr : (fn(self: Self) -> *(u8))Get ctrl pointer (unwrapped for internal use)
Returns: *(u8)
_data_ptr : (fn(self: Self) -> *(Bucket(K, V)))Get data pointer (unwrapped for internal use)
Returns: *(Bucket(K, V))
_find_bucket : (fn(self: Self, key: K, hash: u64) -> Option(usize))Find bucket index for a given key using quadratic probing Returns Some(index) if key is found, None otherwise
Returns: Option(usize)
_find_insert_bucket : (fn(self: Self, hash: u64) -> usize)Find first available bucket (EMPTY or DELETED) for insertion Returns bucket index using quadratic probing
Returns: usize
_needs_resize : (fn(self: Self) -> bool)Check if HashMap needs resizing based on load factor
Returns: bool
_resize : (fn(self: Self, new_capacity: usize) -> Result(unit, HashMapError))Resize and rehash the HashMap to a new capacity
Returns: Result(unit, HashMapError)
set : (fn(self: Self, key: K, value: V) -> Result(Option(V), HashMapError))Insert or update a key-value pair Returns Ok(Some(old_value)) if key existed, Ok(None) if new key
Returns: Result(Option(V), HashMapError)
get : (fn(self: Self, key: K) -> Option(V))Get a value by key Returns Some(value) if found, None otherwise
Returns: Option(V)
contains_key : (fn(self: Self, key: K) -> bool)Check if a key exists in the map
Returns: bool
remove : (fn(self: Self, key: K) -> Option(V))Remove a key-value pair by key Returns Some(value) if the key was found and removed, None otherwise
Returns: Option(V)
len : (fn(self: Self) -> usize)Get the number of key-value pairs in the map
Returns: usize
is_empty : (fn(self: Self) -> bool)Check if the map is empty
Returns: bool
clear : (fn(self: Self) -> unit)Clear all key-value pairs Resets all control bytes to EMPTY
Returns: unit
impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMap(K, V), Dispose(...))
dispose : (fn(self: Self) -> unit)RAII destructor - automatically called when HashMap goes out of scope
Returns: unit
impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMap(K, V), ...)
into_iter : (fn(self : Self) -> HashMapIter(K, V))Returns: HashMapIter(K, V)
impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMap(K, V), ...)
iter : (fn(self : *(Self)) -> HashMapIterPtr(K, V))Returns: HashMapIterPtr(K, V)
impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMap(K, V), ...)
keys : (fn(self : Self) -> HashMapKeys(K, V))Returns: HashMapKeys(K, V)
impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMap(K, V), ...)
values : (fn(self : Self) -> HashMapValues(K, V))Returns: HashMapValues(K, V)
impl(forall(K : Type, V : Type), HashMap(K, V), Index(K)(...))
Output : Vindex : (fn(self: *(Self), idx: K, where(K <: (Eq(K), Hash))) -> *(Self.Output))Parameters
| Name | Type | Notes |
|---|---|---|
idx | K |
Returns: *(Self.Output)
Error variants for HashMap operations.
Variants
| Variant | Fields | Description |
|---|---|---|
AllocError | error: AllocError | Memory allocation failed. |
KeyNotFound | The requested key was not found. | |
CapacityOverflow | Capacity calculation overflowed. |
Pointer iterator for HashMap - yields pointers to Bucket(K, V) Pointers are valid as long as the map is not modified during iteration.
Type Parameters
| Name | Type | Notes |
|---|---|---|
K | Type | comptime |
V | Type | comptime |
Trait Implementations
Keys iterator - wraps HashMapIter and yields only the keys
Type Parameters
| Name | Type | Notes |
|---|---|---|
K | Type | comptime |
V | Type | comptime |
Trait Implementations
impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMapKeys(K, V), Iterator(...))
Item : Knext : (fn(self : *(Self)) -> Option(K))Returns: Option(K)
Values iterator - wraps HashMapIter and yields only the values
Type Parameters
| Name | Type | Notes |
|---|---|---|
K | Type | comptime |
V | Type | comptime |
Trait Implementations
impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMapValues(K, V), Iterator(...))
Item : Vnext : (fn(self : *(Self)) -> Option(V))Returns: Option(V)