check_invariant(): Use the same child->parent "formula" used by heapq.py.

This commit is contained in:
Tim Peters 2002-08-02 19:41:54 +00:00
parent d9ea39db84
commit d2cf1ab0e2
1 changed files with 2 additions and 2 deletions

View File

@ -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():