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-map

std/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
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!

string carries the label <*@scoped> with no obligation attached — a dimension, not a lifecycle.

new

aspirational <map!> koru_std/string-map.kz:50

set

<map><*@scoped> koru_std/string-map.kz:69

get

<map><*@scoped> koru_std/string-map.kz:88

contains

<map><*@scoped> koru_std/string-map.kz:100

~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.

~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.

del

<map><*@scoped> koru_std/string-map.del.kz:13

~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>)