MoaT-Lib-PrioMap
% start synopsis % start main
A heap that behaves like a dict (or vice versa).
The keys are ordered by their associated value.
% end synopsis
Features
-
Dictionary-style access:
h[key] = priority(insert/update)prio = h[key](lookup)del h[key](remove)
-
Bulk initialization:
PrioMap({'a':1, 'b':2}) -
Priority operations:
h.popitem()&h.peekitem()for root (min)h.update(key, new_prio)to change an existing key’s priority
-
Introspection:
len(h),key in h,h.is_empty()
-
Safe iteration:
-
.keys(),.values(),.items(), and plainfor k, v in h: -
Detects concurrent modifications and raises
RuntimeError.
-
% end main
Non-Features
-
Storing more than the priority. Workaround: use a
(prio, other_data)tuple. -
Sorting by highest instead of lowest priority first. Workaround: store the negative priority value.
Installation
pip install moat-lib-priomap
Usage
PrioMap
from moat.lib.priomap import PrioMap
# Min-heap example
h = PrioMap({'a':5, 'b':2, 'c':3})
print(h.peekitem()) # ('b', 2)
# Insert
h['d'] = 1
print(h.popitem()) # ('d', 1)
# Update
h.update('a', 0)
print(h.peekitem()) # ('a', 0)
# Iterate. Does not consume the data.
for key, prio in h.items(): # keys(), values()
print(f"{key} -> {prio}")
# emits a->0, d->1, b->2, c->3
# Async Iteration. Does consume the data!
# Waits for more data if/when it runs out.
async for key, prio in h:
print(f"{key} -> {prio}")
TimerMap
from moat.lib.priomap import TimerMap
# example
h = TimerMap({'a':5, 'b':2, 'c':3})
print(h.peekitem()) # ('b', 1.995)
# Iterate
async for key in h:
print(key)
# > waits two seconds
# b
# > waits another second
# c
# > two seconds later
# a
License
MIT.
Metadata
Release files for moat-lib-priomap 0.2.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| moat_lib_priomap-0.2.8.tar.gz | 9.5 kB | Without provenance | Details for moat_lib_priomap-0.2.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| moat_lib_priomap-0.2.8-py3-none-any.whl | Python 3 | none | any | Details for moat_lib_priomap-0.2.8-py3-none-any.whl |
Total release size: 17.2 kB
Release files / moat_lib_priomap-0.2.8.tar.gz
| Download URL | moat_lib_priomap-0.2.8.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ba3f4e4d36ae3b6b035d61ad8318f3f4cbab2c7283de9043e5ca92257b1cee9
|
|
BLAKE2b-256 checksum How to use checksums |
54cf945b82d26824fd889c3531300394fd1de9dd845c79700bea993968600d03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / moat_lib_priomap-0.2.8-py3-none-any.whl
| Download URL | moat_lib_priomap-0.2.8-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0253b60ac717ad5e5555319e2822badca798e8844f370298c37483b5ec2b0039
|
|
BLAKE2b-256 checksum How to use checksums |
55911b292c373e2d15fa0e2457cf3e5900445f44987f09b2db9c84668c487c1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for moat-lib-priomap 0.2.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.