Staging
v0.8.1
v0.8.1
Revision fa38b3ee749388386914a6584b4c7d97aa474abe authored by cvs2svn on 22 December 1998, 21:43:35 UTC, committed by cvs2svn on 22 December 1998, 21:43:35 UTC
1 parent 45d2ae5
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 ...