From: Mukund Sivaraman Date: Fri, 20 Jul 2012 07:27:52 +0000 (+0530) Subject: [2092] Add support for showing pointers in Graphviz output X-Git-Tag: trac2351_base~158^2^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3eafbeffc07a20aadbc274a690524ecf54fe701e;p=thirdparty%2Fkea.git [2092] Add support for showing pointers in Graphviz output --- diff --git a/src/lib/datasrc/rbtree.h b/src/lib/datasrc/rbtree.h index 2a6c8b4656..4bf8f0b1e7 100644 --- a/src/lib/datasrc/rbtree.h +++ b/src/lib/datasrc/rbtree.h @@ -1055,7 +1055,8 @@ public: /// Graphviz's dot. /// /// \param os A \c std::ostream object to which the tree is printed. - void dumpDot(std::ostream& os) const; + /// \param show_pointers Show node and parent pointers in the node + void dumpDot(std::ostream& os, bool show_pointers = false) const; //@} /// \name Modify functions @@ -1124,7 +1125,7 @@ private: /// \brief Print the information of given RBNode for dot. int dumpDotHelper(std::ostream& os, const RBNode* node, - int* nodecount) const; + int* nodecount, bool show_pointers) const; /// \brief Indentation helper function for dumpTree static void indent(std::ostream& os, unsigned int depth); @@ -1731,33 +1732,37 @@ RBTree::indent(std::ostream& os, unsigned int depth) { template void -RBTree::dumpDot(std::ostream& os) const { +RBTree::dumpDot(std::ostream& os, bool show_pointers) const { int nodecount = 0; os << "digraph g {\n"; os << "node [shape = record,height=.1];\n"; - dumpDotHelper(os, root_, &nodecount); + dumpDotHelper(os, root_, &nodecount, show_pointers); os << "}\n"; } template int RBTree::dumpDotHelper(std::ostream& os, const RBNode* node, - int* nodecount) const + int* nodecount, bool show_pointers) const { if (node == NULLNODE) { return 0; } - int l = dumpDotHelper(os, node->left_, nodecount); - int r = dumpDotHelper(os, node->right_, nodecount); - int d = dumpDotHelper(os, node->down_, nodecount); + int l = dumpDotHelper(os, node->left_, nodecount, show_pointers); + int r = dumpDotHelper(os, node->right_, nodecount, show_pointers); + int d = dumpDotHelper(os, node->down_, nodecount, show_pointers); *nodecount += 1; os << "node" << *nodecount << "[label = \" | " << node->name_.toText() << - "|\"] ["; + "|"; + if (show_pointers) { + os << "| n=" << node << "| p=" << node->parent_; + } + os << "\"] ["; if (node->getColor() == RBNode::RED) { os << "color=red";