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

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

new

aspirational <map!> koru_std/map.kz:45

contains

<map> koru_std/map.kz:88

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

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

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