Module collections/hash_map

collections/hash_map

Hash map using SwissTable algorithm with SIMD-accelerated lookup.

Types

HashMap type-function
fn(comptime(K) : Type, comptime(V) : Type) -> (comptime(fn_return_yo3fa6ab65_id_108) : Type)

High-performance hash map using SwissTable algorithm. Keys must implement Eq and Hash. Provides O(1) average lookup, insert, and delete.

Type Parameters

NameTypeNotes
KTypecomptime
VTypecomptime

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 : V
index : (fn(self: *(Self), idx: K, where(K <: (Eq(K), Hash))) -> *(Self.Output))

Parameters

NameTypeNotes
idxK

Returns: *(Self.Output)

HashMapError

Error variants for HashMap operations.

Variants

VariantFieldsDescription
AllocErrorerror: AllocError

Memory allocation failed.

KeyNotFound

The requested key was not found.

CapacityOverflow

Capacity calculation overflowed.

Bucket type-function
fn(comptime(K) : Type, comptime(V) : Type) -> (comptime(fn_return_yo3fa6ab65_id_53) : Type)

Key-value pair stored in a hash map bucket.

Type Parameters

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

Value iterator for HashMap - yields Bucket(K, V) by value Scans ctrl bytes to find occupied slots.

Type Parameters

NameTypeNotes
KTypecomptime
VTypecomptime

Trait Implementations

impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMapIter(K, V), Iterator(...))
Item : Bucket(K, V)
next : (fn(self : *(Self)) -> Option(Bucket(K, V)))

Returns: Option(Bucket(K, V))

HashMapIterPtr type-function
fn(comptime(K) : Type, comptime(V) : Type) -> (comptime(fn_return_yo3fa6ab65_id_618) : Type)

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

NameTypeNotes
KTypecomptime
VTypecomptime

Trait Implementations

impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMapIterPtr(K, V), Iterator(...))
Item : *(Bucket(K, V))
next : (fn(self : *(Self)) -> Option(*(Bucket(K, V))))

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

HashMapKeys type-function
fn(comptime(K) : Type, comptime(V) : Type) -> (comptime(fn_return_yo3fa6ab65_id_883) : Type)

Keys iterator - wraps HashMapIter and yields only the keys

Type Parameters

NameTypeNotes
KTypecomptime
VTypecomptime

Trait Implementations

impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMapKeys(K, V), Iterator(...))
Item : K
next : (fn(self : *(Self)) -> Option(K))

Returns: Option(K)

HashMapValues type-function
fn(comptime(K) : Type, comptime(V) : Type) -> (comptime(fn_return_yo3fa6ab65_id_1214) : Type)

Values iterator - wraps HashMapIter and yields only the values

Type Parameters

NameTypeNotes
KTypecomptime
VTypecomptime

Trait Implementations

impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMapValues(K, V), Iterator(...))
Item : V
next : (fn(self : *(Self)) -> Option(V))

Returns: Option(V)