Max Heaps, Ordered Heaps in Python With Custom Comparators and Key Function

Python doesn't have an easy to use customisable heap module and there is no support for max heap although you can make it work by negating the element . there is also no support for custom heap nodes like dictionaries and class objects. I have made a single heap class

  1. which you can easily use as min and max heap
  2. use any structure as a heap node with arbitrary key function
  3. Maintain the order of insertion in the heap
  4. Keep the original indexes of the heap arr
  5. You can use a comparator function if you want to structure your heap according to one or more parameters(For Example you want the highest value closest to an index).

You can simply copy paste the contents of https://github.com/gekco/heapy/blob/master/heapy/heap.py

or if you want to use it in a project

pip install heaps

I have done enough documentation for it to be helpful
If anyone has any comments/suggestions they are welcome.

I know there are a lot such libraries, but i think i tried to make it as flexible as i could. Also if you go ahead and decide to use it please star it It would be a really big help. :)
Thanks.

Comments (1)