How to use the sortedcontainers.sortedlist.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 / sortedcontainers / sortedlistwithkey.py View on Github external
more information.

        An optional *key* argument defines a callable that, like the `key`
        argument to Python's `sorted` function, extracts a comparison key from
        each element. The default is the identity function.

        An optional *key* specifies a key function to apply to inserted
        values. Values will be ordered by their key. A SortedListWithKey
        must maintain the sort order at all times.

        SortedListWithKey implements the MutableSequence Abstract Base Class
        type.
        """
        self._key = key
        self._load = load
        self._list = SortedList(load=load)

        if iterable is not None:
            self.update(iterable)
github Samourai-Wallet / boltzmann / boltzmann / linker / txos_linker.py View on Github external
def _match_agg_by_val(self):
        '''
        Matches input/output aggregates by values and returns a bunch of data structs
        '''
        self._all_match_in_agg = SortedList()
        self._match_in_agg_to_val = defaultdict(int)
        self._val_to_match_out_agg = defaultdict(set)

        # Gets unique values of input / output aggregates
        all_unique_in_agg_val, _ = np.unique(self._all_in_agg_val, return_inverse=True)
        all_unique_out_agg_val, _ = np.unique(self._all_out_agg_val, return_inverse=True)

        # Computes total fees paid/receiver by taker/maker
        if self._has_intrafees:
            fees_taker = self._fees + self._fees_taker
            fees_maker = - self._fees_maker         # doesn't take into account tx fees paid by makers

        # Finds input and output aggregates with matching values
        for in_agg_val in np.nditer(all_unique_in_agg_val):
            val = int(in_agg_val)
github grantjenks / python-sortedcontainers / sortedcontainers / sortedset.py View on Github external
SortedSet([5, 4, 3, 2, 1], key=)

        :param iterable: initial values (optional)
        :param key: function used to extract comparison key (optional)

        """
        self._key = key

        # SortedSet._fromset calls SortedSet.__init__ after initializing the
        # _set attribute. So only create a new set if the _set attribute is not
        # already present.

        if not hasattr(self, '_set'):
            self._set = set()

        self._list = SortedList(self._set, key=key)

        # Expose some set methods publicly.

        _set = self._set
        self.isdisjoint = _set.isdisjoint
        self.issubset = _set.issubset
        self.issuperset = _set.issuperset

        # Expose some sorted list methods publicly.

        _list = self._list
        self.bisect_left = _list.bisect_left
        self.bisect = _list.bisect
        self.bisect_right = _list.bisect_right
        self.index = _list.index
        self.irange = _list.irange
github scikit-multiflow / scikit-multiflow / src / skmultiflow / trees / attribute_observer / numeric_attribute_class_observer_gaussian.py View on Github external
def get_split_point_suggestions(self):
        suggested_split_values = SortedList()
        min_value = np.inf
        max_value = -np.inf
        for k, estimator in self._att_val_dist_per_class.items():
            if self._min_value_observed_per_class[k] < min_value:
                min_value = self._min_value_observed_per_class[k]
            if self._max_value_observed_per_class[k] > max_value:
                max_value = self._max_value_observed_per_class[k]
        if min_value < np.inf:
            bin_size = max_value - min_value
            bin_size /= (float(self.num_bin_options) + 1.0)
            for i in range(self.num_bin_options):
                split_value = min_value + (bin_size * (i + 1))
                if split_value > min_value and split_value < max_value:
                    suggested_split_values.add(split_value)
        return suggested_split_values
github scikit-multiflow / scikit-multiflow / src / skmultiflow / trees / numeric_attribute_class_observer_gaussian.py View on Github external
def get_split_point_suggestions(self):
        suggested_split_values = SortedList()
        min_value = np.inf
        max_value = -np.inf
        for k, estimator in self._att_val_dist_per_class.items():
            if self._min_value_observed_per_class[k] < min_value:
                min_value = self._min_value_observed_per_class[k]
            if self._max_value_observed_per_class[k] > max_value:
                max_value = self._max_value_observed_per_class[k]
        if min_value < np.inf:
            bin_size = max_value - min_value
            bin_size /= (float(self.num_bin_options) + 1.0)
            for i in range(self.num_bin_options):
                split_value = min_value + (bin_size * (i + 1))
                if split_value > min_value and split_value < max_value:
                    suggested_split_values.add(split_value)
        return suggested_split_values
github grantjenks / python-sortedcontainers / sortedcontainers / sortedlist.py View on Github external
print('offset', self._offset)
            print('len_index', len(self._index))
            print('index', self._index)
            print('len_maxes', len(self._maxes))
            print('maxes', self._maxes)
            print('len_lists', len(self._lists))
            print('lists', self._lists)
            raise


def identity(value):
    "Identity function."
    return value


class SortedKeyList(SortedList):
    """Sorted-key list is a subtype of sorted list.

    The sorted-key list maintains values in comparison order based on the
    result of a key function applied to every value.

    All the same methods that are available in :class:`SortedList` are also
    available in :class:`SortedKeyList`.

    Additional methods provided:

    * :attr:`SortedKeyList.key`
    * :func:`SortedKeyList.bisect_key_left`
    * :func:`SortedKeyList.bisect_key_right`
    * :func:`SortedKeyList.irange_key`

    Some examples below use:
github grantjenks / python-sortedcontainers / sortedcontainers / sorteddict.py View on Github external
>>> d = {'alpha': 1, 'beta': 2}
        >>> SortedDict([('alpha', 1), ('beta', 2)]) == d
        True
        >>> SortedDict({'alpha': 1, 'beta': 2}) == d
        True
        >>> SortedDict(alpha=1, beta=2) == d
        True

        """
        if args and (args[0] is None or callable(args[0])):
            _key = self._key = args[0]
            args = args[1:]
        else:
            _key = self._key = None

        self._list = SortedList(key=_key)

        # Calls to super() are expensive so cache references to dict methods on
        # sorted dict instances.

        _dict = super(SortedDict, self)
        self._dict_clear = _dict.clear
        self._dict_delitem = _dict.__delitem__
        self._dict_iter = _dict.__iter__
        self._dict_pop = _dict.pop
        self._dict_setitem = _dict.__setitem__
        self._dict_update = _dict.update

        # Reaching through ``self._list`` repeatedly adds unnecessary overhead
        # so cache references to sorted list methods.

        _list = self._list