diff --git a/lib/ts/RbTree.cc b/lib/ts/RbTree.cc index 926a0630e1b..ba7d2a01035 100644 --- a/lib/ts/RbTree.cc +++ b/lib/ts/RbTree.cc @@ -36,7 +36,7 @@ inline bool operator == ( RBNode::Color c, RBNode* n ) { return n == c; } -inline RBNode* +RBNode* RBNode::getChild(Direction d) const { return d == RIGHT ? _right : d == LEFT ? _left @@ -181,7 +181,7 @@ RBNode::remove() { Because of the initial special case checks, we know that remove_node is @b not the root node. */ - self* remove_node(_left && _right ? _next : this); + self* remove_node(_left && _right ? _right->leftmostDescendant() : this); // This is the color of the node physically removed from the tree. // Normally this is the color of @a remove_node diff --git a/lib/ts/RbTree.h b/lib/ts/RbTree.h index 8bf5f3e8e6e..5c8ac4313b8 100644 --- a/lib/ts/RbTree.h +++ b/lib/ts/RbTree.h @@ -66,6 +66,14 @@ struct RBNode { /// @return The color of the node. Color getColor() const { return _color; } + self* leftmostDescendant() const { + const self* n = this; + while (n->_left) + n = n->_left; + + return const_cast(n); + } + /** Reverse a direction @return @c LEFT if @a d is @c RIGHT, @c RIGHT if @a d is @c LEFT, @c NONE otherwise.