本文整理汇总了Python中sortedcontainers.SortedList方法的典型用法代码示例。如果您正苦于以下问题:Python sortedcontainers.SortedList方法的具体用法?Python sortedcontainers.SortedList怎么用?Python sortedcontainers.SortedList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sortedcontainers
的用法示例。
在下文中一共展示了sortedcontainers.SortedList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _getOpcodeAddrs
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def _getOpcodeAddrs(self):
# TODO: lazy load?
addrs = SortedList()
funcs = self.getFunctions()
for f in funcs:
print('addrs for', f['name'])
ofs = f['offset']
sz = f['size']
end = ofs + sz
self.seek(ofs)
cur = ofs
while cur < end:
addrs.add(cur)
self.cmd('so')
cur = self.tell()
return addrs
示例2: test_init
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_init():
slt = SortedList()
slt._check()
slt = SortedList(load=10000)
assert slt._load == 10000
assert slt._twice == 20000
assert slt._half == 5000
slt._check()
slt = SortedList(range(10000))
assert all(tup[0] == tup[1] for tup in zip(slt, range(10000)))
slt.clear()
assert slt._len == 0
assert slt._maxes == []
assert slt._lists == []
slt._check()
示例3: test_add
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_add():
random.seed(0)
slt = SortedList()
for val in range(1000):
slt.add(val)
slt._check()
slt = SortedList()
for val in range(1000, 0, -1):
slt.add(val)
slt._check()
slt = SortedList()
for val in range(1000):
slt.add(random.random())
slt._check()
示例4: test_discard
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_discard():
slt = SortedList()
assert slt.discard(0) == None
assert len(slt) == 0
slt._check()
slt = SortedList([1, 2, 2, 2, 3, 3, 5], load=4)
slt.discard(6)
slt._check()
slt.discard(4)
slt._check()
slt.discard(2)
slt._check()
assert all(tup[0] == tup[1] for tup in zip(slt, [1, 2, 2, 3, 3, 5]))
示例5: test_islice
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_islice():
sl = SortedList(load=7)
assert [] == list(sl.islice())
values = list(range(53))
sl.update(values)
for start in range(53):
for stop in range(53):
assert list(sl.islice(start, stop)) == values[start:stop]
for start in range(53):
for stop in range(53):
assert list(sl.islice(start, stop, reverse=True)) == values[start:stop][::-1]
for start in range(53):
assert list(sl.islice(start=start)) == values[start:]
assert list(sl.islice(start=start, reverse=True)) == values[start:][::-1]
for stop in range(53):
assert list(sl.islice(stop=stop)) == values[:stop]
assert list(sl.islice(stop=stop, reverse=True)) == values[:stop][::-1]
示例6: test_insert
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_insert():
slt = SortedList(range(10), load=4)
slt.insert(-1, 9)
slt._check()
slt.insert(-100, 0)
slt._check()
slt.insert(100, 10)
slt._check()
slt = SortedList(load=4)
slt.insert(0, 5)
slt._check()
slt = SortedList(range(5, 15), load=4)
for rpt in range(8):
slt.insert(0, 4)
slt._check()
slt = SortedList(range(10), load=4)
slt.insert(8, 8)
slt._check()
示例7: test_index
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_index():
slt = SortedList(range(100), load=17)
for val in range(100):
assert val == slt.index(val)
assert slt.index(99, 0, 1000) == 99
slt = SortedList((0 for rpt in range(100)), load=17)
for start in range(100):
for stop in range(start, 100):
assert slt.index(0, start, stop + 1) == start
for start in range(100):
assert slt.index(0, -(100 - start)) == start
assert slt.index(0, -1000) == 0
示例8: test_init
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_init():
slt = SortedListWithKey(key=modulo)
slt._check()
slt = SortedListWithKey(load=10000, key=modulo)
assert slt._load == 10000
assert slt._twice == 20000
assert slt._half == 5000
slt._check()
slt = SortedListWithKey(range(10000), key=modulo)
assert all(tup[0] == tup[1] for tup in zip(slt, sorted(range(10000), key=modulo)))
slt.clear()
assert slt._len == 0
assert slt._maxes == []
assert slt._lists == []
assert isinstance(slt, SortedList)
assert isinstance(slt, SortedListWithKey)
slt._check()
示例9: get_lowest_probable_prepared_certificate_in_view
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def get_lowest_probable_prepared_certificate_in_view(
self, view_no) -> Optional[int]:
"""
Return lowest pp_seq_no of the view for which can be prepared but
choose from unprocessed PRE-PREPAREs and PREPAREs.
"""
# TODO: Naive implementation, dont need to iterate over the complete
# data structures, fix this later
seq_no_pp = SortedList() # pp_seq_no of PRE-PREPAREs
# pp_seq_no of PREPAREs with count of PREPAREs for each
seq_no_p = set()
for (v, p) in self._ordering_service.prePreparesPendingPrevPP:
if v == view_no:
seq_no_pp.add(p)
if v > view_no:
break
for (v, p), pr in self._ordering_service.preparesWaitingForPrePrepare.items():
if v == view_no and len(pr) >= self.quorums.prepare.value:
seq_no_p.add(p)
for n in seq_no_pp:
if n in seq_no_p:
return n
return None
示例10: l_get_lowest_probable_prepared_certificate_in_view
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def l_get_lowest_probable_prepared_certificate_in_view(
self, view_no) -> Optional[int]:
"""
Return lowest pp_seq_no of the view for which can be prepared but
choose from unprocessed PRE-PREPAREs and PREPAREs.
"""
# TODO: Naive implementation, dont need to iterate over the complete
# data structures, fix this later
seq_no_pp = SortedList() # pp_seq_no of PRE-PREPAREs
# pp_seq_no of PREPAREs with count of PREPAREs for each
seq_no_p = set()
for (v, p) in self.prePreparesPendingPrevPP:
if v == view_no:
seq_no_pp.add(p)
if v > view_no:
break
for (v, p), pr in self.preparesWaitingForPrePrepare.items():
if v == view_no and len(pr) >= self._data.quorums.prepare.value:
seq_no_p.add(p)
for n in seq_no_pp:
if n in seq_no_p:
return n
return None
示例11: stress_index2
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def stress_index2(slt):
values = list(slt)[:3] * 200
slt = SortedList(values)
for idx, val in enumerate(slt):
assert slt.index(val, idx) == idx
示例12: stress_lt
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def stress_lt(slt):
values = list(slt)
assert not (values < slt)
values = SortedList(value - 1 for value in values)
assert values < slt
values = []
assert values < slt
assert not (slt < values)
示例13: test_contains
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_contains():
slt = SortedList()
assert 0 not in slt
slt.update(range(10000))
for val in range(10000):
assert val in slt
assert 10000 not in slt
slt._check()
示例14: test_remove
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_remove():
slt = SortedList()
assert slt.discard(0) == None
assert len(slt) == 0
slt._check()
slt = SortedList([1, 2, 2, 2, 3, 3, 5], load=4)
slt.remove(2)
slt._check()
assert all(tup[0] == tup[1] for tup in zip(slt, [1, 2, 2, 3, 3, 5]))
示例15: test_remove_valueerror1
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedList [as 别名]
def test_remove_valueerror1():
slt = SortedList()
slt.remove(0)