Python priority queue implemented in Rust
Find a file
Michael Bradley 265040ee4e
All checks were successful
CI / Formatting (push) Successful in 39s
CI / Clippy (push) Successful in 54s
CI / Build (push) Successful in 1m31s
CI / Python tests (push) Successful in 40s
CI / Rust tests (push) Successful in 1m24s
Update to 2024 edition
`cargo fix` recommended swapping my `if let`s for `match`s, which is appreciated but overzealous.
Code still runs fine.
2025-02-23 10:07:02 -05:00
.forgejo/workflows Re-enable other CI jobs 2025-02-23 09:16:50 -05:00
src Address Clippy lints 2025-02-23 09:50:20 -05:00
tests Add (failing) (minimal) IndexedQueue (Rust) tests 2025-01-13 22:11:05 +13:00
.gitignore Initial setup 2025-01-03 01:41:49 +13:00
Cargo.lock Update dependencies 2025-02-23 09:59:21 -05:00
Cargo.toml Update to 2024 edition 2025-02-23 10:07:02 -05:00
pyority_queue.pyi Rename KeyedQueue to PairedQueue 2025-01-09 00:03:01 +13:00
pyproject.toml Initial setup 2025-01-03 01:41:49 +13:00
README.md Explain project properly in README 2025-01-31 02:14:58 -05:00
requirements.txt Remove unneeded reference to self in requirements.txt 2025-01-31 02:14:16 -05:00

pyority_queue

Implementations of priority queues in Python using Rust bindings for speed.

Purpose

I'm doing this to learn Rust, so don't judge me too hard lol. I've noted a few places where I'm unhappy with the implementation (mostly w.r.t. code duplication), but hopefully as I become more comfortable in Rust I can go back and fix those.

Better to have a bad implementation now than a good implementation never.

Usage

The package provides 3 queues: Pure, Paired, and Indexed, all of which are min-queues. The PureQueue directly sorts the values it is given and returns them in order. The PairedQueue pairs an arbitrary Python object with a float priority and returns the objects in the order specified by their priorities. The IndexedQueue works the same as the PairedQueue, but allows arbitrary priority modification and object deletion at the cost of some runtime overhead and no support for duplicate objects (duplicate priorities are okay).

Typing is provided in pyority_queue.pyi, and should be picked up by your IDE.

Development

Install venv and setup as usual

python -m venv venv
pip install -r requirements.txt
source venv/bin/activate

Build rust code with

maturin develop

Note that after you build the project for the first time you may have to restart the venv for it to pick up the new module

deactivate
source venv/bin/activate

Develop as usual, you should now be able to import the code through Python

from pyority_queue import *

Testing

Run the rust test suite with

cargo test

Run the python test suite with

pytest tests/*.py