<div dir="ltr"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 22, 2017 at 10:52 PM, bunslow <span dir="ltr"><<a href="mailto:bunslow@gmail.com" target="_blank">bunslow@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'll just note the original proposal I made was specifically designed to be the minimum possible improvement, to avoid controversy (and e.g. a PEP).<div><br></div><div>I agree that there are significant flaws and room for improvement in the current heapq module (which is why things like xheap exist), but even so it's still very useful as is, and the minimal OOP wrapper would go a long way towards usability of the current functionality (and of course "just use pip" is often not a viable course of action for certain developers). It seems that such a wrapper is widely (though not unanimously) approved.</div><div><br></div><div>Next step I suppose is creating a bpo issue?</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Wed, Nov 22, 2017 at 10:05 PM, Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On 22 November 2017 at 11:00, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
So the question is more: why, with Python being the way it is, do the<br>
heap functions operate on a list? I think heapq.heapify is the answer:<br>
in linear time, it heapifies a list *in place*.<br>
<br>
I don't think there's any reason to have *both* interfaces to the heap<br>
functionality, but it certainly isn't illogical to try to treat a heap<br>
as a thing, and therefore have a Heap type.<br></blockquote><div><br></div></span>Right, the parallel here is that we have a "heapq" module for the same reason that we have list.sort(), sorted(), and the bisect module, rather than a single "SortedList" type. <a href="https://code.activestate.com/recipes/577197-sortedcollection/" target="_blank">https://code.activestate.com/r<wbr>ecipes/577197-sortedcollection<wbr>/</a> then provides an example of how to combine those into a "SortedCollection" type.<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">That said, I'm still in favour of adding an object-oriented wrapper to either `collections` or the `heapq` module for all the classic OO reasons:</div><div class="gmail_quote"><br></div><div class="gmail_quote">- it makes it easier to reliably maintain the heap invariant (just drop your list reference after passing it to the heap wrapper)</div><div class="gmail_quote">- it gives both human readers and static code analysers more information to work with ("this is a heap" rather than "this is a list")</div><div class="gmail_quote">- it provides a hook for improved interactive help on heap instances</div><div class="gmail_quote"><br></div><div class="gmail_quote">I don't have any great concerns about potential confusion - the OO wrapper will be easy enough to use that anyone that's unsure will likely gravitate towards that, while the lower level `heapq` functions will remain available for folks writing their own heap implementations.</div><div class="gmail_quote"><br></div><div class="gmail_quote">This effect would likely be even more pronounced if the OO wrapper were made available as `collections.Heap` (`collections` already imports the `heapq` module for use in the Counter implementation).<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">Cheers,</div><div class="gmail_quote">Nick.<span class="m_5862481244519462553HOEnZb"><font color="#888888"><br></font></span></div><span class="m_5862481244519462553HOEnZb"><font color="#888888"><br>-- <br><div class="m_5862481244519462553m_-2690528453096258751gmail_signature">Nick Coghlan   |   <a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>   |   Brisbane, Australia</div>
</font></span></div></div>
<br></div></div><span class="">______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
<br></span></blockquote></div><br></div>
</blockquote></div><br></div>