本文整理汇总了Python中sortedcontainers.SortedKeyList.clear方法的典型用法代码示例。如果您正苦于以下问题:Python SortedKeyList.clear方法的具体用法?Python SortedKeyList.clear怎么用?Python SortedKeyList.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sortedcontainers.SortedKeyList
的用法示例。
在下文中一共展示了SortedKeyList.clear方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_eq
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import clear [as 别名]
def test_eq():
this = SortedKeyList(range(10), key=negate)
this._reset(4)
that = SortedKeyList(range(20), key=negate)
that._reset(4)
assert not (this == that)
that.clear()
that.update(range(10))
assert this == that
示例2: test_getitem
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import clear [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))
示例3: test_init
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import clear [as 别名]
def test_init():
slt = SortedKeyList(key=negate)
slt._check()
slt = SortedKeyList(key=negate)
slt._reset(10000)
assert slt._load == 10000
slt._check()
slt = SortedKeyList(range(10000), key=negate)
assert all(tup[0] == tup[1] for tup in zip(slt, reversed(range(10000))))
slt.clear()
assert slt._len == 0
assert slt._maxes == []
assert slt._lists == []
slt._check()
示例4: test_getitem
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import clear [as 别名]
def test_getitem():
random.seed(0)
slt = SortedKeyList(key=negate)
slt._reset(17)
slt.add(5)
assert slt[0] == 5
slt.clear()
lst = list()
for rpt in range(100):
val = random.random()
slt.add(val)
lst.append(val)
lst.sort(reverse=True)
assert all(slt[idx] == lst[idx] for idx in range(100))
assert all(slt[idx - 99] == lst[idx - 99] for idx in range(100))
示例5: test_init
# 需要导入模块: from sortedcontainers import SortedKeyList [as 别名]
# 或者: from sortedcontainers.SortedKeyList import clear [as 别名]
def test_init():
slt = SortedKeyList(key=modulo)
assert slt.key == modulo
slt._check()
slt = SortedKeyList(key=modulo)
slt._reset(10000)
assert slt._load == 10000
slt._check()
slt = SortedKeyList(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, SortedKeyList)
slt._check()