private function balance(RedBlackTree $t)
{
if ($this->isRed($t->right())) {
$t = $this->rotateLeft($t);
}
if ($this->isRed($t->left()) && $this->isRed($t->left()->left())) {
$t = $this->rotateRight($t);
}
if ($this->isRed($t->left()) && $this->isRed($t->right())) {
$t = $this->flipColors($t);
}
return $t;
}