Bisect v0.1.0 Bisect View Source
Bisection algorithms ported from Python.
cpython/Lib/bisect.py
Link to this section Summary
Functions
Return the index where to insert item x in list a, assuming a is sorted. The return value i is such that all e in a[:i] have e < x, and all e in a[i:] have e >= x. So if x already appears in the list, a.insert(x) will insert just before the leftmost x already there. Optional keywords :lo (default 0) and :hi (default len(a)) bound the slice of a to be searched
Return the index where to insert item x in list a, assuming a is sorted. The return value i is such that all e in a[:i] have e <= x, and all e in a[i:] have e > x. So if x already appears in the list, a.insert(x) will insert just after the rightmost x already there. Optional keywords :lo (default 0) and :hi (default len(a)) bound the slice of a to be searched
Insert item x in list a, and keep it sorted assuming a is sorted. If x is already in a, insert it to the left of the leftmost x. Optional keywords :lo (default 0) and :hi (default len(a)) bound the slice of a to be searched
Insert item x in list a, and keep it sorted assuming a is sorted. If x is already in a, insert it to the right of the rightmost x. Optional keywords :lo (default 0) and :hi (default length(a)) bound the slice of a to be searched
Link to this section Functions
Return the index where to insert item x in list a, assuming a is sorted. The return value i is such that all e in a[:i] have e < x, and all e in a[i:] have e >= x. So if x already appears in the list, a.insert(x) will insert just before the leftmost x already there. Optional keywords :lo (default 0) and :hi (default len(a)) bound the slice of a to be searched.
Examples
iex> Bisect.bisect_left([1, 2], 1)
0
iex> Bisect.bisect_left([1, 2], 2)
1
iex> Bisect.bisect_left([1, 2], 4)
2
Return the index where to insert item x in list a, assuming a is sorted. The return value i is such that all e in a[:i] have e <= x, and all e in a[i:] have e > x. So if x already appears in the list, a.insert(x) will insert just after the rightmost x already there. Optional keywords :lo (default 0) and :hi (default len(a)) bound the slice of a to be searched.
Examples
iex> Bisect.bisect_right([1, 2], 1)
1
iex> Bisect.bisect_right([1, 2, 3], 4)
3
Insert item x in list a, and keep it sorted assuming a is sorted. If x is already in a, insert it to the left of the leftmost x. Optional keywords :lo (default 0) and :hi (default len(a)) bound the slice of a to be searched.
Examples
iex> Bisect.insort_left([1, 2, 3], 4)
[1, 2, 3, 4]
iex> Bisect.insort_left([2, 3, 4], 1)
[1, 2, 3, 4]
Insert item x in list a, and keep it sorted assuming a is sorted. If x is already in a, insert it to the right of the rightmost x. Optional keywords :lo (default 0) and :hi (default length(a)) bound the slice of a to be searched.
Examples
iex> Bisect.insort_right([1, 2], 3)
[1, 2, 3]
iex> Bisect.insort_right([1, 2, 3], 0)
[0, 1, 2, 3]