src/Collection/Tree/RedBlackSearchTree.php
protected function nodeRemove($key, RedBlackNode $node): ?RedBlackNode
    {
        $comp = $this->comparator->compare($key, $node->key());
        if ($comp < 0) {
            $node = $this->nodeRemoveLeft($key, $node);
        } else {
            if ($this->isRed($node->left())) {
                $node = $this->rotateRight($node);
            }
            if ($comp === 0 && $node->right() === null) {
                return null;
            }
            $node = $this->nodeRemoveRight($key, $node);
        }

        return $this->balanceOnRemove($node);
    }
protected function nodeRemove($key, RedBlackNode $node): ?RedBlackNode
    {
        $comp = $this->comparator->compare($key, $node->key());
        if ($comp < 0) {
            $node = $this->nodeRemoveLeft($key, $node);
        } else {
            if ($this->isRed($node->left())) {
                $node = $this->rotateRight($node);
            }
            if ($comp === 0 && $node->right() === null) {
                return null;
            }
            $node = $this->nodeRemoveRight($key, $node);
        }

        return $this->balanceOnRemove($node);
    }
protected function nodeRemove ( $ key , RedBlackNode $ node ) : ? RedBlackNode { $ comp = $ this -> comparator -> compare ( $ key , $ node -> key ( ) ) ; if ( $ comp < 0 ) { $ node = $ this -> nodeRemoveLeft ( $ key , $ node ) ; } else { if ( $ this -> isRed ( $ node -> left ( ) ) ) { $ node = $ this -> rotateRight ( $ node ) ; } if ( $ comp === 0 && $ node -> right ( ) === null ) { return null ; } $ node = $ this -> nodeRemoveRight ( $ key , $ node ) ; } return $ this -> balanceOnRemove ( $ node ) ; }
Deletes a node by key and subtree

@param mixed        $key  The key
@param RedBlackNode $node The subtree root

@return RedBlackNode|null
Deletes a node by key and subtree