Skip to content

Commit c0220c1

Browse files
WeberNick5cript
authored andcommitted
Fixed the bug which led to the violation of the max property
1 parent 4568f3b commit c0220c1

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

interval_tree.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -806,18 +806,18 @@ namespace lib_interval_tree
806806

807807
// max fixup
808808
if (x->left_ && x->right_)
809-
x->max_ = std::max(x->left_->max_, x->right_->max_);
809+
x->max_ = std::max(x->max_, std::max(x->left_->max_, x->right_->max_));
810810
else if (x->left_)
811-
x->max_ = x->left_->max_;
811+
x->max_ = std::max(x->max_, x->left_->max_);
812812
else if (x->right_)
813-
x->max_ = x->right_->max_;
813+
x->max_ = std::max(x->max_, x->right_->max_);
814814
else
815815
x->max_ = x->interval_.high_;
816816

817817
if (y->right_)
818-
y->max_ = std::max(y->right_->max_, x->max_);
818+
y->max_ = std::max(y->max_, std::max(y->right_->max_, x->max_));
819819
else
820-
y->max_ = x->max_;
820+
y->max_ = std::max(y->max_, x->max_);
821821
}
822822

823823
void right_rotate(node_type* y)
@@ -841,18 +841,18 @@ namespace lib_interval_tree
841841

842842
// max fixup
843843
if (y->left_ && y->right_)
844-
y->max_ = std::max(y->left_->max_, y->right_->max_);
844+
y->max_ = std::max(y->max_, std::max(y->left_->max_, y->right_->max_));
845845
else if (y->left_)
846-
y->max_ = y->left_->max_;
846+
y->max_ = std::max(y->max_, y->left_->max_);
847847
else if (y->right_)
848-
y->max_ = y->right_->max_;
848+
y->max_ = std::max(y->max_, y->right_->max_);
849849
else
850850
y->max_ = y->interval_.high_;
851851

852852
if (x->left_)
853-
x->max_ = std::max(x->left_->max_, y->max_);
853+
x->max_ = std::max(x->max_, std::max(x->left_->max_, y->max_));
854854
else
855-
y->max_ = y->max_;
855+
x->max_ = std::max(x->max_, y->max_);
856856
}
857857

858858
void recalculate_max(node_type* reacalculation_root)

0 commit comments

Comments
 (0)