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