summaryrefslogtreecommitdiffstats
path: root/Lib/heapq.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2007-02-19 05:28:28 (GMT)
committerRaymond Hettinger <python@rcn.com>2007-02-19 05:28:28 (GMT)
commit54da9819cc74fe6091d090d12753116cfb6c6c62 (patch)
tree36528e899b1424923fe98a08c42f621131e5e547 /Lib/heapq.py
parent00166c5532fc7562c07383a0ae2985b3ffaf253a (diff)
downloadcpython-54da9819cc74fe6091d090d12753116cfb6c6c62.zip
cpython-54da9819cc74fe6091d090d12753116cfb6c6c62.tar.gz
cpython-54da9819cc74fe6091d090d12753116cfb6c6c62.tar.bz2
Add tie-breaker count to preserve sort stability.
Diffstat (limited to 'Lib/heapq.py')
-rw-r--r--Lib/heapq.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/Lib/heapq.py b/Lib/heapq.py
index b56d0f9..4c11eb6 100644
--- a/Lib/heapq.py
+++ b/Lib/heapq.py
@@ -323,10 +323,10 @@ def merge(*iterables):
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 @@ def merge(*iterables):
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