本文整理汇总了Python中sortedcontainers.SortedListWithKey方法的典型用法代码示例。如果您正苦于以下问题:Python sortedcontainers.SortedListWithKey方法的具体用法?Python sortedcontainers.SortedListWithKey怎么用?Python sortedcontainers.SortedListWithKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sortedcontainers
的用法示例。
在下文中一共展示了sortedcontainers.SortedListWithKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_init
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [as 别名]
def test_init():
slt = SortedListWithKey(key=negate)
slt._check()
slt = SortedListWithKey(load=10000, key=negate)
assert slt._load == 10000
assert slt._twice == 20000
assert slt._half == 5000
slt._check()
slt = SortedListWithKey(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()
示例2: test_add
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [as 别名]
def test_add():
random.seed(0)
slt = SortedListWithKey(key=negate)
for val in range(1000):
slt.add(val)
slt._check()
slt = SortedListWithKey(key=negate)
for val in range(1000, 0, -1):
slt.add(val)
slt._check()
slt = SortedListWithKey(key=negate)
for val in range(1000):
slt.add(random.random())
slt._check()
示例3: test_update
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [as 别名]
def test_update():
slt = SortedListWithKey(key=negate)
slt.update(range(1000))
assert len(slt) == 1000
slt._check()
slt.update(range(100))
assert len(slt) == 1100
slt._check()
slt.update(range(10000))
assert len(slt) == 11100
slt._check()
values = sorted((val for val in chain(range(100), range(1000), range(10000))), key=negate)
assert all(tup[0] == tup[1] for tup in zip(slt, values))
示例4: test_discard
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [as 别名]
def test_discard():
slt = SortedListWithKey(key=negate)
assert slt.discard(0) == None
assert len(slt) == 0
slt._check()
slt = SortedListWithKey([1, 2, 2, 2, 3, 3, 5], load=4, key=negate)
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, reversed([1, 2, 2, 3, 3, 5])))
示例5: test_getitem
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [as 别名]
def test_getitem():
random.seed(0)
slt = SortedListWithKey(load=17, key=negate)
slt.append(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))
示例6: test_setitem_slice
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [as 别名]
def test_setitem_slice():
slt = SortedListWithKey(range(100), load=17, key=negate)
slt[:10] = iter(range(99, 89, -1))
assert slt == list(range(99, -1, -1))
slt[:10:2] = iter([99, 97, 95, 93, 91])
assert slt == list(range(99, -1, -1))
slt[-50:] = range(49, -51, -1)
assert slt == list(range(99, -51, -1))
slt[-100:] = range(49, -1, -1)
assert slt == list(range(99, -1, -1))
slt[:] = range(99, -1, -1)
assert slt == list(range(99, -1, -1))
slt[90:] = []
assert slt == list(range(99, 9, -1))
slt[:10] = []
assert slt == list(range(89, 9, -1))
示例7: test_islice
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [as 别名]
def test_islice():
return
slt = SortedListWithKey(load=7, key=negate)
assert [] == list(slt.islice())
values = sorted(range(53), key=negate)
slt.update(values)
for start in range(53):
for stop in range(53):
assert list(slt.islice(start, stop)) == values[start:stop]
for start in range(53):
for stop in range(53):
assert list(slt.islice(start, stop, reverse=True)) == values[start:stop][::-1]
for start in range(53):
assert list(slt.islice(start=start)) == values[start:]
assert list(slt.islice(start=start, reverse=True)) == values[start:][::-1]
for stop in range(53):
assert list(slt.islice(stop=stop)) == values[:stop]
assert list(slt.islice(stop=stop, reverse=True)) == values[:stop][::-1]
示例8: test_index
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [as 别名]
def test_index():
slt = SortedListWithKey(range(100), load=17, key=negate)
for pos, val in enumerate(range(99, -1, -1)):
assert val == slt.index(pos)
assert slt.index(99, 0, 1000) == 0
slt = SortedListWithKey((0 for rpt in range(100)), load=17, key=negate)
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
示例9: test_init
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [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()
示例10: test_contains
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [as 别名]
def test_contains():
slt = SortedListWithKey(key=modulo, load=7)
assert 0 not in slt
slt.update(range(100))
for val in range(100):
assert val in slt
assert 100 not in slt
slt._check()
slt = SortedListWithKey(range(100), key=modulo, load=4)
assert all(val not in slt for val in range(100, 200))
示例11: test_discard
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [as 别名]
def test_discard():
slt = SortedListWithKey(key=modulo)
assert slt.discard(0) == None
assert len(slt) == 0
slt._check()
slt = SortedListWithKey([1, 2, 2, 2, 3, 3, 5], load=4, key=modulo)
slt.discard(6)
slt._check()
slt.discard(4)
slt._check()
slt.discard(2)
slt._check()
slt.discard(11)
slt.discard(12)
slt.discard(13)
slt.discard(15)
assert all(tup[0] == tup[1] for tup in zip(slt, [1, 2, 2, 3, 3, 5]))
示例12: __init__
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [as 别名]
def __init__(self):
self._alive = True
self._pulled_count_per_query = {}
self.db_version = 0
self._sorted_prod_tiles_per_cache_tile = {
} # type: Dict[Tuple[uuid.UUID, Footprint], sortedcontainers.SortedListWithKey]
self._pulled_count_per_query = {} # type: Dict[CachedQueryInfos, int]
self._cache_fp_per_query = {} # type: Dict[CachedQueryInfos, Set[Footprint]]
self.address = '/Global/GlobalPrioritiesWatcher'
示例13: __init__
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [as 别名]
def __init__(self, limit: int, key: Callable):
self._limit = limit
self._key = lambda v: key(v[0])
self._data = SortedListWithKey(key=self._key)
示例14: pop_all
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [as 别名]
def pop_all(self) -> Iterable[Tuple]:
data = self._data
self._data = SortedListWithKey(key=self._key)
return data
示例15: __init__
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedListWithKey [as 别名]
def __init__(self, get_current_time=time.perf_counter):
self._get_current_time = get_current_time
self._events = SortedListWithKey(key=lambda v: v.timestamp)