Skip to main content

Monotone priority queue useful for shortest paths and more; wraps Rust's radix-heap crate

Project description

Radix Heap for Python

This module provides a Python implementation of Radix Heap-like data structures, designed to function as monotone priority queues. The heavy-lifting for the heap operations is powered by the radix-heap Rust crate from mpdn -- they did 99% of the hard work by implementing the data structure.

Monotone priority queues are useful for pathfinding in general (e.g., A*, Dijkstra's algorithm). A monotone priority queue must maintain the invariant where the extracted elements form a monotone sequence (e.g., for a max-heap, the extracted elements are in non-increasing order).

Overview

A Radix Heap is a type of priority queue where the extracted elements form a monotone sequence. This module includes implementations for both maximum and minimum heaps for integer and float keys.

Classes

  • RadixHeapLike[K, V]: A generic base class for Radix Heap-like structures.
  • RadixMaxHeapInt[V]: A radix max heap for integers.
  • RadixMinHeapInt[V]: A radix min heap for integers.
  • RadixMaxHeap[V]: A radix max heap for floats (or integers).
  • RadixMinHeap[V]: A radix min heap for floats (or integers).

Methods

  • push(key: K, value: V) -> None: Adds a key-value pair to the heap.
  • pop() -> V: Removes and returns the minimum value from the heap.
  • pop_with_key() -> tuple[K, V]: Removes and returns the minimum key-value pair from the heap.
  • top() -> V | None: Returns the minimum value from the heap without removing it.
  • clear() -> None: Removes all elements from the heap.
  • __len__() -> int: Returns the number of elements in the heap.

Usage Examples

Radix Max Heap for Integers

from radix_heap import RadixMaxHeapInt

heap = RadixMaxHeapInt()
heap.push(10, "A")
heap.push(5, "B")
heap.push(8, "C")

while heap:
    print(heap.pop())
# Output: "A", "C", "B"

Installation

To install the module, you can use pip:

pip install radix-heap

Contributing

Contributions are welcome! Please check the repository and feel free to open issues or submit pull requests.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

radix_heap-0.1.0.tar.gz (7.7 kB view hashes)

Uploaded Source

Built Distributions

radix_heap-0.1.0-cp37-abi3-win_amd64.whl (139.1 kB view hashes)

Uploaded CPython 3.7+ Windows x86-64

radix_heap-0.1.0-cp37-abi3-win32.whl (132.7 kB view hashes)

Uploaded CPython 3.7+ Windows x86

radix_heap-0.1.0-cp37-abi3-musllinux_1_2_x86_64.whl (441.7 kB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ x86-64

radix_heap-0.1.0-cp37-abi3-musllinux_1_2_i686.whl (463.5 kB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ i686

radix_heap-0.1.0-cp37-abi3-musllinux_1_2_armv7l.whl (541.3 kB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ARMv7l

radix_heap-0.1.0-cp37-abi3-musllinux_1_2_aarch64.whl (459.6 kB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ARM64

radix_heap-0.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (272.0 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

radix_heap-0.1.0-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (331.1 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ s390x

radix_heap-0.1.0-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (308.5 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ppc64le

radix_heap-0.1.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (278.4 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARMv7l

radix_heap-0.1.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (281.1 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

radix_heap-0.1.0-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.whl (282.7 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.5+ i686

radix_heap-0.1.0-cp37-abi3-macosx_11_0_arm64.whl (236.2 kB view hashes)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

radix_heap-0.1.0-cp37-abi3-macosx_10_12_x86_64.whl (238.0 kB view hashes)

Uploaded CPython 3.7+ macOS 10.12+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page