How to use the sortedcontainers.SortedList function in sortedcontainers

To help you get started, we’ve selected a few sortedcontainers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github grantjenks / python-sortedcontainers / tests / test_coverage_sortedlist.py View on Github external
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()
github grantjenks / python-sortedcontainers / tests / test_coverage_sortedlist.py View on Github external
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])
    slt._reset(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]))
github meraki-analytics / cassiopeia / examples / match_collection.py View on Github external
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
github psc-g / Psc2 / research / nips2018 / src / server.py View on Github external
def set_click():
  global num_bars
  global num_steps
  global time_signature
  global playable_notes
  # First clear previous click.
  if len(playable_notes) > 0:
    playable_notes = SortedList([x for x in playable_notes if x.type != 'click'],
                                key=lambda x: x.onset)
  num_steps = int(num_bars * time_signature.numerator * 16 / time_signature.denominator)
  step = 0
  beat = 0
  note_length = int(16 / time_signature.denominator)
  while step < num_steps:
    if step == 0:
      instrument = 'click0'
    else:
      instrument = 'click1' if beat % time_signature.numerator == 0 else 'click2'
    playable_notes.add(PlayableNote(type='click',
                                    note=[],
                                    instrument=instrument,
                                    onset=step))
    step += note_length
    beat += 1
github bx / bootloader_instrumentation_suite / fiddle / labeltool.py View on Github external
def __init__(self, filename, path):
        self.filename = filename
        self.path = path
        self.current_labels = SortedList(key=self._labelsortkey)
        self.updated_labels = SortedList(key=self._labelsortkey)
        self.get_labels_from_file()

        for l in self.current_labels:
            if not ((l.filename == self.filename) and (l.path == self.path)):
                raise Exception("Found label with incorrect filename/path")
github ghackebeil / pybnb / src / pybnb / priority_queue.py View on Github external
def __init__(self,
                 sense,
                 track_bound,
                 _queue_type_=_NoThreadingMaxPriorityFirstQueue):
        assert sense in (minimize, maximize)
        self._sense = sense
        self._queue = _queue_type_()
        self._sorted_by_bound = None
        if track_bound:
            self._sorted_by_bound = SortedList()
github meraki-analytics / cassiopeia / examples / match_collection.py View on Github external
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:
github ZoranPandovski / al-go-rithms / data_structures / Graphs / graphsearch / a-star-search / python / astar.py View on Github external
def a_star(starting_node, target_node, paths):
    """
    A Star generic implementation (see https://en.wikipedia.org/wiki/A*_search_algorithm for more information)
    Finds a way from start to target by using the real cost of travelling and the heuristic values to determine a short path.
    :param starting_node: starting node
    :param target_node: target node
    :param paths: paths
    :return: ordered list of nodes leading to our goal.
    """
    closed = list()  # list that contains all visited nodes
    fringe = SortedList()  # contains all found nodes
    fringe.append(starting_node)  # append the starting node

    while True:
        if (len(fringe) == 0):  # if the fringe is empty
            return None
        node = fringe.pop(0)
        if not any(node.id == it.id for it in closed):  # if the current node is not in our closed list do:
            # print("Current Node= {}, Fringe={}".format(node,fringe)) - uncomment to see how it works!
            if (goal_check(node, target_node)):  # if the current node is our target find the path
                return find_solution(node)
            else:  # else find all neighboring nodes of the current node and add them to the fringe, finally add the curr node to closed.
                connected_nodes = get_connected_nodes(node, paths)
                for connected_node in connected_nodes:
                    fringe.add(connected_node)
                closed.append(node)
        else:
github matrix-org / synapse / synapse / util / caches / ttlcache.py View on Github external
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

        self._metrics = register_cache("ttl", cache_name, self)
github missionpinball / mpf / mpf / core / platform_batch_light_system.py View on Github external
def mark_dirty(self, light: "PlatformBatchLight"):
        """Mark as dirty."""
        self.dirty_lights.add(light)
        self.dirty_schedule = SortedList([x for x in self.dirty_schedule if x[1] != light],
                                         key=lambda x: x[0] + self.sort_function(x[1]))