Staging
v0.8.1
v0.8.1
Revision 22cf34795534220f1bf47013e4a7f0a5502ba3fb authored by cvs2svn on 26 November 1997, 21:20:51 UTC, committed by cvs2svn on 26 November 1997, 21:20:51 UTC
1 parent 8253671
bisect.py
# Bisection algorithms
# Insert item x in list a, and keep it sorted assuming a is sorted
def insort(a, x, lo=0, hi=None):
if hi is None:
hi = len(a)
while lo < hi:
mid = (lo+hi)/2
if x < a[mid]: hi = mid
else: lo = mid+1
a.insert(lo, x)
# Find the index where to insert item x in list a, assuming a is sorted
def bisect(a, x, lo=0, hi=None):
if hi is None:
hi = len(a)
while lo < hi:
mid = (lo+hi)/2
if x < a[mid]: hi = mid
else: lo = mid+1
return lo
Computing file changes ...