Python sortedcontainers.SortedList() Examples
The following are 30
code examples of sortedcontainers.SortedList().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sortedcontainers
, or try the search function
.
Example #1
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 6 votes |
def test_insert(): slt = SortedList(range(10), load=4) slt.insert(-1, 9) slt._check() slt.insert(-100, 0) slt._check() slt.insert(100, 10) slt._check() slt = SortedList(load=4) slt.insert(0, 5) slt._check() slt = SortedList(range(5, 15), load=4) for rpt in range(8): slt.insert(0, 4) slt._check() slt = SortedList(range(10), load=4) slt.insert(8, 8) slt._check()
Example #2
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 6 votes |
def test_islice(): sl = SortedList(load=7) assert [] == list(sl.islice()) values = list(range(53)) sl.update(values) for start in range(53): for stop in range(53): assert list(sl.islice(start, stop)) == values[start:stop] for start in range(53): for stop in range(53): assert list(sl.islice(start, stop, reverse=True)) == values[start:stop][::-1] for start in range(53): assert list(sl.islice(start=start)) == values[start:] assert list(sl.islice(start=start, reverse=True)) == values[start:][::-1] for stop in range(53): assert list(sl.islice(stop=stop)) == values[:stop] assert list(sl.islice(stop=stop, reverse=True)) == values[:stop][::-1]
Example #3
Source File: test_coverage_sortedlistwithkey_modulo.py From pyFileFixity with MIT License | 6 votes |
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()
Example #4
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 6 votes |
def test_index(): slt = SortedList(range(100), load=17) for val in range(100): assert val == slt.index(val) assert slt.index(99, 0, 1000) == 99 slt = SortedList((0 for rpt in range(100)), load=17) 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
Example #5
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 6 votes |
def test_discard(): slt = SortedList() assert slt.discard(0) == None assert len(slt) == 0 slt._check() slt = SortedList([1, 2, 2, 2, 3, 3, 5], load=4) 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, [1, 2, 2, 3, 3, 5]))
Example #6
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 6 votes |
def test_add(): random.seed(0) slt = SortedList() for val in range(1000): slt.add(val) slt._check() slt = SortedList() for val in range(1000, 0, -1): slt.add(val) slt._check() slt = SortedList() for val in range(1000): slt.add(random.random()) slt._check()
Example #7
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 6 votes |
def test_init(): slt = SortedList() slt._check() slt = SortedList(load=10000) assert slt._load == 10000 assert slt._twice == 20000 assert slt._half == 5000 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()
Example #8
Source File: main.py From sonare with MIT License | 6 votes |
def _getOpcodeAddrs(self): # TODO: lazy load? addrs = SortedList() funcs = self.getFunctions() for f in funcs: print('addrs for', f['name']) ofs = f['offset'] sz = f['size'] end = ofs + sz self.seek(ofs) cur = ofs while cur < end: addrs.add(cur) self.cmd('so') cur = self.tell() return addrs
Example #9
Source File: match_collection.py From cassiopeia with MIT License | 5 votes |
def collect_matches(): initial_summoner_name = "GustavEnk" region = "EUW" summoner = Summoner(name=initial_summoner_name, region=region) patch = Patch.from_str("8.9", region=region) unpulled_summoner_ids = SortedList([summoner.id]) pulled_summoner_ids = SortedList() unpulled_match_ids = SortedList() pulled_match_ids = SortedList() while unpulled_summoner_ids: # Get a random summoner from our list of unpulled summoners and pull their match history new_summoner_id = random.choice(unpulled_summoner_ids) new_summoner = Summoner(id=new_summoner_id, region=region) matches = filter_match_history(new_summoner, patch) unpulled_match_ids.update([match.id for match in matches]) unpulled_summoner_ids.remove(new_summoner_id) pulled_summoner_ids.add(new_summoner_id) while unpulled_match_ids: # Get a random match from our list of matches new_match_id = random.choice(unpulled_match_ids) new_match = Match(id=new_match_id, region=region) for participant in new_match.participants: if participant.summoner.id not in pulled_summoner_ids and participant.summoner.id not in unpulled_summoner_ids: unpulled_summoner_ids.add(participant.summoner.id) # The above lines will trigger the match to load its data by iterating over all the participants. # If you have a database in your datapipeline, the match will automatically be stored in it. unpulled_match_ids.remove(new_match_id) pulled_match_ids.add(new_match_id)
Example #10
Source File: test_coverage_sortedlistwithkey_modulo.py From pyFileFixity with MIT License | 5 votes |
def test_new_error(): class SortedListPlus(SortedList): pass SortedListPlus(key=modulo)
Example #11
Source File: ttlcache.py From sydent with Apache License 2.0 | 5 votes |
def __init__(self, cache_name, timer=time.time): # map from key to _CacheEntry self._data = {} # the _CacheEntries, sorted by expiry time self._expiry_list = SortedList() self._timer = timer
Example #12
Source File: test_coverage_sortedlistwithkey_modulo.py From pyFileFixity with MIT License | 5 votes |
def test_new(): slt = SortedList(key=modulo) slt._check() assert isinstance(slt, SortedList) assert isinstance(slt, SortedListWithKey) assert type(slt) == SortedListWithKey slt = SortedListWithKey(key=modulo) slt._check() assert isinstance(slt, SortedList) assert isinstance(slt, SortedListWithKey) assert type(slt) == SortedListWithKey
Example #13
Source File: particles.py From wasabi2d with GNU Lesser General Public License v3.0 | 5 votes |
def __init__( self, layer, clock=default_clock, *, grow: float = 1.0, max_age: float = np.inf, gravity: Tuple[float, float] = (0, 0), drag: float = 1.0, spin_drag: float = 1.0): super().__init__() self.layer = layer self.num: int = 0 # Number of particles we have self.max_age = max_age self.grow = grow self.gravity = np.array(gravity) self.drag = drag self.spin_drag = spin_drag self.spins = np.zeros([0]) self.vels = np.zeros([0, 2]) self._color_stops = SortedList() self.color_tex = layer.ctx.texture((512, 1), 4, dtype='f2') self.color_vals = np.ones((512, 4), dtype='f2') self.color_tex.write(self.color_vals) self._clock = clock clock.each_tick(self._update)
Example #14
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_op_add(): this = SortedList(range(10), load=4) assert (this + this + this) == (this * 3) that = SortedList(range(10), load=4) that += that that += that assert that == (this * 4)
Example #15
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_gt(): this = SortedList(range(10, 15), load=4) assert this > [10, 11, 11, 13, 14] assert this > [10, 11, 12, 13] assert this > [9]
Example #16
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_imul(): this = SortedList(range(10), load=4) this *= 5 this._check() assert this == sorted(list(range(10)) * 5)
Example #17
Source File: abstract.py From wasabi2d with GNU Lesser General Public License v3.0 | 5 votes |
def realloc(self, offset: Union[int, slice], new_size: int) -> slice: """Reallocate the given block. This is optimised so that if there is extra space in the original allocation, it can be done without moving the block. This operation can fail, raising NoCapacity. """ if isinstance(offset, slice): offset = offset.start try: size = self.allocs[offset] except KeyError: raise KeyError(f"Offset {offset} is not allocated.") from None if new_size <= size: return slice(offset, offset + new_size) del self.allocs[offset] # TODO: copying the list before use makes this operation # O(n) (but probably low constant factor) when it should be # O(log n)-ish free_before = list(self._free) self._release(offset, size) try: return self.alloc(new_size) except NoCapacity: # We don't have enough capacity, re-insert before raising self.allocs[offset] = size self._free = SortedList(free_before) raise
Example #18
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_index_valueerror7(): slt = SortedList([0] * 10 + [2] * 10, load=4) slt.index(1, 0, 10)
Example #19
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_index_valueerror6(): slt = SortedList(range(10), load=4) slt.index(3, 5)
Example #20
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_index_valueerror5(): slt = SortedList() slt.index(1)
Example #21
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_index_valueerror4(): slt = SortedList([0] * 10, load=4) slt.index(1)
Example #22
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_index_valueerror3(): slt = SortedList([0] * 10, load=4) slt.index(0, 7, 3)
Example #23
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_index_valueerror1(): slt = SortedList([0] * 10, load=4) slt.index(0, 10)
Example #24
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_pop_indexerror3(): slt = SortedList() slt.pop()
Example #25
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_pop_indexerror2(): slt = SortedList(range(10), load=4) slt.pop(10)
Example #26
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_pop_indexerror1(): slt = SortedList(range(10), load=4) slt.pop(-11)
Example #27
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_insert_valueerror4(): slt = SortedList(range(10), load=4) slt.insert(5, 7)
Example #28
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_insert_valueerror3(): slt = SortedList(range(10), load=4) slt.insert(5, 3)
Example #29
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_insert_valueerror2(): slt = SortedList(range(10), load=4) slt.insert(0, 10)
Example #30
Source File: test_coverage_sortedlist.py From pyFileFixity with MIT License | 5 votes |
def test_insert_valueerror1(): slt = SortedList(range(10), load=4) slt.insert(10, 5)