From: Tim Peters Date: Fri, 2 Aug 2002 19:16:44 +0000 (+0000) Subject: Don't use true division where int division was intended. For that matter, X-Git-Tag: v2.3c1~4768 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d9ea39db84a78b3b994943bc7490615dfe6b009d;p=python Don't use true division where int division was intended. For that matter, don't use division at all. --- diff --git a/Lib/heapq.py b/Lib/heapq.py index cdba693b6d..6264700ee4 100644 --- a/Lib/heapq.py +++ b/Lib/heapq.py @@ -126,7 +126,7 @@ def heappush(heap, item): pos = len(heap) heap.append(None) while pos: - parentpos = (pos - 1) / 2 + parentpos = (pos - 1) >> 1 parent = heap[parentpos] if item >= parent: break diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py index 43723f33f6..016fd3af41 100644 --- a/Lib/test/test_heapq.py +++ b/Lib/test/test_heapq.py @@ -8,7 +8,7 @@ import random def check_invariant(heap): # Check the heap invariant. for pos, item in enumerate(heap): - parentpos = (pos+1)/2 - 1 + parentpos = ((pos+1) >> 1) - 1 if parentpos >= 0: verify(heap[parentpos] <= item)