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_109) : 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_ptr : (fn(self : Self) -> HashMapIterPtr(K, V))

Pointer iterator — yields *(Bucket(K, V)) for each occupied bucket. Kept as a separate method (not iter()) so the Phase D for-macro's coll.iter() call dispatches to the position-iter variant defined later in the file, enabling for(map, ref(b) => body).

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

Parameters

NameTypeNotes
idxK

Returns: *(Self.Output)

impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMap(K, V), Indexable(usize)(...))
Element : Bucket(K, V)
project : (fn(ref(self) : Self, pos : usize) -> ref(Bucket(K, V)))

Parameters

NameTypeNotes
posusize

Returns: ref(Bucket(K, V))

impl(forall(K : Type, V : Type), where(K <: (Eq(K), Hash)), HashMap(K, V), ...)
iter : (fn(self : Self) -> HashMapPosIter(K, V))

Returns: HashMapPosIter(K, V)

impl(forall(K : Type, V : Type), where(K <: (Clone, Eq(K), Hash), V <: Clone), HashMap(K, V), Clone(...))
clone : (fn(ref(self) : Self) -> Self)

Returns: Self

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_54) : 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_402) : 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(ref(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_670) : 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(ref(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_938) : 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(ref(self) : Self) -> Option(K))

Returns: Option(K)

HashMapValues type-function
fn(comptime(K) : Type, comptime(V) : Type) -> (comptime(fn_return_yo3fa6ab65_id_1272) : 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(ref(self) : Self) -> Option(V))

Returns: Option(V)

Functions

hash_map function
fn(...(quote(entries))) -> (unquote(fn_return_yo3fa6ab65_id_2064) : Expr)

hash_map macro — construct a HashMap(K, V) literal.

K and V are inferred from the first entry's key and value via typeof, so at least one entry is required.

Example

m := hash_map(`a` => i32(1), `b` => i32(2));

Returns: Expr