Skip to main content

PriorityQ is a library for managing a priority queue (PQ) with a cleaner API to enable custom comparators, finding references to values efficiently (in constant time) and deleting values from the PQ. This was developed because the current heapq module (in python’s standard library) does not provide an efficient find operation (it is O(n)) and has no easy way to deleting an element and ensuring the heap invariant afterwards.

Features

  • O(1) finding of elements

  • Deletion of elements possible (in O(log n)).

  • Adjusting of the priority of an element without requiring a deletion followed by an insertion.

  • Opaque handles to elements that can be used to reference to the same item again.

  • Duplicate elements allowed.

  • Custom comparator function can be passed to the PQ itself instead of needing to implement __cmp__.

It is simple to use

To create a PQ simply do:

# A simple object with a comparator
class Item(object):
    def __init__(self, value):
        self.value = value
    def __cmp__(self, another):
        return cmp(self.value, another.value)

from priorityq import PQ
pq = PQ()
pq.heapify([Item(r) for r in [1, 10, 2, 20, 4, 7, 9, 3, 5, 6]])

print list(pq)

# Should print:
# 1 2 3 4 5 6 7 9 10 20

handle_10 = pq.find(10)   #   Happens in O(1)

handle_10.value = 25      #   Modify its value - O(log n)
pq.adjust(handle_10)      #   Indicate to the heap to reprioritise/adjust it

print list(pq)

# Should print:
# 1 2 3 4 5 6 7 9 20 25

handle_10.value = 10      #   Modify its value using the same opaque handle as before
pq.adjust(handle_10)      #   Indicate to the heap to reprioritise/adjust it

print list(pq)

# Should print:
# 1 2 3 4 5 6 7 9 10 20

Metadata

Release files for priorityq 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for priorityq 0.0.9
File Size Uploaded Provenance
priorityq-0.0.9.tar.gz 10.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for priorityq 0.0.9
File Interpreter ABI Platform
priorityq-0.0.9-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 32.2 kB

Release files / priorityq-0.0.9.tar.gz

Download URL priorityq-0.0.9.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
39a786a1f2badea96b30914794ae3a8bc281ccefd451a3838bf7cb7d1fbf1b13
BLAKE2b-256 checksum
How to use checksums
56ec71249eee8f951d90033f8664ad8cf4d9f85ad58a10f75bde9ab06f0dafae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / priorityq-0.0.9-py2.py3-none-any.whl

Download URL priorityq-0.0.9-py2.py3-none-any.whl
Size 21.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b5c8cca37600adf04784e2f7fdd20e039b8f69b8c9c62b5b2222d07a416ad2e5
BLAKE2b-256 checksum
How to use checksums
87f8f30580967db9407a6e6b834bf480f50cddf63c16578aabad5e06b88054e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for priorityq 0.0.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page