def remove(self, key):
        """T.remove(key) <==> del T[key], remove item <key> from tree."""
        if self._root is None:
            raise KeyError(str(key))
        head = Node()  # False tree root
        node = head
        node.right = self._root
        parent = None
        grand_parent = None
        found = None  # Found item
        direction = 1

        # Search and push a red down
        while node[direction] is not None:
            last = direction

            # Update helpers
            grand_parent = parent
            parent = node
            node = node[direction]

            direction = 1 if (self._cmp(self._cmp_data, node.key, key) < 0) else 0

            # Save found node
            if self._cmp(self._cmp_data, key, node.key) == 0:
                found = node

            # Push the red node down
            if not RBTree.is_red(node) and not RBTree.is_red(node[direction]):
                if RBTree.is_red(node[1 - direction]):
                    parent[last] = RBTree.jsw_single(node, direction)
                    parent = parent[last]
                elif not RBTree.is_red(node[1 - direction]):
                    sibling = parent[1 - last]
                    if sibling is not None:
                        if (not RBTree.is_red(sibling[1 - last])) and (not RBTree.is_red(sibling[last])):
                            # Color flip
                            parent.red = False
                            sibling.red = True
                            node.red = True
                        else:
                            direction2 = 1 if grand_parent.right is parent else 0
                            if RBTree.is_red(sibling[last]):
                                grand_parent[direction2] = RBTree.jsw_double(parent, last)
                            elif RBTree.is_red(sibling[1-last]):
                                grand_parent[direction2] = RBTree.jsw_single(parent, last)
                            # Ensure correct coloring
                            grand_parent[direction2].red = True
                            node.red = True
                            grand_parent[direction2].left.red = False
                            grand_parent[direction2].right.red = False

        # Replace and remove if found
        if found is not None:
            found.key = node.key
            found.value = node.value
            parent[int(parent.right is node)] = node[int(node.left is None)]
            node.free()
            self._count -= 1

        # Update root and make it black
        self._root = head.right
        if self._root is not None:
            self._root.red = False
        if not found:
            raise KeyError(str(key))
def remove(self, key):
        """T.remove(key) <==> del T[key], remove item <key> from tree."""
        if self._root is None:
            raise KeyError(str(key))
        head = Node()  # False tree root
        node = head
        node.right = self._root
        parent = None
        grand_parent = None
        found = None  # Found item
        direction = 1

        # Search and push a red down
        while node[direction] is not None:
            last = direction

            # Update helpers
            grand_parent = parent
            parent = node
            node = node[direction]

            direction = 1 if (self._cmp(self._cmp_data, node.key, key) < 0) else 0

            # Save found node
            if self._cmp(self._cmp_data, key, node.key) == 0:
                found = node

            # Push the red node down
            if not RBTree.is_red(node) and not RBTree.is_red(node[direction]):
                if RBTree.is_red(node[1 - direction]):
                    parent[last] = RBTree.jsw_single(node, direction)
                    parent = parent[last]
                elif not RBTree.is_red(node[1 - direction]):
                    sibling = parent[1 - last]
                    if sibling is not None:
                        if (not RBTree.is_red(sibling[1 - last])) and (not RBTree.is_red(sibling[last])):
                            # Color flip
                            parent.red = False
                            sibling.red = True
                            node.red = True
                        else:
                            direction2 = 1 if grand_parent.right is parent else 0
                            if RBTree.is_red(sibling[last]):
                                grand_parent[direction2] = RBTree.jsw_double(parent, last)
                            elif RBTree.is_red(sibling[1-last]):
                                grand_parent[direction2] = RBTree.jsw_single(parent, last)
                            # Ensure correct coloring
                            grand_parent[direction2].red = True
                            node.red = True
                            grand_parent[direction2].left.red = False
                            grand_parent[direction2].right.red = False

        # Replace and remove if found
        if found is not None:
            found.key = node.key
            found.value = node.value
            parent[int(parent.right is node)] = node[int(node.left is None)]
            node.free()
            self._count -= 1

        # Update root and make it black
        self._root = head.right
        if self._root is not None:
            self._root.red = False
        if not found:
            raise KeyError(str(key))
def remove ( self , key ) : if self . _root is None : raise KeyError ( str ( key ) ) head = Node ( ) # False tree root node = head node . right = self . _root parent = None grand_parent = None found = None # Found item direction = 1 # Search and push a red down while node [ direction ] is not None : last = direction # Update helpers grand_parent = parent parent = node node = node [ direction ] direction = 1 if ( self . _cmp ( self . _cmp_data , node . key , key ) < 0 ) else 0 # Save found node if self . _cmp ( self . _cmp_data , key , node . key ) == 0 : found = node # Push the red node down if not RBTree . is_red ( node ) and not RBTree . is_red ( node [ direction ] ) : if RBTree . is_red ( node [ 1 - direction ] ) : parent [ last ] = RBTree . jsw_single ( node , direction ) parent = parent [ last ] elif not RBTree . is_red ( node [ 1 - direction ] ) : sibling = parent [ 1 - last ] if sibling is not None : if ( not RBTree . is_red ( sibling [ 1 - last ] ) ) and ( not RBTree . is_red ( sibling [ last ] ) ) : # Color flip parent . red = False sibling . red = True node . red = True else : direction2 = 1 if grand_parent . right is parent else 0 if RBTree . is_red ( sibling [ last ] ) : grand_parent [ direction2 ] = RBTree . jsw_double ( parent , last ) elif RBTree . is_red ( sibling [ 1 - last ] ) : grand_parent [ direction2 ] = RBTree . jsw_single ( parent , last ) # Ensure correct coloring grand_parent [ direction2 ] . red = True node . red = True grand_parent [ direction2 ] . left . red = False grand_parent [ direction2 ] . right . red = False # Replace and remove if found if found is not None : found . key = node . key found . value = node . value parent [ int ( parent . right is node ) ] = node [ int ( node . left is None ) ] node . free ( ) self . _count -= 1 # Update root and make it black self . _root = head . right if self . _root is not None : self . _root . red = False if not found : raise KeyError ( str ( key ) )
T.remove(key) <==> del T[key], remove item <key> from tree.
T . remove ( key ) < == > del T [ key ] remove item <key > from tree .