This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 8/19/2026.
Set
~import std/setstd/set — a hash set of i64 keys, with the same owned-handle ownership model
set.kz · 5 tors
std/set — a hash set of i64 keys, with the same owned-handle ownership model
as std/list and std/grid. First cut: i64 keys (pack composite keys — e.g. a
2D coordinate — into one i64 at the call site); genericity over the key type,
and a String-keyed sibling, land later by replication (same as list/grid).
Backed by Zig's std.AutoHashMapUnmanaged — the hashing has no business being
in Koru and isn't; the set is the thin owned-handle surface over it, exactly
like grid is over a flat buffer.
Ownership states (phantom on *Set_i64):
<set!> - new issues the obligation: this set must be freed.
<set> - borrowed: add / contains / count, obligation untouched.
<!set> - 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.
Set_i64 1 state set!~[
- aspirational
The set HANDLE is heap-boxed (allocator.create(Set_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 / string together).
]pub tor new {}
| set *Set_i64<set!>
| err string// Mutation (borrow — obligation untouched)
//
// Add a key (idempotent — adding a present key is a no-op). Void, chains with `|>`.
~pub tor add { s: *Set_i64<set>, v: i64 }// Read (borrow)
//
// Membership test.
~pub tor contains { s: *Set_i64<set>, v: i64 }
| yes
| no// Number of distinct keys.
~pub tor count { s: *Set_i64<set> } -> i64// Teardown (consume — discharges <!set>)
~pub tor free { s: *Set_i64<!set> }