public function add($key, $value)
{
$c = $this->compare($this->key, $key);
if ($c === 0) {
return new self($key, $value, $this->left, $this->right);
} else {
if ($c > 0) {
return $this->makeBalanced(new self($this->key, $this->value, $this->left, $this->right->add($key, $value)));
} else {
return $this->makeBalanced(new self($this->key, $this->value, $this->left->add($key, $value), $this->right));
}
}
}