mirror of
https://github.com/python/cpython.git
synced 2024-11-26 03:14:27 +08:00
check_invariant(): Use the same child->parent "formula" used by heapq.py.
This commit is contained in:
parent
d9ea39db84
commit
d2cf1ab0e2
@ -8,8 +8,8 @@ import random
|
||||
def check_invariant(heap):
|
||||
# Check the heap invariant.
|
||||
for pos, item in enumerate(heap):
|
||||
parentpos = ((pos+1) >> 1) - 1
|
||||
if parentpos >= 0:
|
||||
if pos: # pos 0 has no parent
|
||||
parentpos = (pos-1) >> 1
|
||||
verify(heap[parentpos] <= item)
|
||||
|
||||
def test_main():
|
||||
|
Loading…
Reference in New Issue
Block a user