How to use the sortedcontainers.SortedListWithKey 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 pgjones / quart / src / quart / routing.py View on Github external
def __init__(self, host_matching: bool = False) -> None:
        self.rules = SortedListWithKey(key=lambda rule: rule.match_key)
        self.endpoints: Dict[str, SortedListWithKey] = defaultdict(
            lambda: SortedListWithKey(key=lambda rule: rule.build_key)
        )  # noqa
        self.converters = self.default_converters.copy()
        self.host_matching = host_matching
github mitmproxy / mitmproxy / mitmproxy / addons / view.py View on Github external
def set_order(self, order: str) -> None:
        """
            Sets the current view order.
        """
        if order not in self.orders:
            raise exceptions.CommandError(
                "Unknown flow order: %s" % order
            )
        order_key = self.orders[order]
        self.order_key = order_key
        newview = sortedcontainers.SortedListWithKey(key=order_key)
        newview.update(self._view)
        self._view = newview
github ssbothwell / greedypacker / greedypacker / guillotine.py View on Github external
elif heuristic == 'best_shortside':
            self._score = scoreBSSF
        elif heuristic == 'best_longside':
            self._score = scoreBLSF
        elif heuristic == 'worst_area':
            self._score = scoreWAF
        elif heuristic == 'worst_shortside':
            self._score = scoreWSSF
        elif heuristic == 'worst_longside':
            self._score = scoreWLSF
        else:
            raise ValueError('No such heuristic!')

        if x == 0 or y == 0:
            #self.freerects = [] # type: List[FreeRectangle]
            self.freerects = SortedListWithKey(iterable=None, key=lambda x: x.area)
        else:
            self.freerects = SortedListWithKey([FreeRectangle(self.x, self.y, 0, 0)], key=lambda x: x.area)
        self.items = [] # type: List[Item]
        self.rotation = rotation
github ICB-DCM / pyABC / pyabc / sampler / eps_mixin.py View on Github external
full_submit_function = self.full_submit_function_pickle
        else:
            # For advanced pickling, e.g. cloudpickle
            def full_submit_function(job_id):
                result_batch = []
                for j in range(self.batch_size):
                    eval_result = simulate_one()
                    eval_accept = eval_result.accepted
                    result_batch.append((eval_result, eval_accept, job_id[j]))
                return result_batch

        num_accepted_total = 0
        num_accepted_sequential = 0
        next_job_id = 0
        running_jobs = []
        unprocessed_results = SortedListWithKey(key=lambda x: x[0])
        all_results = SortedListWithKey(key=lambda x: x[0])
        next_valid_index = -1

        # Main Loop, leave once we have enough material
        while True:
            # Gather finished jobs
            # make sure to track and update both
            # total accepted and sequentially
            # accepted jobs
            for curJob in running_jobs:
                if curJob.done():
                    remote_batch = curJob.result()
                    running_jobs.remove(curJob)
                    for i in range(self.batch_size):
                        remote_evaluated = remote_batch[i]
                        remote_result = remote_evaluated[0]
github hyperledger / indy-plenum / plenum / common / stashing_router.py View on Github external
def __init__(self, limit: int, key: Callable):
        self._limit = limit
        self._key = lambda v: key(v[0])
        self._data = SortedListWithKey(key=self._key)
github wanqizhu / mtg-python-engine / MTG / permanent.py View on Github external
        self.effects = defaultdict(lambda: SortedListWithKey(
                                           [], lambda x : x.timestamp))
github carsonfarmer / streamhist / streamhist / histogram.py View on Github external
def __init__(self, maxbins=64, weighted=False, freeze=None):
        """Create a Histogram with a max of n bins."""
        super(StreamHist, self).__init__()
        # self.bins = []
        self.bins = SortedListWithKey(key=lambda b: b.value)
        self.maxbins = maxbins  # A useful property
        self.total = 0
        self.weighted = weighted
        self._min = None   # A useful property
        self._max = None   # A useful property
        self.freeze = freeze
        self.missing_count = 0
github hyperledger / indy-plenum / plenum / server / consensus / consensus_shared_data.py View on Github external
self.primaries = []
        self.is_master = is_master

        self.legacy_vc_in_progress = False
        self.requests = Requests()
        self.last_ordered_3pc = (0, 0)
        # Indicates name of the primary replica of this protocol instance.
        # None in case the replica does not know who the primary of the
        # instance is
        # TODO: Replace this by read-only property which uses primaries and inst_id
        self.primary_name = None
        # seqNoEnd of the last stabilized checkpoint
        self.stable_checkpoint = 0
        # Checkpoint messages which the current node sent.
        # TODO: Replace sorted list with dict
        self.checkpoints = SortedListWithKey(key=lambda checkpoint: checkpoint.seqNoEnd)
        self.checkpoints.append(self.initial_checkpoint)
        # List of BatchIDs of PrePrepare messages for which quorum of Prepare messages is not reached yet
        self.preprepared = []  # type:  List[BatchID]
        # List of BatchIDs of PrePrepare messages for which quorum of Prepare messages is reached
        self.prepared = []  # type:  List[BatchID]
        self._validators = None
        self.quorums = None
        self.new_view = None  # type: Optional[NewView]
        self.view_change_votes = ViewChangeVotesForView(Quorums(len(validators)))
        # a list of validator node names ordered by rank (historical order of adding)
        self.set_validators(validators)
        self.low_watermark = 0
        self.log_size = getConfig().LOG_SIZE
        self.high_watermark = self.low_watermark + self.log_size
        self.pp_seq_no = 0
        self.node_mode = Mode.starting