Skip to content

Commit

Permalink
Changes to RBNode to make it more generally useful
Browse files Browse the repository at this point in the history
  • Loading branch information
bgaff committed Oct 8, 2014
1 parent f1bedb4 commit 0999715
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ts/RbTree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/ts/RbTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<self*>(n);
}

/** Reverse a direction
@return @c LEFT if @a d is @c RIGHT, @c RIGHT if @a d is @c LEFT,
@c NONE otherwise.
Expand Down

0 comments on commit 0999715

Please sign in to comment.