本文整理汇总了Python中sortedcontainers.SortedSet.bisect_left方法的典型用法代码示例。如果您正苦于以下问题:Python SortedSet.bisect_left方法的具体用法?Python SortedSet.bisect_left怎么用?Python SortedSet.bisect_left使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sortedcontainers.SortedSet
的用法示例。
在下文中一共展示了SortedSet.bisect_left方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SortedList
# 需要导入模块: from sortedcontainers import SortedSet [as 别名]
# 或者: from sortedcontainers.SortedSet import bisect_left [as 别名]
# http://www.grantjenks.com/docs/sortedcontainers/
from sortedcontainers import SortedList
sl = SortedList(['e', 'a', 'c', 'd', 'b'])
print(sl)
sl *= 10000000
print(sl.count('c'))
print(sl[-3:])
['e', 'e', 'e']
from sortedcontainers import SortedDict
sd = SortedDict({'c': 3, 'a': 1, 'b': 2})
print(sd)
SortedDict({'a': 1, 'b': 2, 'c': 3})
print(sd.popitem())
from sortedcontainers import SortedSet
ss = SortedSet('abracadabra')
print(ss)
print(ss.bisect_left('c'))
示例2: test_bisect
# 需要导入模块: from sortedcontainers import SortedSet [as 别名]
# 或者: from sortedcontainers.SortedSet import bisect_left [as 别名]
def test_bisect():
temp = SortedSet(range(100), load=7)
assert all(temp.bisect_left(val) == val for val in range(100))
assert all(temp.bisect(val) == val for val in range(100))
assert all(temp.bisect_right(val) == (val + 1) for val in range(100))
示例3: Selection
# 需要导入模块: from sortedcontainers import SortedSet [as 别名]
# 或者: from sortedcontainers.SortedSet import bisect_left [as 别名]
#.........这里部分代码省略.........
return from_index, to_index
def subslice(self, from_index: Optional[int], to_index: Optional[int]):
from_index, to_index = self._normalized_range(from_index, to_index)
sel = self._spanning_subslice(from_index, to_index)
if len(sel._intervals) % 2 == 0:
if len(sel) > 0:
if sel._intervals[0] < from_index < sel._intervals[1]:
sel._revealed_count -= from_index - sel._intervals[0]
del sel._intervals[0]
sel._intervals.add(from_index)
if sel._intervals[-2] < to_index < sel._intervals[-1]:
sel._revealed_count -= sel._intervals[-1] - to_index
del sel._intervals[-1]
sel._intervals.add(to_index)
else:
if 0 < from_index < sel._intervals[0]:
sel._revealed_count -= from_index
sel._intervals.add(from_index)
if (len(sel._intervals) == 1 and to_index < sel._intervals[-1]
or len(sel._intervals) >= 2 and sel._intervals[-2] < to_index < sel._intervals[-1]):
sel._revealed_count -= sel._intervals[-1] - to_index
del sel._intervals[-1]
sel._intervals.add(to_index)
return sel
def _spanning_subslice(self, from_index: int, to_index: int):
""" :return A Selection whose set of revealed slices is a subset of that of this Selection such that every index
in [from_index, to_index) is either on some slice in the subset, or on a gap. """
if from_index >= to_index:
return Selection(universe=deepcopy(self.universe), intervals=[])
m = self._intervals.bisect_right(from_index)
if len(self._intervals) % 2 == 0:
n = self._intervals.bisect_left(to_index)
intervals = self._intervals[m - (m % 2):n + (n % 2)]
else:
n = self._intervals.bisect_right(to_index)
a = max(0, m - ((m + 1) % 2))
b = n + ((n + 1) % 2)
intervals = self._intervals[a:b]
sel = Selection(universe=deepcopy(self.universe), intervals=intervals)
return sel
def _slow_subslice(self, from_index: Optional[int], to_index: Optional[int]):
sel = self.deepcopy()
if isinstance(from_index, int):
sel.exclude(None, from_index)
if isinstance(to_index, int):
sel.exclude(to_index, None)
return sel
def _interval_index(self, pindex):
""" :return n if the nth interval edge is the smallest number such that @pindex < n (zero-indexed). """
lower = 0
upper = len(self._intervals) - 1
while lower <= upper:
middle = (lower + upper) // 2
midsl = self._intervals[middle]
if pindex < midsl.start:
upper = middle - 1
elif midsl.stop <= pindex:
lower = middle + 1
else: # midsl.start <= pindex < midsl.stop:
return middle
raise IndexError("{} is not in any interval.".format(pindex))