}
}
+ bool isSubTreeRoot() const {
+ return (parent_ == NULL_NODE());
+ }
+
/// \brief return the next node which is bigger than current node
/// in the same subtree
///
down_node->down_ = node.down_;
node.down_ = down_node.get();
+
// Restore the color of the node (may have gotten changed by the flags swap)
node.setColor(down_node->getColor());
+
// root node of sub tree, the initial color is BLACK
down_node->setColor(RBNode<T>::BLACK);
++node_count_;
indent(os, depth);
os << node->name_.toText() << " ("
<< ((node->getColor() == RBNode<T>::BLACK) ? "black" : "red") << ")";
- os << ((node->isEmpty()) ? "[invisible] \n" : "\n");
+ if (node->isEmpty()) {
+ os << " [invisible]";
+ }
+ if (node->isSubTreeRoot()) {
+ os << " [subtreeroot]";
+ }
+ os << "\n";
if (node->down_ != NULLNODE) {
indent(os, depth + 1);
std::ostringstream str2;
rbtree.dumpTree(str);
str2 << "tree has 14 node(s)\n" <<
- "b. (black)\n" <<
+ "b. (black) [subtreeroot]\n" <<
" a. (black)\n" <<
" NULL\n" <<
" NULL\n" <<
- " d.e.f. (black)[invisible] \n" <<
+ " d.e.f. (black) [invisible]\n" <<
" begin down from d.e.f.\n" <<
- " w.y. (black)[invisible] \n" <<
+ " w.y. (black) [invisible] [subtreeroot]\n" <<
" begin down from w.y.\n" <<
- " p. (black)\n" <<
+ " p. (black) [subtreeroot]\n" <<
" o. (red)\n" <<
" NULL\n" <<
" NULL\n" <<
" NULL\n" <<
" z. (red)\n" <<
" begin down from z.\n" <<
- " j. (black)\n" <<
+ " j. (black) [subtreeroot]\n" <<
" NULL\n" <<
" NULL\n" <<
" end down from z.\n" <<
" NULL\n" <<
" g.h. (red)\n" <<
" begin down from g.h.\n" <<
- " i. (black)\n" <<
+ " i. (black) [subtreeroot]\n" <<
" NULL\n" <<
" k. (red)\n" <<
" NULL\n" <<
" end down from g.h.\n" <<
" NULL\n" <<
" NULL\n";
- rbtree.dumpTree(std::cout);
EXPECT_EQ(str.str(), str2.str());
}