def __init__(self, items=None, key_type=None, alg=RED_BLACK_TREE, key=None, compare=None, updator=None): """ :param items: Sequence or mapping 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 dict with initial items >>> t = SortedDict([(1, 'a'), (2, 'b')]) >>> list(t) [1, 2] >>> assert 1 in t >>> assert 4 not in t Key-Type Example: >>> # Almost no change! >>> t = SortedDict([(1, 'a'), (2, 'b')], key_type = int) >>> # Identical from here. """ try: items = items.items() except AttributeError: pass self._init_info = _CommonInitInfo(key_type, alg, key, compare, updator) metadata = _updator_metadata(0, self._init_info) _adopt_updator_methods(self, updator) DictTree.__init__(self, alg, items, key_type, 0, metadata, key, compare, 0)
def root(self): """ :returns: The root :py:class:`Node` of the DictTree. """ c_node = DictTree.root(self) return Node(c_node) if c_node is not None else None
def __init__( self, items = None, key_type = None, alg = RED_BLACK_TREE, key = None, compare = None, updator = None): """ :param items: Sequence or mapping 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 dict with initial items >>> t = SortedDict([(1, 'a'), (2, 'b')]) >>> list(t) [1, 2] >>> assert 1 in t >>> assert 4 not in t Key-Type Example: >>> # Almost no change! >>> t = SortedDict([(1, 'a'), (2, 'b')], key_type = int) >>> # Identical from here. """ try: items = items.items() except AttributeError: pass self._init_info = _CommonInitInfo(key_type, alg, key, compare, updator) metadata = _updator_metadata(0, self._init_info) _adopt_updator_methods(self, updator) DictTree.__init__( self, alg, items, key_type, 0, metadata, key, compare, 0)