larzheap
A binary heap / priority queue.
A heap keeps a collection so the highest-priority item is always instantly available - the structure behind task queues, schedulers, top-N problems and Dijkstra. larzheap is a readable array-backed binary heap: push, pop the smallest (or largest), peek, with an optional key, plus heapsort.
larzscript pkg install heap
What you get
- push / pop / peek
- Min or max, custom key
- heapsort included
- Readable array-backed heap
Try it
import "heap" as heap let h = heap.new() heap.push(h, 5); heap.push(h, 1); heap.push(h, 3) print(heap.pop(h)) print(heap.peek(h)) print(heap.heapsort([5, 1, 4, 2, 8]))
Output
1 3 [1, 2, 4, 5, 8]
Why it's in the Larz Stack
larzheap is a real Larzscript package (larzscript pkg install heap) - money-native, zero dependencies, the same language as the rest of the estate, not a separate Python runtime. It composes with the rest of the Larz Stack and the Larz framework.