Heapdict is a Python library that implements a mutable mapping (like a dictionary) but with the properties of a min-heap. It provides efficient decrease-key and increase-key operations, making it particularly suitable for priority queue implementations in algorithms such as Dijkstra's or A*. Unlike Python's built-in `heapq` module, heapdict allows for efficient modification of item priorities. The current version is 1.0.1, with its last release in September 2019.
pip install heapdictVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create a `heapdict`, add items with associated priorities, peek at the lowest priority item, pop the lowest priority item, and efficiently change an item's priority.
As of the last stable release (1.0.1), there is no official fix. Users may need to downgrade Python, manually patch the library to use `collections.abc.MutableMapping`, or consider alternative priority queue implementations that are actively maintained for modern Python versions.
If stable sorting for equal priorities is critical, an alternative priority queue implementation should be considered, or a tie-breaking mechanism (e.g., adding an insertion index to the priority tuple) must be implemented by the user.
Users should be aware of the maintenance status and thoroughly test `heapdict` in their target Python environment, especially with Python versions newer than 3.7. Consider contributing fixes or using more actively maintained alternatives if long-term support is critical.
Install the package using pip: `pip install heapdict`
Before accessing a key, check for its existence using the `in` operator (e.g., `if key in hd:`), use the `get()` method with a default value (e.g., `hd.get(key, default_value)`), or wrap the access in a `try-except KeyError` block.
Ensure that any objects (keys or values) you retrieve from `heapdict` and subsequently operate on are not `None` or a type that doesn't support the `len()` function when such an operation is performed. Add checks for `None` or validate the type of the retrieved object before calling `len()`.
No dependency data recorded yet.