These libraries are experimental. APIs may change without notice. Generated from source with koruc 0.1.7 on 10/5/2026.
Flat
@korulang/flat@0.1.0Fixed-capacity flat containers for Koru flow code — indexed i64/i32 arrays, borrowed-string ref tables, emit buffers, and the small algorithms flat storage enables (pair sort, run grouping, packed k-subsets)
flat/index.kz · 29 tors
@korulang/flat — fixed-capacity flat containers for flow code. · 26 more lines
@korulang/flat — fixed-capacity flat containers for flow code.
The gap this fills: `std/list` is a growable list (push/get/pop) and
`std/field` is a bit array — neither spells indexed set on a word cell,
and nothing in std carries a string slice's address pair or an emit
buffer. Algorithms that want flat, indexed, cache-dense storage had to
write `|zig` leaves inline; this package is those leaves, generalized.
Shapes, all obligation-tracked the same way (`live!` minted by `new`,
discharged by `free` — the parse/close idiom):
I64 / I32 fixed-capacity indexed integer cells (get/set/bump/add/zero)
Refs string-slice table — packs a slice's ptr+len per slot so a
borrowed string (e.g. a yyjson arena read) is storable in a
flat structure without copying. The referenced memory must
outlive the table's uses — this package stores addresses,
not bytes.
Buf byte emit buffer with JSON escaping (raw/jesc/closearr/done)
Plus the small generic algorithms flat storage makes possible:
pairs.sort sort parallel (key, payload) arrays by key
runs.each yield each adjacent-equal-key run as {lo, hi} bounds
combi.each yield every k-subset of an i64 range as a packed u64 key
(8 bits per element — requires k <= 8 and ids <= 255)
fail loud abort — std has no refuse-at-runtime tor
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.
I64 1 state live!I32 1 state live!Refs 1 state live!Buf 1 state live!~pub tor i64.new { n: i64 } -> *I64<live!>~pub tor i64.get { a: *I64<live>, i: i64 } -> i64~pub tor i64.set { a: *I64<live>, i: i64, v: i64 }~pub tor i64.bump { a: *I64<live>, i: i64 }~pub tor i64.add { a: *I64<live>, i: i64, v: i64 }~pub tor i64.zero { a: *I64<live> }~pub tor i64.len { a: *I64<live> } -> i64~pub tor i64.free { a: *I64<!live> }~pub tor i32.new { n: i64 } -> *I32<live!>~pub tor i32.get { a: *I32<live>, i: i64 } -> i64~pub tor i32.set { a: *I32<live>, i: i64, v: i64 }~pub tor i32.len { a: *I32<live> } -> i64~pub tor i32.free { a: *I32<!live> }~pub tor ref.new { n: i64 } -> *Refs<live!>~pub tor ref.put { r: *Refs<live>, i: i64, s: string }~pub tor ref.str { r: *Refs<live>, i: i64 } -> string~pub tor ref.free { r: *Refs<!live> }~pub tor buf.new { n: i64 } -> *Buf<live!>~pub tor buf.raw { b: *Buf<live>, s: string }~pub tor buf.jesc { b: *Buf<live>, s: string }~pub tor buf.closearr { b: *Buf<live> }~pub tor buf.done { b: *Buf<live> } -> string~pub tor buf.free { b: *Buf<!live> }// pairs.sort — sort parallel (key, payload) arrays by key, ascending, so
// equal keys land contiguous. Payload stays paired with its key.
~pub tor pairs.sort { keys: *I64<live>, cands: *I32<live>, n: i64 }~pub tor runs.each { keys: *I64<live>, n: i64 }
! run *Run
| donerun.lo
index.kz:319~pub tor run.lo { r: *Run } -> i64run.hi
index.kz:325~pub tor run.hi { r: *Run } -> i64// combi.each — enumerate every k-subset of vals[lo..lo+n], firing `! subset`
// once per combination with the subset's element ids packed into a u64 key
// (8 bits per position, in ascending order). Two values share a key iff
// they picked the same k elements — this is the packed-set-intersection
// primitive. Requires n <= 64, k <= 8, element ids <= 255.
~pub tor combi.each { vals: *I64<live>, lo: i64, n: i64, k: i64 }
! subset i64
| donefail
index.kz:379// fail — loud abort with a message. std has no refuse-at-runtime tor; a
// program that detects input it cannot serve should die saying so, never
// produce quietly wrong output.
~pub tor fail { msg: string }