[Python-Dev] heapq API
Raymond Hettinger
raymond.hettinger at verizon.net
Sat Jun 12 04:38:56 EDT 2004
Please give feedback on two proposed new functions heappushpop(heap,
item) and heapiter(heap). Both are intended to make the API more
closely fit the way heaps are actually used and to take maximum
advantage of the implementation.
The first is equivalent to:
def heappushpop(heap, item):
"Pushes the item onto the heap and then pops the smallest value"
if not heap or item < heap[0]:
return item
return heapreplace(heap, item)
def heapiter(heap):
"Return a destructive iterator over the heap's elements,
smallest-to-largest"
try:
while 1:
yield heappop(heap)
except IndexError:
pass
Raymond
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20040612/75c74107/attachment.html
More information about the Python-Dev
mailing list