Binary Heap Priority Queue
Project description
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
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
bhpq-2.0.1.tar.gz
(3.0 kB
view details)
Built Distribution
bhpq-2.0.1-py3-none-any.whl
(4.2 kB
view details)
File details
Details for the file bhpq-2.0.1.tar.gz
.
File metadata
- Download URL: bhpq-2.0.1.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03bd7d93e8e442dec2c789944825d5df4a5f5ce0d16d999b3df02ceccff28de2 |
|
MD5 | 5703ccf69be774ccd1af75f358cb1e4c |
|
BLAKE2b-256 | 101d6e922bf14474e430041f39a3068836915d8931275bd260806fe1e19d0b87 |
File details
Details for the file bhpq-2.0.1-py3-none-any.whl
.
File metadata
- Download URL: bhpq-2.0.1-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91526b9feb7714542a71f55b10bd3de9c5d6726a3d5a4efdbc439641660f0236 |
|
MD5 | 2f13b617aadf18020851c378aaac0ef9 |
|
BLAKE2b-256 | 3efdf17e933271fb6332ab225681322c064be561507f84ec8bf66265428cc5ba |