It is easy to have a wrapper class around the heapq functions so that you
can use
an arbitrary comparison on the heap.

I have an answer with such an snippet, that got some
activity today - maybe exactly due to your questioning:

https://stackoverflow.com/questions/8875706/heapq-with-custom-compare-predicate/8875823#8875823



On Fri, 20 Mar 2020 at 14:30, Abhai Kollara <[email protected]> wrote:

> Hi,
> I understand that the default implementation of heapq.heapify is to create
> a min-heap. The logic for max-heapify has already been implemented inside
> _heapify_max and along with that for corresponding push and pop operations.
> But they are not exposed to the user and hence not mentioned in any of the
> docs. I am unable to find any explanation as to why this is so.
>
> Current methods of implementing max-heaps (according to the SO question
> mentioned below) involves inverting the signs of numeric values and other
> workarounds. Therefore, I would like to propose officially supporting
> max-heaps as a part of heapq module.
>
> SO Q&A regarding the issue :
> https://stackoverflow.com/questions/2501457/what-do-i-use-for-a-max-heap-implementation-in-python
>
> Thank you
> --
> Abhai Kollara
> _______________________________________________
> Python-ideas mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/E33N242KUHP33NITOSJ7JLRJMC74SQKY/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/FY2UOPNEC32W7DBOE4ZT5CWX5UEP4EJY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to