本文整理汇总了Python中sortedcontainers.SortedKeyList._check方法的典型用法代码示例。如果您正苦于以下问题:Python SortedKeyList._check方法的具体用法?Python SortedKeyList._check怎么用?Python SortedKeyList._check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sortedcontainers.SortedKeyList
的用法示例。
在下文中一共展示了SortedKeyList._check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_key
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_key():
slt = SortedKeyList(range(10000), key=lambda val: val % 10)
slt._check()
values = sorted(range(10000), key=lambda val: (val % 10, val))
assert slt == values
assert all(val in slt for val in range(10000))
示例2: test_delitem
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_delitem():
random.seed(0)
slt = SortedKeyList(range(100), key=negate)
slt._reset(17)
while len(slt) > 0:
del slt[random.randrange(len(slt))]
slt._check()
示例3: test_bisect_right
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_bisect_right():
slt = SortedKeyList(key=modulo)
assert slt.bisect_right(10) == 0
slt = SortedKeyList(range(100), key=modulo)
slt._reset(17)
slt.update(range(100))
slt._check()
assert slt.bisect_right(10) == 20
assert slt.bisect_right(0) == 20
示例4: test_bisect
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_bisect():
slt = SortedKeyList(key=negate)
assert slt.bisect(10) == 0
slt = SortedKeyList(range(100), key=negate)
slt._reset(17)
slt.update(range(100))
slt._check()
assert slt.bisect(10) == 180
assert slt.bisect(0) == 200
示例5: test_delete
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_delete():
slt = SortedKeyList(range(20), key=modulo)
slt._reset(4)
slt._check()
for val in range(20):
slt.remove(val)
slt._check()
assert len(slt) == 0
assert slt._maxes == []
assert slt._lists == []
示例6: test_update
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_update():
slt = SortedKeyList(key=modulo)
slt.update(range(1000))
assert all(tup[0] == tup[1] for tup in zip(slt, sorted(range(1000), key=modulo)))
assert len(slt) == 1000
slt._check()
slt.update(range(10000))
assert len(slt) == 11000
slt._check()
示例7: test_pop
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_pop():
slt = SortedKeyList(range(10), key=modulo)
slt._reset(4)
slt._check()
assert slt.pop() == 9
slt._check()
assert slt.pop(0) == 0
slt._check()
assert slt.pop(-2) == 7
slt._check()
assert slt.pop(4) == 5
slt._check()
示例8: test_pop
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_pop():
slt = SortedKeyList(range(10), key=negate)
slt._reset(4)
slt._check()
assert slt.pop() == 0
slt._check()
assert slt.pop(0) == 9
slt._check()
assert slt.pop(-2) == 2
slt._check()
assert slt.pop(4) == 4
slt._check()
示例9: test_contains
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_contains():
slt = SortedKeyList(key=negate)
assert 0 not in slt
slt.update(range(10000))
for val in range(10000):
assert val in slt
assert 10000 not in slt
assert -1 not in slt
slt._check()
示例10: test_count
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_count():
slt = SortedKeyList(key=negate)
slt._reset(7)
assert slt.count(0) == 0
for iii in range(100):
for jjj in range(iii):
slt.add(iii)
slt._check()
for iii in range(100):
assert slt.count(iii) == iii
示例11: test_delitem
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_delitem():
random.seed(0)
slt = SortedKeyList(range(100), key=modulo)
slt._reset(17)
while len(slt) > 0:
del slt[random.randrange(len(slt))]
slt._check()
slt = SortedKeyList(range(100), key=modulo)
slt._reset(17)
del slt[:]
assert len(slt) == 0
slt._check()
示例12: test_remove
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_remove():
slt = SortedKeyList(key=modulo)
assert slt.discard(0) == None
assert len(slt) == 0
slt._check()
slt = SortedKeyList([1, 2, 2, 2, 3, 3, 5], key=modulo)
slt._reset(4)
slt.remove(2)
slt._check()
assert all(tup[0] == tup[1] for tup in zip(slt, [1, 2, 2, 3, 3, 5]))
示例13: test_stress
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_stress(repeat=1000):
slt = SortedKeyList((random.random() for rpt in range(1000)))
for rpt in range(repeat):
action = random.choice(actions)
action(slt)
slt._check()
while len(slt) > 2000:
# Shorten the sortedlist. This maintains the "jaggedness"
# of the sublists which helps coverage.
pos = random.randrange(len(slt._maxes))
del slt._maxes[pos]
del slt._keys[pos]
del slt._lists[pos]
slt._len = sum(len(sublist) for sublist in slt._lists)
slt._index = []
slt._check()
slt._check()
stress_update(slt)
while len(slt) > 0:
pos = random.randrange(len(slt))
del slt[pos]
slt._check()
示例14: test_getitem
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_getitem():
random.seed(0)
slt = SortedKeyList(key=modulo)
slt._reset(17)
slt.add(5)
slt._build_index()
slt._check()
slt.clear()
lst = list(random.random() for rpt in range(100))
slt.update(lst)
lst.sort(key=modulo)
assert all(slt[idx] == lst[idx] for idx in range(100))
assert all(slt[idx - 99] == lst[idx - 99] for idx in range(100))
示例15: test_count
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import _check [as 别名]
def test_count():
slt = SortedKeyList(key=modulo)
slt._reset(7)
assert slt.count(0) == 0
for iii in range(100):
for jjj in range(iii):
slt.add(iii)
slt._check()
for iii in range(100):
assert slt.count(iii) == iii
slt = SortedKeyList(range(8), key=modulo)
assert slt.count(9) == 0