priorityQueue is a queue with priority support
Project description
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 as e:
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
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 Distribution
File details
Details for the file k3priorityqueue-0.1.2.tar.gz
.
File metadata
- Download URL: k3priorityqueue-0.1.2.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 288f7dbf10726199b1b7bacf727fa3ae93c288f2e2cad228e3340a81aab24b1e |
|
MD5 | d33becc5dded2d992ad19a6427ed9b7c |
|
BLAKE2b-256 | 6361c8f4164cd12bf0bf8ac1ee3e69e1ac3a6ca2b94f0a236832c312f98ebc39 |
File details
Details for the file k3priorityqueue-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: k3priorityqueue-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8345e2ec32194be5a14a9edb4a7d99fe99e15e49de61c7f2de304bf3b6dabd9 |
|
MD5 | 4fcb242d6334a80fac40e9a73ae1f688 |
|
BLAKE2b-256 | 66d250824cdc74281351d024f9a7ae8b51489a6f791be5b5ddb2dedc11545cdf |