This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/17/2026.

Heap

import std/heap

Koru Standard Library: std/heap — binary min-heap over i64 keys.

heap.kz · 5 tors

Koru Standard Library: std/heap — binary min-heap over i64 keys. · 18 more lines
Koru Standard Library: std/heap — binary min-heap over i64 keys. v1 is the i64 trunk only (the List_i64 precedent): packed keys carry their own ordering, so `key = cost << K | payload` gives cost-ordered extract-min for uniform-cost search (Dijkstra/A*) with zero heap-side knowledge of what the key means. The unified `new(<element>)` / element-synthesis machinery and the `Heap[i64]` spelling are the follow-on rung — see concepts/frag-specialization-is-synthesis-not- generics.md for the ruling this module is the first consumer of. Ownership states (phantom on *Heap_i64 — identical protocol to *List_i64): <heap!> - new issues the obligation: this heap must be freed. <heap> - borrowed: push/pop/len in place, obligation untouched. <!heap> - consumed: free discharges the obligation. Ops are direct `-i64` tors (no transform layer yet): heap.push-i64, heap.pop-i64, heap.len-i64, heap.free-i64, heap.new-i64.

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.

Heap_i64 1 state heap!

new-i64

<heap!> koru_std/heap.kz:64

push-i64

<heap> koru_std/heap.kz:89

pop-i64

<heap> koru_std/heap.kz:100

len-i64

<heap> koru_std/heap.kz:120

free-i64

<!heap> koru_std/heap.kz:130