src/Collection/Tree/RedBlackSearchTree.php
protected function balanceOnInsert(RedBlackNode $node): RedBlackNode
    {
        if ($this->isRed($node->right()) && !$this->isRed($node->left())) {
            $node = $this->rotateLeft($node);
        }
        if ($this->isRed($node->left()) && $this->isRed($node->left()->left())) {
            $node = $this->rotateRight($node);
        }
        if ($this->isRed($node->left()) && $this->isRed($node->right())) {
            $this->flipColors($node);
        }
        $node->setSize(1 + $this->nodeSize($node->left()) + $this->nodeSize($node->right()));

        return $node;
    }
protected function balanceOnInsert(RedBlackNode $node): RedBlackNode
    {
        if ($this->isRed($node->right()) && !$this->isRed($node->left())) {
            $node = $this->rotateLeft($node);
        }
        if ($this->isRed($node->left()) && $this->isRed($node->left()->left())) {
            $node = $this->rotateRight($node);
        }
        if ($this->isRed($node->left()) && $this->isRed($node->right())) {
            $this->flipColors($node);
        }
        $node->setSize(1 + $this->nodeSize($node->left()) + $this->nodeSize($node->right()));

        return $node;
    }
protected function balanceOnInsert ( RedBlackNode $ node ) : RedBlackNode { if ( $ this -> isRed ( $ node -> right ( ) ) && ! $ this -> isRed ( $ node -> left ( ) ) ) { $ node = $ this -> rotateLeft ( $ node ) ; } if ( $ this -> isRed ( $ node -> left ( ) ) && $ this -> isRed ( $ node -> left ( ) -> left ( ) ) ) { $ node = $ this -> rotateRight ( $ node ) ; } if ( $ this -> isRed ( $ node -> left ( ) ) && $ this -> isRed ( $ node -> right ( ) ) ) { $ this -> flipColors ( $ node ) ; } $ node -> setSize ( 1 + $ this -> nodeSize ( $ node -> left ( ) ) + $ this -> nodeSize ( $ node -> right ( ) ) ) ; return $ node ; }
Restores red-black tree invariant on insert

@codeCoverageIgnore

@param RedBlackNode $node The subtree root

@return RedBlackNode
Restores red - black tree invariant on insert