private function flipColors(RedBlackTree $t) { $color = $t->isRoot() ? RedBlackTree::BLACK : !$t->color(); return new self($t->key(), $t->value(), $this->flipColor($t->left()), $this->flipColor($t->right()), $color, $t->isRoot()); }