[issue42240] Add Maxheap version of a heappush into heapq module

2020-12-04 Thread Matteo Dell'Amico


Matteo Dell'Amico  added the comment:

Personally, I'd find a maxheap in the standard library helpful, and a quick 
Google search tells me I'm not alone.

I generally have to deal with numeric values, so I have these choices:
 - ugly code (e.g., `minus_distance, elem = heappop(heap)`, `distance = 
-minus_distance`)
 - slow code (e.g., wrapping heapq in a class)

Since most of maxheap is already implemented in the library, I wonder what is 
the rationale for not including it.

A couple of use cases for max-heap that I ran into:
 - maintaining k-nearest-neighbor structures (the farthest known one is at the 
top of the queue)
 - running median (requires both a minheap and a maxheap)

--
nosy: +della

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42240] Add Maxheap version of a heappush into heapq module

2020-11-02 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Only the minheap is in the public API.  The maxheap functions are only supposed 
to be used internally.

Thank you for the suggestion, but I think we should decline.

--
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42240] Add Maxheap version of a heappush into heapq module

2020-11-02 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42240] Add Maxheap version of a heappush into heapq module

2020-11-01 Thread Rudresh Veerkhare


New submission from Rudresh Veerkhare :

Main functions required to implement Heap data structure are: 
function heappush - to push an element in Heap
function heappop - to pop an element from Heap

for implementing Minheap this functions are present in the module as : 
heappush - for adding element into Minheap
heappop - to pop an element from Minheap

for implementing Maxheap only one of this two required functions is present:
_heappop_max - to pop an element from Maxheap

I suggest adding a Maxheap version of heappush into heapq module.
_heappush_max - for adding an element into Maxheap.

--
components: Library (Lib)
messages: 380184
nosy: veerkharerudresh
priority: normal
severity: normal
status: open
title: Add Maxheap version of a heappush into heapq module
type: enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com