~pythonregexp2.7/python/issue2636-22

« back to all changes in this revision

Viewing changes to Lib/heapq.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-06-09 14:36:32 UTC
  • mfrom: (39021.1.402 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080609143632-wwwkx92u1t5l7yd3
Merged in changes from the latest python source snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
167
167
 
168
168
def heappushpop(heap, item):
169
169
    """Fast version of a heappush followed by a heappop."""
170
 
    if heap and item > heap[0]:
 
170
    if heap and heap[0] < item:
171
171
        item, heap[0] = heap[0], item
172
172
        _siftup(heap, 0)
173
173
    return item
240
240
    while pos > startpos:
241
241
        parentpos = (pos - 1) >> 1
242
242
        parent = heap[parentpos]
243
 
        if parent <= newitem:
244
 
            break
245
 
        heap[pos] = parent
246
 
        pos = parentpos
 
243
        if newitem < parent:
 
244
            heap[pos] = parent
 
245
            pos = parentpos
 
246
            continue
 
247
        break
247
248
    heap[pos] = newitem
248
249
 
249
250
# The child indices of heap index pos are already heaps, and we want to make
294
295
    while childpos < endpos:
295
296
        # Set childpos to index of smaller child.
296
297
        rightpos = childpos + 1
297
 
        if rightpos < endpos and heap[rightpos] <= heap[childpos]:
 
298
        if rightpos < endpos and not heap[childpos] < heap[rightpos]:
298
299
            childpos = rightpos
299
300
        # Move the smaller child up.
300
301
        heap[pos] = heap[childpos]