Skip to content

Commit

Permalink
strong exception safety
Browse files Browse the repository at this point in the history
  • Loading branch information
Taro Sekiyama committed Jun 12, 2011
1 parent c2847bb commit 8170ce1
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions sml/red_black_tree.hpp
Expand Up @@ -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_); }
Expand Down Expand Up @@ -776,11 +782,8 @@ class red_black_tree {
}

std::pair<iterator, bool> _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);
}
Expand Down Expand Up @@ -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())) {
Expand All @@ -850,6 +853,7 @@ class red_black_tree {
this->right_most_ = iter_node;
}

*inserted = iter_node;
this->insert_fixup(iter_node);
}

Expand Down Expand Up @@ -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_;
Expand Down

0 comments on commit 8170ce1

Please sign in to comment.