Skip to main content

Priority queue with weighted producer support

Project description

k3priorityqueue

Action-CI Documentation Status Package

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


Download files

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

Source Distribution

k3priorityqueue-0.1.6.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

k3priorityqueue-0.1.6-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file k3priorityqueue-0.1.6.tar.gz.

File metadata

  • Download URL: k3priorityqueue-0.1.6.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for k3priorityqueue-0.1.6.tar.gz
Algorithm Hash digest
SHA256 89b10d2305cff0a857776753f4ecb3a324a8037a0318bc08fd401034b3d4cfde
MD5 2032369d9c8f4d6f43d66822079283fe
BLAKE2b-256 1b16228f68d9e001addf0365a24fc3916b701603d832da5416e0cc1e9f8aa94d

See more details on using hashes here.

File details

Details for the file k3priorityqueue-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for k3priorityqueue-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 67b9912161e92c8bda5ff665852506dbfdfe4cb9e85beba89a3da532f3ed5619
MD5 641850f066e3b8322381acdd469ab99b
BLAKE2b-256 2d95550213f11d0fbf8c8ab80f5a09c382d311a78336be27f93aa3aa057ad18d

See more details on using hashes here.

Supported by

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