Releases: ori88c-python-packages/top-k
Releases · ori88c-python-packages/top-k
Release list
v1.0.0 - Initial Release
Keep the top-k highest-priority items in O(k) space. Zero runtime dependencies.
Highlights
- High-level abstraction for "keep the best k items". The priority is a callable on your item type. Return
-scoreto keep the k least risky items instead. - O(k) space. Only the current top-k is stored. Additional candidates are either rejected or swapped with the current lowest-priority entry.
- Generic and fully typed.
TopK[T]stores your items as-is, including third-party types you do not control. You pass aprioritycallable (Callable[[T], int | float]) instead of wrapping those objects in(score, item)tuples. Type checkers can still validate that every stored item is aT. Ships with apy.typedmarker (PEP 561). Works out of the box with mypy, pyright, and other type checkers. - Items need not be comparable. Many third-party types have no
__lt__. A monotonic unique tiebreaker is stored alongside each priority soheapqnever falls through toT.__lt__— you do not have to wrap the item just to make it heap-safe. - Zero runtime dependencies. The package uses only the Python standard library (
heapq). - Tested on Python 3.12 through 3.14.