This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 8/19/2026.
String Map
~import std/string-mapstd/string-map — a hash map of String (byte-slice) keys → i64 values.
string-map.kz · 6 tors
std/string-map — a hash map of String (byte-slice) keys → i64 values. · 18 more lines
std/string-map — a hash map of String (byte-slice) keys → i64 values.
NAIVE-PHASE SHAPE, pinned deliberately. The IDEAL surface is one generic
`std/map` whose key/value types are chosen at construction (`map:new(string,
i64)`) with ops that dispatch on the handle's concrete type. Koru can't
express that yet: events lower to a `<name>_event` struct member keyed by
NAME ONLY, so a second `set`/`get`/`free` (string-typed) in the `map` module
collides ("duplicate struct member name"). There is no overload-by-handle-type
and no type registry for the call site to resolve against — that is THE pinned
dispatch gap (see 660_024). Until it's built, a String-keyed map lives in its
own module with its own clean op surface (`string-map:set(m, k, v)`), rather
than contorting call sites with hash-to-i64 workarounds. The naivety is here in
the Zig impl (boxed handle, dupe-and-own keys), not in the .k that uses it.
Ownership states (phantom on *Map_string_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 (and frees the duped keys).
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!~[
- 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, v: i64 }// Read (borrow)
//
// Lookup by key. `value` on hit, `missing` when absent.
~pub tor get { m: *Map_string_i64<map>, k: string }
| value i64
| missing// Membership test.
~pub tor contains { m: *Map_string_i64<map>, k: string }
| yes
| no// Number of distinct keys.
~pub tor count { m: *Map_string_i64<map> } -> i64// Teardown (consume — discharges <!map>)
~pub tor free { m: *Map_string_i64<!map> }