HashMap API Reference

Generic hash table with separate chaining collision resolution

Import

U std/hashmap

Struct

S HashMap<K, V> {
    buckets: i64,   # Bucket array pointer
    size: i64,      # Number of key-value pairs
    cap: i64        # Number of buckets
}

Methods

MethodSignatureDescription
with_capacityF with_capacity(capacity: i64) -> HashMap<K, V>Create with given bucket count
lenF len(&self) -> i64Get number of entries
capacityF capacity(&self) -> i64Get capacity
is_emptyF is_empty(&self) -> i64Check if empty
getF get(&self, key: K) -> VGet value (0 if not found)
get_optF get_opt(&self, key: K) -> Option<V>Get value as Option
containsF contains(&self, key: K) -> i64Check if key exists
setF set(&self, key: K, value: V) -> VInsert/update, returns old value
removeF remove(&self, key: K) -> VRemove key, returns value
clearF clear(&self) -> i64Remove all entries
dropF drop(&self) -> i64Free all memory

Free Functions

FunctionSignatureDescription
hashmap_newF hashmap_new() -> HashMap<i64, i64>Create with default capacity (16)

Usage

U std/hashmap

F main() -> i64 {
    m := hashmap_new()
    m.set(1, 100)
    m.set(2, 200)
    val := m.get(1)     # val = 100
    m.remove(2)
    m.drop()
    0
}