diff --git a/sml/red_black_tree.hpp b/sml/red_black_tree.hpp index 96f3a4e..49e3e0a 100644 --- a/sml/red_black_tree.hpp +++ b/sml/red_black_tree.hpp @@ -550,7 +550,13 @@ class red_black_tree { lesser_(r.lesser_), allocator_(r.allocator_) { - this->copy_node(r); + this->root_ = + node::clone_node(this->allocator_, r.root_, this->root_, this->lesser_); + + if (this->root_) { + this->left_most_ = this->root_->left_most_descendant(); + this->right_most_ = this->root_->right_most_descendant(); + } } iterator begin() { return iterator(*this, this->left_most_); } @@ -776,11 +782,8 @@ class red_black_tree { } std::pair _insert(const value_type& value, iterator pos) { - if (this->empty()) { - return this->insert(value); - } - const node_type node = pos.node_; + if (!node) { return this->insert_to_right_most_if_can(value); } @@ -840,7 +843,7 @@ class red_black_tree { node::create_root(this->allocator_, value, this->root_); } else { - iter_node = *inserted = + iter_node = node::create_node(this->allocator_, parent, value, this->root_); if (this->lesser_(value.first, this->left_most_->key())) { @@ -850,6 +853,7 @@ class red_black_tree { this->right_most_ = iter_node; } + *inserted = iter_node; this->insert_fixup(iter_node); } @@ -1074,16 +1078,6 @@ class red_black_tree { return this->root_; } - void copy_node(const red_black_tree& r) { - this->root_ = - node::clone_node(this->allocator_, r.root_, this->root_, this->lesser_); - - if (this->root_) { - this->left_most_ = this->root_->left_most_descendant(); - this->right_most_ = this->root_->right_most_descendant(); - } - } - node_type root_; node_type left_most_; node_type right_most_;