This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/2026.
Map
import std/mapstd/map — a hash map of i64 keys → i64 values, with the same owned-handle
map.kz · 8 tors
std/map — a hash map of i64 keys → i64 values, with the same owned-handle · 15 more lines
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~part each koru_std/map.each.kz
Koru Standard Library: the `each` part of map.kz. Joined via `~part each` in map.kz; merged into the module at load. Iteration (borrow — stream every pair) Traverse every key→value pair — the EFFECT SHAPE, same surface and same ruling as std/string-map:each. `! pair {k, v}` fires once per entry, `| done` delivers the pair count after. Mutating `m` inside the arm is unsafe (`set` can grow the table and invalidate the iterator); `free` is unspellable — the handle stays `<map>` borrowed for the whole extent. Iteration order is hash order — not stable, never pin output on it.
// Koru Standard Library: the `each` part of map.kz.
// Joined via `~part each` in map.kz; merged into the module at load.
//
// Iteration (borrow — stream every pair)
//
// Traverse every key→value pair — the EFFECT SHAPE, same surface and same
// ruling as std/string-map:each. `! pair {k, v}` fires once per entry,
// `| done` delivers the pair count after. Mutating `m` inside the arm is
// unsafe (`set` can grow the table and invalidate the iterator); `free` is
// unspellable — the handle stays `<map>` borrowed for the whole extent.
// Iteration order is hash order — not stable, never pin output on it.
~pub tor each { m: *Map_i64_i64<map> }
! pair { k: i64, v: i64 }
| done usize~part del koru_std/map.del.kz
Koru Standard Library: the `del` part of map.kz. Joined via `~part del` in map.kz; merged into the module at load. Deletion (borrow — obligation untouched) Remove key from the table. `value` delivers the evicted payload on a hit, `missing` on absence — `get`'s shape, minus the read. i64 keys carry no ownership, so removal is the table's business alone (string-map's sibling also frees the duped key bytes).
// Koru Standard Library: the `del` part of map.kz.
// Joined via `~part del` in map.kz; merged into the module at load.
//
// Deletion (borrow — obligation untouched)
//
// Remove key from the table. `value` delivers the evicted payload on a hit,
// `missing` on absence — `get`'s shape, minus the read. i64 keys carry no
// ownership, so removal is the table's business alone (string-map's sibling
// also frees the duped key bytes).
~pub tor del { m: *Map_i64_i64<map>, k: i64 }
| value i64
| missing~part free koru_std/map.free.kz
Koru Standard Library: the `free` part of map.kz. Joined via `~part free` in map.kz; merged into the module at load. Teardown (consume — discharges <!map>)
// Koru Standard Library: the `free` part of map.kz.
// Joined via `~part free` in map.kz; merged into the module at load.
//
// Teardown (consume — discharges <!map>)
~pub tor free { m: *Map_i64_i64<!map> }