def _heappushpop_max(heap, item):
"""Maxheap version of a heappush followed by a heappop."""
- if heap and heap[0] > item:
+ if heap and item < heap[0]:
item, heap[0] = heap[0], item
_siftup_max(heap, 0)
return item
while pos > startpos:
parentpos = (pos - 1) >> 1
parent = heap[parentpos]
- if newitem > parent:
+ if parent < newitem:
heap[pos] = parent
pos = parentpos
continue
while childpos < endpos:
# Set childpos to index of larger child.
rightpos = childpos + 1
- if rightpos < endpos and not heap[childpos] > heap[rightpos]:
+ if rightpos < endpos and not heap[rightpos] < heap[childpos]:
childpos = rightpos
# Move the larger child up.
heap[pos] = heap[childpos]