maxheap
A drop-in max-heap for Python
Mirrors Python's standard heapq
— but max-first. Optional C accelerator with pure-Python fallback, fully typed, rigorously tested, zero runtime dependencies.
Quick Install
pip install maxheapx
Then import maxheap
in your code.
Version history
v0.1.0
2025-08-13
Yanked- Initial release (Linux-only wheel). Superseded by 0.1.1.
v0.1.1
2025-08-13
Latest- Linux wheels for CPython 3.9–3.14 (manylinux & musllinux).
- C accelerator enabled by default with Python fallback.
- Benchmarks: heappush ~+19%, heapify ~+28%, heapify+drain ~+41% vs heapq+negation (N=100k, repeat=10).
maxheapx-0.1.1-cp39-...-manylinux_x86_64.whl
manylinux · 13 KB
maxheapx-0.1.1-cp39-...-musllinux_x86_64.whl
musllinux · 13 KB
Latest v0.1.1 · Released on 2025-08-13
Usage Example
import maxheap as heapq
h = []
heapq.heappush(h, 10)
heapq.heappush(h, 3)
heapq.heappush(h, 42)
print(heapq.heappop(h)) # 42
heapq-Compatible API
Same function names; max-first by default.
C Accelerator
Fast path in C; falls back to Python if unavailable.
Fully Typed
PEP 561
py.typed
for great IDEs.Performance highlights
median speedup vs heapq
+negationFaster than the common “negate values” workaround for max-heaps:
- heappush
- ~+19%
- heapify
- ~+28%
- heapify + drain
- ~+41%
Insert N items
Build from list
Build then pop all
Methodology: N=100k random integers, repeat=10, warmup=3; results report the median. Environment: Python 3.13.x on x86_64. Your results may vary by CPU, Python, and data distribution.
Want to reproduce? See Benchmarks for a ready-to-run microbench harness.
Want to reproduce? See Benchmarks for a ready-to-run microbench harness.
Why maxheap?
Max-First Priority
Python's heapq
is min-heap only. maxheap is max-first without negating values.
Zero Runtime Deps
Optional C extension; pure-Python fallback ensures portability.
Open Source
MIT-licensed and tested (unit + property-based).