src/Collection/Tree/RedBlackSearchTree.php
protected function nodeRemoveRight($key, RedBlackNode $node): RedBlackNode
    {
        if (!$this->isRed($node->right()) && !$this->isRed($node->right()->left())) {
            $node = $this->moveRedRight($node);
        }
        if ($this->comparator->compare($key, $node->key()) === 0) {
            $link = $this->nodeMin($node->right());
            $node->setKey($link->key());
            $node->setValue($link->value());
            $node->setRight($this->nodeRemoveMin($node->right()));
        } else {
            $node->setRight($this->nodeRemove($key, $node->right()));
        }

        return $node;
    }
protected function nodeRemoveRight($key, RedBlackNode $node): RedBlackNode
    {
        if (!$this->isRed($node->right()) && !$this->isRed($node->right()->left())) {
            $node = $this->moveRedRight($node);
        }
        if ($this->comparator->compare($key, $node->key()) === 0) {
            $link = $this->nodeMin($node->right());
            $node->setKey($link->key());
            $node->setValue($link->value());
            $node->setRight($this->nodeRemoveMin($node->right()));
        } else {
            $node->setRight($this->nodeRemove($key, $node->right()));
        }

        return $node;
    }
protected function nodeRemoveRight ( $ key , RedBlackNode $ node ) : RedBlackNode { if ( ! $ this -> isRed ( $ node -> right ( ) ) && ! $ this -> isRed ( $ node -> right ( ) -> left ( ) ) ) { $ node = $ this -> moveRedRight ( $ node ) ; } if ( $ this -> comparator -> compare ( $ key , $ node -> key ( ) ) === 0 ) { $ link = $ this -> nodeMin ( $ node -> right ( ) ) ; $ node -> setKey ( $ link -> key ( ) ) ; $ node -> setValue ( $ link -> value ( ) ) ; $ node -> setRight ( $ this -> nodeRemoveMin ( $ node -> right ( ) ) ) ; } else { $ node -> setRight ( $ this -> nodeRemove ( $ key , $ node -> right ( ) ) ) ; } return $ node ; }
Deletes a node to the right by key and subtree

@internal Helper for nodeRemove()

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

@return RedBlackNode
Deletes a node to the right by key and subtree