def update(self, *others): """ :param iterable others: Other elemens. :type others: iterable or multiple iterables Update this set to the union of its own items and those in others. Example: >>> t = SortedSet([1, 3, 2]) >>> t.update([20]) >>> t SortedSet([1, 2, 3, 20]) >>> >>> t = SortedSet([1, 3, 2]) >>> t.update([20], [30, 3]) >>> t SortedSet([1, 2, 3, 20, 30]) """ t = self.union(*others) SetTree.__init__(self, self._init_info.alg, t, self._init_info.key_type, 1, _updator_metadata(1, self._init_info), self._init_info.key, self._init_info.compare, 1)
def symmetric_difference_update(self, *others): """ :param iterable others: Other elemens. :type others: iterable or multiple iterables Update this set to the symmetric difference of its own items and those in others. Example: >>> t = SortedSet([1, 3, 2]) >>> t.symmetric_difference_update([2, 5]) >>> t SortedSet([1, 3, 5]) """ t = self.symmetric_difference(*others) SetTree.__init__( self, self._init_info.alg, t, self._init_info.key_type, 1, _updator_metadata(1, self._init_info), self._init_info.key, self._init_info.compare, 1)
def intersection_update(self, *others): """ :param iterable others: Other elemens. :type others: iterable or multiple iterables Update this set to the intersection of its own items and those in others. Example: >>> t = SortedSet([1, 3, 2]) >>> t.intersection_update([20]) >>> t SortedSet([]) >>> t = SortedSet([1, 3, 2]) >>> t.intersection_update([1, 3], [3]) >>> t SortedSet([3]) """ t = self.intersection(*others) SetTree.__init__( self, self._init_info.alg, t, self._init_info.key_type, 1, _updator_metadata(1, self._init_info), self._init_info.key, self._init_info.compare, 1)
def __init__(self, items=None, key_type=None, alg=RED_BLACK_TREE, key=None, compare=None, updator=None): """ :param items: Sequence of initial items :type items: iterable or ``None`` :param key_type: Optional keys' type, or ``None`` to show it is unknown or undefined (specifying the key type can greatly improve performance). :type key_type: ``int``, ``float``, ``str``, ``bytes``, ``unicode`` (for pre Py3) , ``(int, int)``, ``(float, float)``, or ``None`` :param string alg: Underlying algorithm string. Should be one of RED_BLACK_TREE, SPLAY_TREE, or SORTED_LIST :param function key: Key function: transforms the set's keys into something that can be compared. :param compare: Comparison function. Should take two parameters, say x and y, and return the a negative number, 0, or positive number, for the cases x < y, x == y, and x > y, respectively. :type compare: function or ``None`` :param updator: Node updator :type updator: function or ``None`` .. Note:: The compare fuction is deprecated in favor of the key function. Examples: >>> # Red-black tree sorted set >>> t = SortedSet() >>> >>> # (Red-black tree) sorted set with initial items >>> t = SortedSet([1, 3, 2]) >>> list(t) [1, 2, 3] >>> >>> # Splay-tree sorted set >>> t = SortedSet(alg = SPLAY_TREE) >>> >>> # Splay-tree larger-first sorted set with initial items. >>> t = SortedSet([1, 3, 2], alg = SPLAY_TREE, compare = lambda x, y: y - x) >>> list(t) [3, 2, 1] Key-Type Example: >>> # Almost no change! >>> t = SortedSet([1, 3, 2], key_type = int) >>> # Identical from here. """ self._init_info = _CommonInitInfo(key_type, alg, key, compare, updator) metadata = _updator_metadata(True, self._init_info) _adopt_updator_methods(self, updator) SetTree.__init__(self, alg, items, key_type, 1, metadata, key, compare, 0)
def symmetric_difference_update(self, *others): """ :param iterable others: Other elemens. :type others: iterable or multiple iterables Update this set to the symmetric difference of its own items and those in others. Example: >>> t = SortedSet([1, 3, 2]) >>> t.symmetric_difference_update([2, 5]) >>> t SortedSet([1, 3, 5]) """ t = self.symmetric_difference(*others) SetTree.__init__(self, self._init_info.alg, t, self._init_info.key_type, 1, _updator_metadata(1, self._init_info), self._init_info.key, self._init_info.compare, 1)
def __init__( self, items = None, key_type = None, alg = RED_BLACK_TREE, key = None, compare = None, updator = None): """ :param items: Sequence of initial items :type items: iterable or ``None`` :param key_type: Optional keys' type, or ``None`` to show it is unknown or undefined (specifying the key type can greatly improve performance). :type key_type: ``int``, ``float``, ``str``, ``bytes``, ``unicode`` (for pre Py3) , ``(int, int)``, ``(float, float)``, or ``None`` :param string alg: Underlying algorithm string. Should be one of RED_BLACK_TREE, SPLAY_TREE, or SORTED_LIST :param function key: Key function: transforms the set's keys into something that can be compared. :param compare: Comparison function. Should take two parameters, say x and y, and return the a negative number, 0, or positive number, for the cases x < y, x == y, and x > y, respectively. :type compare: function or ``None`` :param updator: Node updator :type updator: function or ``None`` .. Note:: The compare fuction is deprecated in favor of the key function. Examples: >>> # Red-black tree sorted set >>> t = SortedSet() >>> >>> # (Red-black tree) sorted set with initial items >>> t = SortedSet([1, 3, 2]) >>> list(t) [1, 2, 3] >>> >>> # Splay-tree sorted set >>> t = SortedSet(alg = SPLAY_TREE) >>> >>> # Splay-tree larger-first sorted set with initial items. >>> t = SortedSet([1, 3, 2], alg = SPLAY_TREE, compare = lambda x, y: y - x) >>> list(t) [3, 2, 1] Key-Type Example: >>> # Almost no change! >>> t = SortedSet([1, 3, 2], key_type = int) >>> # Identical from here. """ self._init_info = _CommonInitInfo(key_type, alg, key, compare, updator) metadata = _updator_metadata(True, self._init_info) _adopt_updator_methods(self, updator) SetTree.__init__( self, alg, items, key_type, 1, metadata, key, compare, 0)