Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3....
File: bisect.py
"""Bisection algorithms."""
[0] Fix | Delete
[1] Fix | Delete
def insort_right(a, x, lo=0, hi=None):
[2] Fix | Delete
"""Insert item x in list a, and keep it sorted assuming a is sorted.
[3] Fix | Delete
[4] Fix | Delete
If x is already in a, insert it to the right of the rightmost x.
[5] Fix | Delete
[6] Fix | Delete
Optional args lo (default 0) and hi (default len(a)) bound the
[7] Fix | Delete
slice of a to be searched.
[8] Fix | Delete
"""
[9] Fix | Delete
[10] Fix | Delete
lo = bisect_right(a, x, lo, hi)
[11] Fix | Delete
a.insert(lo, x)
[12] Fix | Delete
[13] Fix | Delete
def bisect_right(a, x, lo=0, hi=None):
[14] Fix | Delete
"""Return the index where to insert item x in list a, assuming a is sorted.
[15] Fix | Delete
[16] Fix | Delete
The return value i is such that all e in a[:i] have e <= x, and all e in
[17] Fix | Delete
a[i:] have e > x. So if x already appears in the list, a.insert(x) will
[18] Fix | Delete
insert just after the rightmost x already there.
[19] Fix | Delete
[20] Fix | Delete
Optional args lo (default 0) and hi (default len(a)) bound the
[21] Fix | Delete
slice of a to be searched.
[22] Fix | Delete
"""
[23] Fix | Delete
[24] Fix | Delete
if lo < 0:
[25] Fix | Delete
raise ValueError('lo must be non-negative')
[26] Fix | Delete
if hi is None:
[27] Fix | Delete
hi = len(a)
[28] Fix | Delete
while lo < hi:
[29] Fix | Delete
mid = (lo+hi)//2
[30] Fix | Delete
if x < a[mid]: hi = mid
[31] Fix | Delete
else: lo = mid+1
[32] Fix | Delete
return lo
[33] Fix | Delete
[34] Fix | Delete
def insort_left(a, x, lo=0, hi=None):
[35] Fix | Delete
"""Insert item x in list a, and keep it sorted assuming a is sorted.
[36] Fix | Delete
[37] Fix | Delete
If x is already in a, insert it to the left of the leftmost x.
[38] Fix | Delete
[39] Fix | Delete
Optional args lo (default 0) and hi (default len(a)) bound the
[40] Fix | Delete
slice of a to be searched.
[41] Fix | Delete
"""
[42] Fix | Delete
[43] Fix | Delete
lo = bisect_left(a, x, lo, hi)
[44] Fix | Delete
a.insert(lo, x)
[45] Fix | Delete
[46] Fix | Delete
[47] Fix | Delete
def bisect_left(a, x, lo=0, hi=None):
[48] Fix | Delete
"""Return the index where to insert item x in list a, assuming a is sorted.
[49] Fix | Delete
[50] Fix | Delete
The return value i is such that all e in a[:i] have e < x, and all e in
[51] Fix | Delete
a[i:] have e >= x. So if x already appears in the list, a.insert(x) will
[52] Fix | Delete
insert just before the leftmost x already there.
[53] Fix | Delete
[54] Fix | Delete
Optional args lo (default 0) and hi (default len(a)) bound the
[55] Fix | Delete
slice of a to be searched.
[56] Fix | Delete
"""
[57] Fix | Delete
[58] Fix | Delete
if lo < 0:
[59] Fix | Delete
raise ValueError('lo must be non-negative')
[60] Fix | Delete
if hi is None:
[61] Fix | Delete
hi = len(a)
[62] Fix | Delete
while lo < hi:
[63] Fix | Delete
mid = (lo+hi)//2
[64] Fix | Delete
if a[mid] < x: lo = mid+1
[65] Fix | Delete
else: hi = mid
[66] Fix | Delete
return lo
[67] Fix | Delete
[68] Fix | Delete
# Overwrite above definitions with a fast C implementation
[69] Fix | Delete
try:
[70] Fix | Delete
from _bisect import *
[71] Fix | Delete
except ImportError:
[72] Fix | Delete
pass
[73] Fix | Delete
[74] Fix | Delete
# Create aliases
[75] Fix | Delete
bisect = bisect_right
[76] Fix | Delete
insort = insort_right
[77] Fix | Delete
[78] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function