A note on heapq module

Steven Bethard steven.bethard at gmail.com
Tue Jan 16 12:43:18 EST 2007


bearophileHUGS at lycos.com wrote:
> some time ago I have written a bug
> into small program that uses the functions of the heapq module, because
> I have added an item to the head of the heap using a normal list
> method, breaking the heap invariant.

I know I've had similar bugs in my code before.

> from heapq import heapify, heappush, heappop, heapreplace
> 
> class Heap(object):
[snip implementation]

+1 for adding a Heap object like this to the collections module. If you 
can make a little time to add some tests (you could probably steal a lot 
of what you need from test_heapq.py) you should definitely submit it as 
a patch for 2.6.

STeVe



More information about the Python-list mailing list