本文整理汇总了Python中bisect.insort_left方法的典型用法代码示例。如果您正苦于以下问题:Python bisect.insort_left方法的具体用法?Python bisect.insort_left怎么用?Python bisect.insort_left使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bisect
的用法示例。
在下文中一共展示了bisect.insort_left方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_section
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def add_section(self, start_address, name, virt_size, real_size,
is_exec, is_data, is_bss, data):
if is_exec or is_data:
bisect.insort_left(self._sorted_sections, start_address)
self._abs_sections[start_address] = SectionAbs(
name,
start_address,
virt_size,
real_size,
is_exec,
is_data,
is_bss,
data)
# for elf
示例2: _update_tag_positions
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def _update_tag_positions(self, rule):
"""
Update _tag_positions to reflect the changes to tags that are
made by *rule*.
"""
# Update the tag index.
for pos in self._positions_by_rule[rule]:
# Delete the old tag.
old_tag_positions = self._tag_positions[rule.original_tag]
old_index = bisect.bisect_left(old_tag_positions, pos)
del old_tag_positions[old_index]
# Insert the new tag.
new_tag_positions = self._tag_positions[rule.replacement_tag]
bisect.insort_left(new_tag_positions, pos)
示例3: _order_cluster_tree
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def _order_cluster_tree(Z):
"""
Return clustering nodes in bottom-up order by distance.
Parameters
----------
Z : scipy.cluster.linkage array
The linkage matrix.
Returns
-------
nodes : list
A list of ClusterNode objects.
"""
q = deque()
tree = to_tree(Z)
q.append(tree)
nodes = []
while q:
node = q.popleft()
if not node.is_leaf():
bisect.insort_left(nodes, node)
q.append(node.get_right())
q.append(node.get_left())
return nodes
示例4: fillInSnpSlotsWithOverflowers
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def fillInSnpSlotsWithOverflowers(newPositions, totalPhysLen, overflowers):
posH = {}
for pos in newPositions:
posH[pos] = 1
for i in range(len(overflowers)):
del newPositions[-1]
for pos in reversed(range(1, totalPhysLen+1)):
if pos not in posH:
bisect.insort_left(newPositions, pos)
overflowers.pop()
if len(overflowers) == 0:
break
示例5: add_domain
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def add_domain(candidate, domains):
'''
Use binary search to add the new domain `candidate`
to the candidate list `domains` so that `domains` remains a sorted list.
'''
bisect.insort_left(domains, candidate)
示例6: _insort_call
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def _insort_call(self, call):
# We want to insert the call in the appropriate time slot. A simple
# bisect.insort_left() is not sufficient as the comparison of two
# methods is not defined in Python 3.
times = [c[0] for c in self._calls]
index = bisect.bisect_left(times, call[0])
self._calls.insert(index, call)
示例7: add
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def add(self, state: State) -> None:
self.index_to_state[state.index] = state
bisect.insort_left(self.ordered_index, state.index)
示例8: add_major
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def add_major(self, state: State) -> None:
# NOTE: major means the interval stubs
self.add(state)
bisect.insort_left(self.major_index, state.index)
示例9: _order_cluster_tree
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def _order_cluster_tree(Z):
"""
Returns clustering nodes in bottom-up order by distance.
Parameters
----------
Z : scipy.cluster.linkage array
The linkage matrix.
Returns
-------
nodes : list
A list of ClusterNode objects.
"""
q = deque()
tree = to_tree(Z)
q.append(tree)
nodes = []
while q:
node = q.popleft()
if not node.is_leaf():
bisect.insort_left(nodes, node)
q.append(node.get_right())
q.append(node.get_left())
return nodes
示例10: _InsertTask
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def _InsertTask(self, task):
"""Insert a task into the dummy store, keeps lists sorted.
Args:
task: the new task.
"""
eta = task.eta_usec()
name = task.task_name()
bisect.insort_left(self._sorted_by_eta, (eta, name, task))
bisect.insort_left(self._sorted_by_name, (name, task))
示例11: _InsertTask
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def _InsertTask(self, task):
"""Insert a task into the store, keeps lists sorted.
Args:
task: the new task.
"""
assert self._lock.locked()
eta = task.eta_usec()
name = task.task_name()
bisect.insort_left(self._sorted_by_eta, (eta, name, task))
if task.has_tag():
bisect.insort_left(self._sorted_by_tag, (task.tag(), eta, name, task))
bisect.insort_left(self._sorted_by_name, (name, task))
self.task_name_archive.add(name)
示例12: _PostponeTaskInsertOnly
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def _PostponeTaskInsertOnly(self, task, new_eta_usec):
assert self._lock.locked()
task.set_eta_usec(new_eta_usec)
name = task.task_name()
bisect.insort_left(self._sorted_by_eta, (new_eta_usec, name, task))
if task.has_tag():
tag = task.tag()
bisect.insort_left(self._sorted_by_tag, (tag, new_eta_usec, name, task))
示例13: test_keyword_args
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def test_keyword_args(self):
data = [10, 20, 30, 40, 50]
self.assertEqual(bisect_left(a=data, x=25, lo=1, hi=3), 2)
self.assertEqual(bisect_right(a=data, x=25, lo=1, hi=3), 2)
self.assertEqual(bisect(a=data, x=25, lo=1, hi=3), 2)
insort_left(a=data, x=25, lo=1, hi=3)
insort_right(a=data, x=25, lo=1, hi=3)
insort(a=data, x=25, lo=1, hi=3)
self.assertEqual(data, [10, 20, 25, 25, 25, 30, 40, 50])
#==============================================================================
示例14: test_vsBuiltinSort
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def test_vsBuiltinSort(self, n=500):
from random import choice
for insorted in (list(), UserList()):
for i in xrange(n):
digit = choice("0123456789")
if digit in "02468":
f = insort_left
else:
f = insort_right
f(insorted, digit)
self.assertEqual(sorted(insorted), insorted)
示例15: test_non_sequence
# 需要导入模块: import bisect [as 别名]
# 或者: from bisect import insort_left [as 别名]
def test_non_sequence(self):
for f in (bisect_left, bisect_right, insort_left, insort_right):
self.assertRaises(TypeError, f, 10, 10)