Benchmarked priority queue implementation in Rust
Project description
prqrs
Python priority queue in Rust via pyo3
The prqrs
package provides a simple interface to a priority queue implemented in Rust. This
guide will show you how to create a priority queue, add items to it, and retrieve items based on
their priority.
Installation
To build the Rust project from source run:
maturin develop --release
Alternatively using the PDM package manager, just run pdm install
.
Usage
Creating a Priority Queue
To create a priority queue, import the PriorityQueue
class from the prqrs
package and
instantiate it:
from prqrs import PriorityQueue
pq = PriorityQueue()
Creating Items
Items that can be added to the priority queue need a value and a priority.
Import the Item
class and create items:
from prqrs import Item
item1 = Item(value=5, priority=3) # An item with value 5 and priority 3
item2 = Item(value=10, priority=1) # An item with value 10 and priority 1
Adding Items to the Queue
Add items to the queue using the push method:
pq.push(item1)
pq.push(item2)
Retrieving Items from the Queue
Retrieve items based on their priority using the pop
method.
This method returns the item with the highest priority (lowest numerical value of priority):
highest_priority_item = pq.pop()
if highest_priority_item is not None:
print(f"Value: {highest_priority_item.value}, Priority: {highest_priority_item.priority}")
Checking if the Queue is Empty
To check whether the priority queue is empty, use the is_empty
method:
if pq.is_empty():
print("The priority queue is empty.")
else:
print("The priority queue is not empty.")
Example
Here is a complete example that demonstrates creating a priority queue, adding items, and retrieving them:
from prqrs import PriorityQueue, Item
# Create a priority queue
pq = PriorityQueue()
# Add items
pq.push(Item(value=5, priority=3))
pq.push(Item(value=10, priority=1))
pq.push(Item(value=7, priority=2))
# Retrieve and print items
while not pq.is_empty():
item = pq.pop()
print(f"Value: {item.value}, Priority: {item.priority}")
This will output
Value: 5, Priority: 3
Value: 7, Priority: 2
Value: 10, Priority: 1
Benchmarking
Running pdm install
(or maturin develop
) to install the Rust wheel followed by python benchmark_1m.py
:
1.1 GHz CPU: (0.18+0.51)s
Enqueue time for 1 million items: 0.1798386573791504 seconds
Dequeue time for 1 million items: 0.5103330612182617 seconds
3.7 GHz CPU: (0.08+0.19)s
Enqueue time for 1 million items: 0.08250904083251953 seconds
Dequeue time for 1 million items: 0.1858220100402832 seconds
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file prqrs-0.1.0.tar.gz
.
File metadata
- Download URL: prqrs-0.1.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a29fa25bac7fe0d38dcbafbbda0013bdb33951eb215010890aefdfb7e4c0e7cd |
|
MD5 | c6012fe8bcdc530385cd730c3fb094ff |
|
BLAKE2b-256 | e19aeb5d2990179d2b4c41497b1bb5ece54985004f5b4ecd9a3b0fe52d456ecf |
File details
Details for the file prqrs-0.1.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: prqrs-0.1.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 655.8 kB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fef87fe58ce1d1c82f9dbf9305733782470523025e3b1e870cbc292aea609c37 |
|
MD5 | bdd444d740a7dcc8183f6ea32f5b4831 |
|
BLAKE2b-256 | a18d71feba24360bd2310602fb6b866850cf78c209d409dca96f4954e4620ae6 |
File details
Details for the file prqrs-0.1.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl
.
File metadata
- Download URL: prqrs-0.1.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 663.4 kB
- Tags: PyPy, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04fbc02e82a886e1509b6a6ebf2fa96c75a3e072bacd9f8104f919fac02b6745 |
|
MD5 | e3a90704de0fd0e66693b7d9742589a8 |
|
BLAKE2b-256 | adf2d31d3a1b1b31ed4caeb654d91ea960ec04cd25940dbf15be041b8e4fdf09 |
File details
Details for the file prqrs-0.1.0-cp311-none-win_arm64.whl
.
File metadata
- Download URL: prqrs-0.1.0-cp311-none-win_arm64.whl
- Upload date:
- Size: 123.3 kB
- Tags: CPython 3.11, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a91cc111ee36236ce0a28afd64cce0c30e2f7fa67b9d8529de34c8ba0a382c55 |
|
MD5 | c271e82994106835b3d3e85d5b9d9ba5 |
|
BLAKE2b-256 | a216974eb38897613715de0f9ae769e22c6479ee7cf805bb6f7324999b1a33f2 |
File details
Details for the file prqrs-0.1.0-cp311-none-win_amd64.whl
.
File metadata
- Download URL: prqrs-0.1.0-cp311-none-win_amd64.whl
- Upload date:
- Size: 129.1 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5645f7a73fa241d64499a9853bea6b6021ae4520b74ea58d203eb65e3185973 |
|
MD5 | 09d58cd507353e24656af7a79219365f |
|
BLAKE2b-256 | 6f083240f37fb6344ce5daf2c6d959803df681b5d2e0a13e97de037ffd31b346 |
File details
Details for the file prqrs-0.1.0-cp311-none-win32.whl
.
File metadata
- Download URL: prqrs-0.1.0-cp311-none-win32.whl
- Upload date:
- Size: 123.6 kB
- Tags: CPython 3.11, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75265aedf395a9f596e0a213db4d2505bcfb47dbeefb909be2ad1bff7e44caf8 |
|
MD5 | 905f6c0c4ee5a852d26d86fad0893259 |
|
BLAKE2b-256 | 19a9d7ff007553401ba993b34e273753b376fc4af2f5ebcbd5b911d340a31389 |
File details
Details for the file prqrs-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: prqrs-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 655.8 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc19bba654305b66547f338d136fd4b17283ed178de60321f2a14a69881c39f6 |
|
MD5 | 550a25b46b9189772f46b0e2735d6d1e |
|
BLAKE2b-256 | ac945044ba46fd24fa71584e9f1da7ac46845a4cc79c08972cbe0900cd85e005 |
File details
Details for the file prqrs-0.1.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl
.
File metadata
- Download URL: prqrs-0.1.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 663.5 kB
- Tags: CPython 3.11, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a098ac9219653429116bcd7ccc392434c96c8bdf64729c5526f0503b7bb1013 |
|
MD5 | 93277fa85c007422af74799cec096dad |
|
BLAKE2b-256 | 740a7de07456524add5a9f768c6111cb702ce189e03a17539d11fb6171f33449 |
File details
Details for the file prqrs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: prqrs-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 243.0 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8e6a846eafda0b251ec55d91d8a586dc734f4991e415b24dd7a493b03a6525e |
|
MD5 | 836a4d01a443a63d8fa02bc3e9fc45a8 |
|
BLAKE2b-256 | fad19cbf8631d0421022929c44e629345eeec0214a93379f188231b38115328c |
File details
Details for the file prqrs-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: prqrs-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl
- Upload date:
- Size: 248.4 kB
- Tags: CPython 3.11, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 825e614d156c5c0b7835ea34eed2c598d07df300a2dc3e69bc678cf69df2e9d7 |
|
MD5 | c7fcb1014fa996ad26ac9d97208d133f |
|
BLAKE2b-256 | a110328f37f3faa3a514e888bb62796745062186e7a99a711fceaeb060e89519 |
File details
Details for the file prqrs-0.1.0-cp310-none-win_arm64.whl
.
File metadata
- Download URL: prqrs-0.1.0-cp310-none-win_arm64.whl
- Upload date:
- Size: 123.3 kB
- Tags: CPython 3.10, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab8799bf958f32c6f638d7fee4efb3cf184db4c354f5f452c8d96aa2fa055ecf |
|
MD5 | a91ded07d966dbfc659ba176059fc48e |
|
BLAKE2b-256 | 003e4238ff7694c57bf866f98b1b428586d7408d57544cd4d53b57b8c6c0a5da |
File details
Details for the file prqrs-0.1.0-cp310-none-win_amd64.whl
.
File metadata
- Download URL: prqrs-0.1.0-cp310-none-win_amd64.whl
- Upload date:
- Size: 129.1 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc0c7990188dc30a4b19661a6f487771f7cfda060160d2a41e216556a91d0ed2 |
|
MD5 | d73876e3aa377b4e3cf8107f669aafbd |
|
BLAKE2b-256 | 14cb000db48a2a9a59ca0307190ffd42b235315425f5cf9776911b86dcee63ca |
File details
Details for the file prqrs-0.1.0-cp310-none-win32.whl
.
File metadata
- Download URL: prqrs-0.1.0-cp310-none-win32.whl
- Upload date:
- Size: 123.6 kB
- Tags: CPython 3.10, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3d765314843d6615ed67b4a25a792eeffca45c4d430ecce2ec2956ac3507fd6 |
|
MD5 | 9f8b7098ab265dabc1cacaaa92591f2f |
|
BLAKE2b-256 | e7ba45deac5f0cbc661d24421af13fe691abf32102b98efa748eb9fcaac15c8b |
File details
Details for the file prqrs-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: prqrs-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 655.8 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb78ee9e1aae12b06f30fc8850138a45692c068c8cfaa6474091999d026211c9 |
|
MD5 | 1f50d98206fb4861ff36fff58a9c6ee1 |
|
BLAKE2b-256 | f5262894f2d52b5202802856a360e6d579b483ac3bf36b0ab21ef4ee32bd2ae0 |
File details
Details for the file prqrs-0.1.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl
.
File metadata
- Download URL: prqrs-0.1.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 663.5 kB
- Tags: CPython 3.10, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31178b6f25326da2f1bdd83d8db1f23020cb9e618206264ed4415643cb61e30f |
|
MD5 | baaf325e24ebaab42aec6af121d870f6 |
|
BLAKE2b-256 | b9609876c1511e0887f925753381a45ca7cb0ab447235dead691451b40835e9e |