Commit d9ea39db authored by Tim Peters's avatar Tim Peters

Don't use true division where int division was intended. For that matter,

don't use division at all.
parent b4812865
...@@ -126,7 +126,7 @@ def heappush(heap, item): ...@@ -126,7 +126,7 @@ def heappush(heap, item):
pos = len(heap) pos = len(heap)
heap.append(None) heap.append(None)
while pos: while pos:
parentpos = (pos - 1) / 2 parentpos = (pos - 1) >> 1
parent = heap[parentpos] parent = heap[parentpos]
if item >= parent: if item >= parent:
break break
......
...@@ -8,7 +8,7 @@ import random ...@@ -8,7 +8,7 @@ import random
def check_invariant(heap): def check_invariant(heap):
# Check the heap invariant. # Check the heap invariant.
for pos, item in enumerate(heap): for pos, item in enumerate(heap):
parentpos = (pos+1)/2 - 1 parentpos = ((pos+1) >> 1) - 1
if parentpos >= 0: if parentpos >= 0:
verify(heap[parentpos] <= item) verify(heap[parentpos] <= item)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment