k3priorityqueue
priorityQueue is a queue with priority support
k3priorityqueue is a component of pykit3 project: a python3 toolkit set.
PriorityQueue is a queue with priority support:
The numbers of items it pops from each producer matches exactly the ratio of their priority: If the priorities of 3 producer A, B and C are 1, 3 and 7, and it runs long enough, it is expected that the number of items popped from A, B and C are 1:3:7.
import k3priorityqueue
producers = ( # id, priority, iterable (1, 1, [1] * 10), (2, 2, [2] * 10), (3, 3, [3] * 10),
)
pq = k3priorityqueue.PriorityQueue()
for pid, prio, itr in producers: pq.add_producer(pid, prio, itr)
count = {}
for _ in range(12): val = pq.get() count[val] = count.get(val, 0) + 1 print(val)
print('respect priority ratio: counts:', repr(count))
while True: try: val = pq.get() except k3priorityqueue.Empty as e: break
count[val] = count.get(val, 0) + 1
print(val)
print('consumed all: counts:', repr(count))
Install
pip install k3priorityqueue
Synopsis
import k3priorityqueue
producers = (
# id, priority, iterable
(1, 1, [1] * 10),
(2, 2, [2] * 10),
(3, 3, [3] * 10),
)
pq = k3priorityqueue.PriorityQueue()
for pid, prio, itr in producers:
pq.add_producer(pid, prio, itr)
count = {}
for _ in range(12):
val = pq.get()
count[val] = count.get(val, 0) + 1
print(val)
print("respect priority ratio: counts:", repr(count))
while True:
try:
val = pq.get()
except k3priorityqueue.Empty:
break
count[val] = count.get(val, 0) + 1
print(val)
print("consumed all: counts:", repr(count))
Author
Zhang Yanpo (张炎泼) drdr.xp@gmail.com
Copyright and License
The MIT License (MIT)
Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com
Metadata
Release files for k3priorityqueue 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| k3priorityqueue-0.1.7.tar.gz | 6.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| k3priorityqueue-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.0 kB
Release files / k3priorityqueue-0.1.7.tar.gz
| Download URL | k3priorityqueue-0.1.7.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee23e1bf5c9b2dc7521cf2074df5a7d5c73ef186cbd73ce4d9b42372fba92505
|
|
BLAKE2b-256 checksum How to use checksums |
e43b7cf7080fa87cf9d62ef3805444984a55b7502bfe03f0afe44ae6b0f72f1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / k3priorityqueue-0.1.7-py3-none-any.whl
| Download URL | k3priorityqueue-0.1.7-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dca5e21bb8036058ffc27b18ff9a4699712efedc89b02111c7353522b8e79da6
|
|
BLAKE2b-256 checksum How to use checksums |
4c785bb4cd167128847e6079fca61abcfcf0775cc84764225d2e18e9bd87d1e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|