Staging
v0.5.1
https://github.com/python/cpython
Revision 176bb41efa974a88406d5c7b15341cccea77afd7 authored by Guido van Rossum on 07 October 1997, 16:17:55 UTC, committed by Guido van Rossum on 07 October 1997, 16:17:55 UTC
1 parent 9337453
Raw File
Tip revision: 176bb41efa974a88406d5c7b15341cccea77afd7 authored by Guido van Rossum on 07 October 1997, 16:17:55 UTC
Add the Setup line for the pcre module.
Tip revision: 176bb41
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
back to top