Priority Map -- efficient heap x map
Project description
Python Priority Map
A asymptotically-efficient combination between a heap and a map that stores key:priority mappings. Licensed under the Apache License Version 2.0.
Operations
Operation | Description | Runtime Complexity |
---|---|---|
__getitem__(key) |
Get priority of key | O(1) |
__setitem__(key, priority) |
Set priority of key | O(log n) |
__delitem__(key) |
Remove a key | O(log n) |
__contains__(key) |
Check whether a key is contained | O(1) |
__len__() |
Return the number of keys contained | O(1) |
peek() |
Get lowest-priority key and its priority | O(1) |
pop() |
Get and remove lowest-priority key and its priority | O(log n) |
Example Console Output
>>> from prioritymap import PriorityMap
>>> pm = PriorityMap()
>>> pm["first"] = 1
>>> pm["second"] = 2
>>> pm["underdog"] = 5
>>> pm.peek()
('first', 1)
>>> pm["underdog"] = 0
>>> len(pm)
3
>>> pm.pop()
('underdog', 0)
>>> pm.pop()
('first', 1)
>>> pm.pop()
('second', 2)
>>> len(pm)
0
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
prioritymap-0.0.1.tar.gz
(5.7 kB
view hashes)
Built Distribution
Close
Hashes for prioritymap-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 432c91dbd281da64136f71d1497442b3124b3d7b3df6f95733f60796a43016f9 |
|
MD5 | 389959c0e468205405cf2009c14752e0 |
|
BLAKE2b-256 | 5577c7865e2faba0cf5829112c8f43b04986e94dd5fb373070a6de0c57f28cb6 |