mirror of
https://github.com/python/cpython.git
synced 2025-10-03 05:35:59 +00:00
Use LT in all comparisons
This commit is contained in:
parent
221760a3aa
commit
975a8e8f76
1 changed files with 3 additions and 3 deletions
|
@ -181,7 +181,7 @@ def heapify(x):
|
||||||
|
|
||||||
def _heappushpop_max(heap, item):
|
def _heappushpop_max(heap, item):
|
||||||
"""Maxheap version of a heappush followed by a heappop."""
|
"""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
|
item, heap[0] = heap[0], item
|
||||||
_siftup_max(heap, 0)
|
_siftup_max(heap, 0)
|
||||||
return item
|
return item
|
||||||
|
@ -312,7 +312,7 @@ def _siftdown_max(heap, startpos, pos):
|
||||||
while pos > startpos:
|
while pos > startpos:
|
||||||
parentpos = (pos - 1) >> 1
|
parentpos = (pos - 1) >> 1
|
||||||
parent = heap[parentpos]
|
parent = heap[parentpos]
|
||||||
if newitem > parent:
|
if parent < newitem:
|
||||||
heap[pos] = parent
|
heap[pos] = parent
|
||||||
pos = parentpos
|
pos = parentpos
|
||||||
continue
|
continue
|
||||||
|
@ -329,7 +329,7 @@ def _siftup_max(heap, pos):
|
||||||
while childpos < endpos:
|
while childpos < endpos:
|
||||||
# Set childpos to index of larger child.
|
# Set childpos to index of larger child.
|
||||||
rightpos = childpos + 1
|
rightpos = childpos + 1
|
||||||
if rightpos < endpos and not heap[childpos] > heap[rightpos]:
|
if rightpos < endpos and not heap[rightpos] < heap[childpos]:
|
||||||
childpos = rightpos
|
childpos = rightpos
|
||||||
# Move the larger child up.
|
# Move the larger child up.
|
||||||
heap[pos] = heap[childpos]
|
heap[pos] = heap[childpos]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue