This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 8/19/2026.
Map
~import std/mapstd/map — a hash map of i64 keys → i64 values, with the same owned-handle
map.kz · 6 tors
std/map — a hash map of i64 keys → i64 values, with the same owned-handle · 15 more lines
std/map — a hash map of i64 keys → i64 values, with the same owned-handle
ownership model as std/set (map IS set-with-values: set is
AutoHashMapUnmanaged(i64, void), map is AutoHashMapUnmanaged(i64, i64)).
First cut: i64→i64 (pack composite keys — e.g. a 2D coordinate — into one i64
at the call site); genericity over the key/value types lands later by
replication (same as list / grid / set).
Backed by Zig's std.AutoHashMapUnmanaged — the hashing has no business being
in Koru and isn't; the map is the thin owned-handle surface over it, exactly
like set is over the keys-only table.
Ownership states (phantom on *Map_i64_i64):
<map!> - new issues the obligation: this map must be freed.
<map> - borrowed: set / get / contains / count, obligation untouched.
<!map> - consumed: free discharges the obligation.
Phantom lifecycles
Derived from the phantom labels in the declarations below — state! issues an
obligation the compiler will chase, !state discharges it, a bare state holds it without moving it. Nothing here is hand-drawn.
Map_i64_i64 1 state map!~[
- aspirational
The map HANDLE is heap-boxed (allocator.create(Map_i64_i64)) — escape-driven
local allocation (the no-silent-degradation doctrine) is not built yet, so this
boxes the handle unconditionally. The hash table's own storage is heap
regardless. Marked so the box debt is explicit and greppable, not hidden;
closes with the shared escape-allocation model (list / grid / set / map /
string together). The `| err` branch is the proven shape across the
collections; upgrading allocation failure to a `| ?!oom` panic branch is the
uniform follow-up across all of them (panic-branches' first collection
customers), not a map-only fork.
]pub tor new {}
| map *Map_i64_i64<map!>
| err string// Mutation (borrow — obligation untouched)
//
// Insert or overwrite key → value. Void, chains with `|>`.
~pub tor set { m: *Map_i64_i64<map>, k: i64, v: i64 }// Read (borrow)
//
// Lookup by key. `value` on hit, `missing` when absent.
~pub tor get { m: *Map_i64_i64<map>, k: i64 }
| value i64
| missing// Membership test (key present, value ignored).
~pub tor contains { m: *Map_i64_i64<map>, k: i64 }
| yes
| no// Number of distinct keys.
~pub tor count { m: *Map_i64_i64<map> } -> i64// Teardown (consume — discharges <!map>)
~pub tor free { m: *Map_i64_i64<!map> }