This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/2026.
String Map
import std/string-mapstd/string-map — a hash map of String (byte-slice) keys → i64 values.
string-map.kz · 8 tors
std/string-map — a hash map of String (byte-slice) keys → i64 values. · 18 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_string_i64 1 state map!string carries the label <*@scoped> with no obligation attached — a dimension, not a lifecycle.
~[
- aspirational
Naive: the handle is heap-boxed AND every key is duped-and-owned (one fresh
allocation per distinct key, freed on teardown). Escape-driven allocation, a
borrow-keyed variant (keys that outlive the map, no dupe), and unification into
one generic `map` are the shared collections follow-ups. `| err` OOM is the
proven shape across collections; uniform panic-branch migration is the noted
follow-up.
]pub tor new {}
| map *Map_string_i64<map!>
| err string// Mutation (borrow — obligation untouched)
//
// Insert or overwrite key → value. Dupes the key on first insert; an overwrite
// reuses the already-stored key (no re-dupe, no leak). Void, chains with `|>`.
~pub tor set { m: *Map_string_i64<map>, k: string<*@scoped>, v: i64 }// Read (borrow)
//
// Lookup by key. `value` on hit, `missing` when absent.
~pub tor get { m: *Map_string_i64<map>, k: string<*@scoped> }
| value i64
| missing// Membership test.
~pub tor contains { m: *Map_string_i64<map>, k: string<*@scoped> }
| yes
| no// Number of distinct keys.
~pub tor count { m: *Map_string_i64<map> } -> i64~part each koru_std/string-map.each.kz
Koru Standard Library: the `each` part of string-map.kz. Joined via `~part each` in string-map.kz; merged into the module at load. Iteration (borrow — stream every pair) Traverse every key→value pair — the EFFECT SHAPE (the corpus idiom: std/fs:read-lines' `! line`, std/string:split's `! piece`, std/control:for's `! each`). `! pair {k, v}` fires once per entry, `| done` delivers the pair count after. `k` is a BORROWED view into the table's owned key bytes and `v` is a copy — no allocation, no ownership, valid for the handler's extent only (same as `split`'s pieces). Mutating `m` inside the arm is unsafe: `set` can grow the table and invalidate the Zig iterator under this traversal — insert after the sweep, not during it. (`free` inside the arm is already 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 string-map.kz.
// Joined via `~part each` in string-map.kz; merged into the module at load.
//
// Iteration (borrow — stream every pair)
//
// Traverse every key→value pair — the EFFECT SHAPE (the corpus idiom:
// std/fs:read-lines' `! line`, std/string:split's `! piece`,
// std/control:for's `! each`). `! pair {k, v}` fires once per entry,
// `| done` delivers the pair count after.
// `k` is a BORROWED view into the table's owned key bytes and `v` is a copy —
// no allocation, no ownership, valid for the handler's extent only (same as
// `split`'s pieces). Mutating `m` inside the arm is unsafe: `set` can grow
// the table and invalidate the Zig iterator under this traversal — insert
// after the sweep, not during it. (`free` inside the arm is already
// 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_string_i64<map> }
! pair { k: string, v: i64 }
| done usize~part del koru_std/string-map.del.kz
Koru Standard Library: the `del` part of string-map.kz. Joined via `~part del` in string-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. The map owns its duped keys, so a hit frees the stored key bytes here rather than leaving them for `free` to sweep; a delete is real removal, not a tombstone the program has to spell in band.
// Koru Standard Library: the `del` part of string-map.kz.
// Joined via `~part del` in string-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. The map owns its
// duped keys, so a hit frees the stored key bytes here rather than leaving
// them for `free` to sweep; a delete is real removal, not a tombstone the
// program has to spell in band.
~pub tor del { m: *Map_string_i64<map>, k: string<*@scoped> }
| value i64
| missing~part free koru_std/string-map.free.kz
Koru Standard Library: the `free` part of string-map.kz. Joined via `~part free` in string-map.kz; merged into the module at load. Teardown (consume — discharges <!map>)
// Koru Standard Library: the `free` part of string-map.kz.
// Joined via `~part free` in string-map.kz; merged into the module at load.
//
// Teardown (consume — discharges <!map>)
~pub tor free { m: *Map_string_i64<!map> }