本文整理汇总了Python中sortedcontainers.SortedSet方法的典型用法代码示例。如果您正苦于以下问题:Python sortedcontainers.SortedSet方法的具体用法?Python sortedcontainers.SortedSet怎么用?Python sortedcontainers.SortedSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sortedcontainers
的用法示例。
在下文中一共展示了sortedcontainers.SortedSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_islice
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def test_islice():
ss = SortedSet(load=7)
assert [] == list(ss.islice())
values = list(range(53))
ss.update(values)
for start in range(53):
for stop in range(53):
assert list(ss.islice(start, stop)) == values[start:stop]
for start in range(53):
for stop in range(53):
assert list(ss.islice(start, stop, reverse=True)) == values[start:stop][::-1]
for start in range(53):
assert list(ss.islice(start=start)) == values[start:]
assert list(ss.islice(start=start, reverse=True)) == values[start:][::-1]
for stop in range(53):
assert list(ss.islice(stop=stop)) == values[:stop]
assert list(ss.islice(stop=stop, reverse=True)) == values[:stop][::-1]
示例2: test_init
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def test_init():
sst = SortedSet()
sst._check()
sst = SortedSet(load=10000)
assert sst._list._load == 10000
assert sst._list._twice == 20000
assert sst._list._half == 5000
sst._check()
sst = SortedSet(range(10000))
assert all(tup[0] == tup[1] for tup in zip(sst, range(10000)))
sst.clear()
assert len(sst) == 0
assert list(iter(sst)) == []
sst._check()
示例3: _set_data
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def _set_data(self, data):
(
self.priority_split,
self.data,
self.pending_points,
self._stack,
x_mapping,
self.ivals,
self.first_ival,
) = data
# Add the pending_points to the _stack such that they are evaluated again
for x in self.pending_points:
if x not in self._stack:
self._stack.append(x)
# x_mapping is a data structure that can't easily be saved
# so we recreate it here
self.x_mapping = defaultdict(lambda: SortedSet([], key=attrgetter("rdepth")))
for k, _set in x_mapping.items():
self.x_mapping[k].update(_set)
示例4: __init__
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def __init__(self) -> None:
# Always start without knowing anything about a trie. The only unexplored
# prefix is the root prefix: (), which means the whole trie is unexplored.
self._unexplored_prefixes = SortedSet({()})
示例5: _new_trie_fog
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def _new_trie_fog(cls, unexplored_prefixes: SortedSet) -> 'HexaryTrieFog':
"""
Convert a set of unexplored prefixes to a proper HexaryTrieFog object.
"""
copy = cls()
copy._unexplored_prefixes = unexplored_prefixes
return copy
示例6: deserialize
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def deserialize(cls, encoded: bytes) -> 'HexaryTrieFog':
serial_prefix = b'HexaryTrieFog:'
if not encoded.startswith(serial_prefix):
raise ValueError(f"Cannot deserialize this into HexaryTrieFog object: {encoded!r}")
else:
encoded_list = encoded[len(serial_prefix):]
prefix_list = ast.literal_eval(encoded_list.decode())
deserialized_prefixes = SortedSet(
# decode nibbles from compressed bytes value, and validate each value in range(16)
Nibbles(decode_nibbles(prefix))
for prefix in prefix_list
)
return cls._new_trie_fog(deserialized_prefixes)
示例7: test_init
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def test_init():
temp = SortedSet(range(100), load=7)
temp._check()
assert all(val == temp[val] for val in temp)
示例8: test_contains
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def test_contains():
temp = SortedSet(range(100), load=7)
assert all(val in temp for val in range(100))
assert all(val not in temp for val in range(100, 200))
示例9: test_getitem
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def test_getitem():
temp = SortedSet(range(100), load=7)
assert all(val == temp[val] for val in temp)
示例10: test_getitem_slice
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def test_getitem_slice():
vals = list(range(100))
temp = SortedSet(vals, load=7)
assert temp[20:30] == vals[20:30]
示例11: test_getitem_key
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def test_getitem_key():
temp = SortedSet(range(100), load=7, key=negate)
assert all(temp[val] == (99 - val) for val in range(100))
示例12: test_delitem_slice
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def test_delitem_slice():
vals = list(range(100))
temp = SortedSet(vals, load=7)
del vals[20:40:2]
del temp[20:40:2]
assert temp == set(vals)
示例13: test_delitem_key
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def test_delitem_key():
temp = SortedSet(range(100), load=7, key=modulo)
values = sorted(range(100), key=modulo)
for val in range(10):
del temp[val]
del values[val]
assert list(temp) == list(values)
示例14: test_eq
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def test_eq():
alpha = SortedSet(range(100), load=7)
beta = SortedSet(range(100), load=17)
assert alpha == beta
assert alpha == beta._set
beta.add(101)
assert not (alpha == beta)
示例15: test_ne
# 需要导入模块: import sortedcontainers [as 别名]
# 或者: from sortedcontainers import SortedSet [as 别名]
def test_ne():
alpha = SortedSet(range(100), load=7)
beta = SortedSet(range(99), load=17)
assert alpha != beta
beta.add(100)
assert alpha != beta
assert alpha != beta._set
assert alpha != list(range(101))