本文整理匯總了Python中sortedcontainers.SortedList._reset方法的典型用法代碼示例。如果您正苦於以下問題:Python SortedList._reset方法的具體用法?Python SortedList._reset怎麽用?Python SortedList._reset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sortedcontainers.SortedList
的用法示例。
在下文中一共展示了SortedList._reset方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_delitem_slice
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [as 別名]
def test_delitem_slice():
slt = SortedList(range(100))
slt._reset(17)
del slt[10:40:1]
del slt[10:40:-1]
del slt[10:40:2]
del slt[10:40:-2]
示例2: test_copy
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [as 別名]
def test_copy():
alpha = SortedList(range(100))
alpha._reset(7)
beta = alpha.copy()
alpha.add(100)
assert len(alpha) == 101
assert len(beta) == 100
示例3: test_copy_copy
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [as 別名]
def test_copy_copy():
import copy
alpha = SortedList(range(100))
alpha._reset(7)
beta = copy.copy(alpha)
alpha.add(100)
assert len(alpha) == 101
assert len(beta) == 100
示例4: test_pickle
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [as 別名]
def test_pickle():
import pickle
alpha = SortedList(range(10000))
alpha._reset(500)
beta = pickle.loads(pickle.dumps(alpha))
assert alpha == beta
assert alpha._load == 500
assert beta._load == 1000
示例5: test_bisect_left
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [as 別名]
def test_bisect_left():
slt = SortedList()
assert slt.bisect_left(0) == 0
slt = SortedList(range(100))
slt._reset(17)
slt.update(range(100))
slt._check()
assert slt.bisect_left(50) == 100
assert slt.bisect_left(200) == 200
示例6: test_bisect_right
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [as 別名]
def test_bisect_right():
slt = SortedList()
assert slt.bisect_right(10) == 0
slt = SortedList(range(100))
slt._reset(17)
slt.update(range(100))
slt._check()
assert slt.bisect_right(10) == 22
assert slt.bisect_right(200) == 200
示例7: test_op_add
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [as 別名]
def test_op_add():
this = SortedList(range(10))
this._reset(4)
assert (this + this + this) == (this * 3)
that = SortedList(range(10))
that._reset(4)
that += that
that += that
assert that == (this * 4)
示例8: test_delete
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [as 別名]
def test_delete():
slt = SortedList(range(20))
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 == []
示例9: test_pop
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [as 別名]
def test_pop():
slt = SortedList(range(10))
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()
示例10: test_remove
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [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])
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]))
示例11: test_count
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [as 別名]
def test_count():
slt = SortedList()
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
assert slt.count(100) == 0
示例12: test_delitem
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [as 別名]
def test_delitem():
random.seed(0)
slt = SortedList(range(100))
slt._reset(17)
while len(slt) > 0:
pos = random.randrange(len(slt))
del slt[pos]
slt._check()
slt = SortedList(range(100))
slt._reset(17)
del slt[:]
assert len(slt) == 0
slt._check()
示例13: test_getitem
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [as 別名]
def test_getitem():
random.seed(0)
slt = SortedList()
slt._reset(17)
lst = list()
for rpt in range(100):
val = random.random()
slt.add(val)
lst.append(val)
lst.sort()
assert all(slt[idx] == lst[idx] for idx in range(100))
assert all(slt[idx - 99] == lst[idx - 99] for idx in range(100))
示例14: test_init
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [as 別名]
def test_init():
slt = SortedList()
assert slt.key is None
slt._check()
slt = SortedList()
slt._reset(10000)
assert slt._load == 10000
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()
示例15: test_stress
# 需要導入模塊: from sortedcontainers import SortedList [as 別名]
# 或者: from sortedcontainers.SortedList import _reset [as 別名]
def test_stress(repeat=1000):
slt = SortedList((random.random() for rpt in range(1000)))
slt._reset(23)
for rpt in range(repeat):
action = random.choice(actions)
action(slt)
slt._check()
fourth = int(len(slt) / 4)
count = 0 if fourth == 0 else random.randrange(-fourth, fourth)
while count > 0:
slt.add(random.random())
count -= 1
while count < 0:
pos = random.randrange(len(slt))
del slt[pos]
count += 1
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._lists[pos]
slt._len = sum(len(sublist) for sublist in slt._lists)
slt._index = []
slt._check()
slt._check()
slt._check()
stress_update(slt)
while len(slt) > 0:
pos = random.randrange(len(slt))
del slt[pos]
slt._check()