An implementation of a Min-Max Heap with a MutableMapping interface.
Project description
heap-mapping
This is a library containing an implementation of the min-max heap data structure, which allows for $O(log(n))$ retrieval or removal of both the minimum and maximum elements of the heap, as well as insertion and keys and changes to their priorities. Heap creation can be additionally performed in $O(n)$ time.
The data structure can be accessed as MutableMapping; keys are the
"values" stored in the data structure, and values are their priorities.
Getting started
You can construct a MinMaxHeap from a list of values.
from heap_mapping import MinMaxHeap
heap = MinMaxHeap([5, 0, 4, 1, 2, 9, 8])
print(heap.min_value) # 0
print(heap.max_value) # 9
By default, priorities are the same as the values.
print(heap[5]) # 5
You can specify a key function in the constructor to get a priority from each element.
heap2 = MinMaxHeap([5, 0, 4, 1, 2, 9, 8], key=lambda x: -x)
print(heap2.min_value) # 9
print(heap2.max_value) # 0
print(heap2[5]) # -5
You can add elements with the add method. By default, the key function
specified in the constructor is used to get the priority.
heap2.add(7)
print(heap2[7]) # -7
Alternatively, you can manually specify a key.
heap2.add(6, -3)
print(heap2[6]) # -3
You can change the priorities after they've been inserted.
heap2[7] = 1
print(heap2.max_value) # 7
You can look up and delete arbitrary elements in $O(log(n))$ time.
del heap2[6]
print(6 in heap2) # False
Iteration is performed out of order. Note that this order is also not the order in which the elements are stored in the heap!
print(list(heap2)) # [5, 0, 4, 1, 2, 9, 8, 7]
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 heap_mapping-0.1.0.tar.gz.
File metadata
- Download URL: heap_mapping-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da6c2e488731acadb6c5c94910d1c12879e60cba031bb4aa936c2e65f1193489
|
|
| MD5 |
212f1e0df44f6c2f4d5b35f368e0ebe6
|
|
| BLAKE2b-256 |
4ca6b773caa839b97a47676e92596324861b4f4933d10eae6c9d368399ca0591
|
Provenance
The following attestation bundles were made for heap_mapping-0.1.0.tar.gz:
Publisher:
package.yml on actapia/min-max-heap-mapping
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
heap_mapping-0.1.0.tar.gz -
Subject digest:
da6c2e488731acadb6c5c94910d1c12879e60cba031bb4aa936c2e65f1193489 - Sigstore transparency entry: 194460424
- Sigstore integration time:
-
Permalink:
actapia/min-max-heap-mapping@fda5e0b95b2790e994c6988f81dd75b32006d74c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/actapia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
package.yml@fda5e0b95b2790e994c6988f81dd75b32006d74c -
Trigger Event:
release
-
Statement type:
File details
Details for the file heap_mapping-0.1.0-py3-none-any.whl.
File metadata
- Download URL: heap_mapping-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e89e03f10a699e9134e46629e7d4f586c1fdd0f28c99f9eb8f2e4c19c741728c
|
|
| MD5 |
97f7221abe07177658d0ff0651516cf2
|
|
| BLAKE2b-256 |
9ff8ddd822525a6cd60647ed27c5d9507384c915433e9ca20e2da1a49ae82aac
|
Provenance
The following attestation bundles were made for heap_mapping-0.1.0-py3-none-any.whl:
Publisher:
package.yml on actapia/min-max-heap-mapping
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
heap_mapping-0.1.0-py3-none-any.whl -
Subject digest:
e89e03f10a699e9134e46629e7d4f586c1fdd0f28c99f9eb8f2e4c19c741728c - Sigstore transparency entry: 194460428
- Sigstore integration time:
-
Permalink:
actapia/min-max-heap-mapping@fda5e0b95b2790e994c6988f81dd75b32006d74c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/actapia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
package.yml@fda5e0b95b2790e994c6988f81dd75b32006d74c -
Trigger Event:
release
-
Statement type: