[Python-checkins] r53821 - python/trunk/Lib/heapq.py
raymond.hettinger
python-checkins at python.org
Mon Feb 19 06:28:34 CET 2007
Author: raymond.hettinger
Date: Mon Feb 19 06:28:28 2007
New Revision: 53821
Modified:
python/trunk/Lib/heapq.py
Log:
Add tie-breaker count to preserve sort stability.
Modified: python/trunk/Lib/heapq.py
==============================================================================
--- python/trunk/Lib/heapq.py (original)
+++ python/trunk/Lib/heapq.py Mon Feb 19 06:28:28 2007
@@ -323,10 +323,10 @@
h = []
h_append = h.append
- for it in map(iter, iterables):
+ for itnum, it in enumerate(map(iter, iterables)):
try:
next = it.next
- h_append([next(), next])
+ h_append([next(), itnum, next])
except _StopIteration:
pass
heapify(h)
@@ -334,12 +334,12 @@
while 1:
try:
while 1:
- v, next = s = h[0] # raises IndexError when h is empty
+ v, itnum, next = s = h[0] # raises IndexError when h is empty
yield v
- s[0] = next() # raises StopIteration when exhausted
- siftup(h, 0) # restore heap condition
+ s[0] = next() # raises StopIteration when exhausted
+ siftup(h, 0) # restore heap condition
except _StopIteration:
- _heappop(h) # remove empty iterator
+ _heappop(h) # remove empty iterator
except IndexError:
return
More information about the Python-checkins
mailing list