Skip to main content

maxheap

Existing heapq library can be used as a maxheap by negating the values passed We need to negate back while retrieving from the heap as well. This can result in a cumbersome interface.

Maxpheap is a implementation similar to heapq that lets you push and pop to the heap. In a maxheap largest element has the priority.

maxheap.png

Dependencies

Python3

Install

pip3 install maxheap

Verify install

Python 3.8.10 (default, Jun  2 2021, 10:49:15)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> import maxheap

Usage

heap = []            # creates an empty heap
heappush(heap, item) # pushes a new item on the heap
item = heappop(heap) # pops the largest item from the heap
item = heap[0]       # largest item on the heap without popping it
heapify(x)           # transforms list into a max heap, in-place, in linear time
item = heapreplace(heap, item) # pops and returns largest item, and adds
                               # new item; the heap size is unchanged

Metadata

Release files for maxheapq 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for maxheapq 0.0.4
File Size Uploaded
maxheapq-0.0.4.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for maxheapq 0.0.4
File Interpreter ABI Platform
maxheapq-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 17.1 kB

Release files / maxheapq-0.0.4.tar.gz

Download URL maxheapq-0.0.4.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0ebd351889b06eb36629de9d6daf588ff6c6d0726492c332bc67dd36eb6664d0
BLAKE2b-256 checksum
How to use checksums
da316de9ca4b9fd2d274d36b5eeb3dd44c7a68ec4657dadea04a0b53710fe75c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release files / maxheapq-0.0.4-py3-none-any.whl

Download URL maxheapq-0.0.4-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e43af6922997b251907b8cdca7383e393066d40d27738142a6a7370be4f54f4
BLAKE2b-256 checksum
How to use checksums
e5a1199b7b1126500ed323960f29e05ade9d0826d2d4e9a8d420367283776b35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page