Skip to main content

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


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.2.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prioritymap-0.0.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file prioritymap-0.0.2.tar.gz.

File metadata

  • Download URL: prioritymap-0.0.2.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for prioritymap-0.0.2.tar.gz
Algorithm Hash digest
SHA256 50bd454fc1c6b64be8e66b9c4ac37532ff33d1719bea252532f9570c870dcbb8
MD5 ebceeb4b3e591f56a5757764373980ad
BLAKE2b-256 b5f3c22bcd2c168d14555d52e6f6cfa72595ab1cab1ebf4098ff4f4cd357a60f

See more details on using hashes here.

File details

Details for the file prioritymap-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: prioritymap-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for prioritymap-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7a2de9f28590d7bd95602c3edb55ef90569dce1bb40b7f2aac2b9223db0944a7
MD5 df7e941c7a90cfb5dec7daee432e0fea
BLAKE2b-256 6bb1ed6e38c89e3d82a46cdecf9b76b718f9121ddf017d52fab778c4c9bc2f6a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page