A double ended priority queue implemented with a min-max-heap
Project description
DepqDict
DepqDict is an efficient double-ended priority queue implemented in Python. It allows efficient retrieval and extraction of the minimum and maximum priority elements, as well as updating priorities of arbitrary elements. Implemented using a min-max heap.
Features
- Supports both min and max priority queue operations.
- Efficient push and pop operations for both min and max elements.
- Allows updating priorities of arbitrary keys.
- Implements the
MutableMappinginterface, behaving like a dictionary.
Installation
You can install DepqDict from PyPI using pip:
pip install depqdict
Usage
from depqdict import DepqDict
pq = DepqDict()
pq['task1'] = 5
pq['task2'] = 2
pq['task3'] = 8
print(pq.min_item()) # ('task2', 2)
print(pq.max_item()) # ('task3', 8)
pq['task1'] = 1 # Update priority
print(pq.min_item()) # ('task1', 1)
pq.pop_min_item() # Removes ('task1', 1)
API with Runtimes
Retrieve Min/Max Items
pq.min_item() # O(1)
pq.max_item() # O(1)
Returns the key-value pair with the lowest or highest priority.
Remove Min/Max Items
pq.pop_min_item() # O(log n)
pq.pop_max_item() # O(log n)
Removes and returns the key-value pair with the lowest or highest priority.
Push-Pop Operations
pq.push_pop_min_item('task4', 3) # O(log n)
pq.push_pop_max_item('task5', 9) # O(log n)
Pushes a new key-priority pair into the queue and returns the smallest or largest item. Faster than using two separate operations.
Insert or Update a Key
pq['task6'] = 4 # O(log n)
Inserts or updates the priority of a key.
Delete a Key
del pq['task3'] # O(log n)
Removes a key from the queue.
License
This project is licensed under the GPL-3.0 License, as it is based on heapdict by Evgeniy Selezniov, which is also licensed under GPL-3.0. See the LICENSE file for details.
Acknowledgments
This package is based on heapdict, originally developed by Evgeniy Selezniov.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file depqdict-0.1.0.tar.gz.
File metadata
- Download URL: depqdict-0.1.0.tar.gz
- Upload date:
- Size: 38.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5531a6a68c464956a46d77cd8f954b1ae69612f5dba6a7f01b9cab23ebf7d0f7
|
|
| MD5 |
9f26d63644fe2a5c2b13a517426c2792
|
|
| BLAKE2b-256 |
4ec50a866ba3db2d79f342810f0d7baea026149e05d047971e6b784f829e6aee
|
File details
Details for the file depqdict-0.1.0-py3-none-any.whl.
File metadata
- Download URL: depqdict-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cd3f930cb80ace8049a49b4f23b35c217e2bc8e74ab54808beee351044a7778
|
|
| MD5 |
b19d6df77c8cea6b9c69cb5c2ca93430
|
|
| BLAKE2b-256 |
1c6e596478a46a787405a57e683ae5ae720d51d72dc423e90b9c6491c3149e2f
|