heapix
A lightweight Rust library offering two heap‑based priority‑queue data structures with the same ergonomic API:
MinHeap<K>– classic binary min‑heap (array‑based) withO(log n)insert / delete‑min.FibHeap<K>– a Fibonacci heap withO(1)amortised insert & decrease‑key andO(log n)delete‑min. Perfect for graph algorithms (Dijkstra, Prim) that calldecrease_keyfrequently.
Both types store items as (id, key) tuples and keep a dense positions array so you can change priorities in constant time.
Features
| Structure | insert | delete‑min | get_min | decrease_key | build_heap |
|---|---|---|---|---|---|
MinHeap |
O(log n) |
O(log n) |
O(1) |
O(log n) |
O(n) |
FibHeap |
O(1) |
O(log n) |
O(1) |
O(1) |
O(n) |
- Identical public API – swap one for the other via a simple
typealias. - Generic over any
K: PartialOrd + Copy(integers, floats, etc.). - Dense‑id
positionstable for constant‑timedecrease_key(id, new_key). build_heapto construct directly from an unsorted vector.
Installation
[]
= "0.4"
Or via the CLI:
Quick Start
use ;
API (common to both heaps)
new
Replace Heap<K> with either MinHeap<K> or FibHeap<K>.
Choosing a heap
- Use
MinHeapwhen your workload rarely callsdecrease_key(e.g. a simple priority‑queue for tasks). - Use
FibHeapfor graph algorithms or any scenario heavy ondecrease_keyor heap melding.
Both share the same tests in ./tests to guarantee identical behaviour.
License
Licensed under the MIT License. See the LICENSE file for details.