BHPQ - Binary Heap Priority Queue
A binary heap priority queue implementation, thread safe
Installation
You can install bhpq from PyPI:
pip install bhpq
bhpq is supported on Python 3.7
Usage
from bhpq import BinaryHeapPriorityQueue
# The BinaryHeapPriorityQueue constructor takes two input params:
# - prefer (required param)
# the preferred object is pushed to the top of the queue
# the prefer input is a lambda function eg:
# prefer=(lambda lhs, rhs: lhs if lhs.val >= rhs.val else rhs)
# - size
# The initial size allocation of the queue, default value is 10
Example
class Node(object):
def __init__(self, val):
self.val = val
A = BinaryHeapPriorityQueue(
prefer=(lambda lhs, rhs: lhs if lhs.val >= rhs.val else rhs), size=5
)
A.add(Node(1))
A.add(Node(4))
A.add(Node(3))
A.add(Node(5))
A.add(Node(2))
assert 5 == A.pop().val
assert 4 == A.pop().val
assert 3 == A.pop().val
assert 2 == A.pop().val
assert 1 == A.pop().val
assert None == A.pop()
Methods
size()
returns the current size of the priority queue
peek()
returns the object at the topof the priority queue if it exists else returns None
pop()
removes and returns the object at the top of the priority queue if it exists else returns None
add(val)
adds an element to the priority queue
Maintainer
Release files for bhpq 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bhpq-2.0.1.tar.gz | 3.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bhpq-2.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:7.1 kB
Release files / bhpq-2.0.1.tar.gz
| Download URL | bhpq-2.0.1.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
03bd7d93e8e442dec2c789944825d5df4a5f5ce0d16d999b3df02ceccff28de2
|
|
BLAKE2b-256 checksum How to use checksums |
101d6e922bf14474e430041f39a3068836915d8931275bd260806fe1e19d0b87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Release files / bhpq-2.0.1-py3-none-any.whl
| Download URL | bhpq-2.0.1-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
91526b9feb7714542a71f55b10bd3de9c5d6726a3d5a4efdbc439641660f0236
|
|
BLAKE2b-256 checksum How to use checksums |
3efdf17e933271fb6332ab225681322c064be561507f84ec8bf66265428cc5ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|