Skip to main content

Maxheap

Project description

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

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

maxheapq-0.0.4.tar.gz (8.6 kB view hashes)

Uploaded Source

Built Distribution

maxheapq-0.0.4-py3-none-any.whl (8.5 kB view hashes)

Uploaded Python 3

Supported by

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