MINOR: tools: emphasize the node being worked on in the tree dump
Now we can show in dotted red the node being removed or surrounded in red
a node having been inserted, and add a description on the graph related to
the operation in progress for example.
diff --git a/include/common/standard.h b/include/common/standard.h
index 3762338..b2d67ed 100644
--- a/include/common/standard.h
+++ b/include/common/standard.h
@@ -37,6 +37,7 @@
#include <common/config.h>
#include <common/namespace.h>
#include <eb32tree.h>
+#include <eb32sctree.h>
#ifndef LLONG_MAX
# define LLONG_MAX 9223372036854775807LL
@@ -823,8 +824,15 @@
*/
unsigned int get_next_id(struct eb_root *root, unsigned int key);
-/* dump the full tree to <file> in DOT format for debugging purposes */
-void eb32sc_to_file(FILE *file, struct eb_root *root);
+/* dump the full tree to <file> in DOT format for debugging purposes. Will
+ * optionally highlight node <subj> if found, depending on operation <op> :
+ * 0 : nothing
+ * >0 : insertion, node/leaf are surrounded in red
+ * <0 : removal, node/leaf are dashed with no background
+ * Will optionally add "desc" as a label on the graph if set and non-null.
+ */
+void eb32sc_to_file(FILE *file, struct eb_root *root, const struct eb32sc_node *subj,
+ int op, const char *desc);
/* This function compares a sample word possibly followed by blanks to another
* clean word. The compare is case-insensitive. 1 is returned if both are equal,
diff --git a/src/standard.c b/src/standard.c
index a0f3d65..acd136c 100644
--- a/src/standard.c
+++ b/src/standard.c
@@ -2228,14 +2228,28 @@
return key;
}
-/* dump the full tree to <file> in DOT format for debugging purposes */
-void eb32sc_to_file(FILE *file, struct eb_root *root)
+/* dump the full tree to <file> in DOT format for debugging purposes. Will
+ * optionally highlight node <subj> if found, depending on operation <op> :
+ * 0 : nothing
+ * >0 : insertion, node/leaf are surrounded in red
+ * <0 : removal, node/leaf are dashed with no background
+ * Will optionally add "desc" as a label on the graph if set and non-null.
+ */
+void eb32sc_to_file(FILE *file, struct eb_root *root, const struct eb32sc_node *subj, int op, const char *desc)
{
struct eb32sc_node *node;
unsigned long scope = -1;
+ fprintf(file, "digraph ebtree {\n");
+
+ if (desc && *desc) {
+ fprintf(file,
+ " fontname=\"fixed\";\n"
+ " fontsize=8;\n"
+ " label=\"%s\";\n", desc);
+ }
+
fprintf(file,
- "digraph ebtree {\n"
" node [fontname=\"fixed\" fontsize=8 shape=\"box\" style=\"filled\" color=\"black\" fillcolor=\"white\"];\n"
" edge [fontname=\"fixed\" fontsize=8 style=\"solid\" color=\"magenta\" dir=\"forward\"];\n"
" \"%lx_n\" [label=\"root\\n%lx\"]\n", (long)eb_root_to_node(root), (long)root
@@ -2250,8 +2264,9 @@
while (node) {
if (node->node.node_p) {
/* node part is used */
- fprintf(file, " \"%lx_n\" [label=\"%lx\\nkey=%u\\nscope=%lx\\nbit=%d\" fillcolor=\"lightskyblue1\"];\n",
- (long)node, (long)node, node->key, node->node_s, node->node.bit);
+ fprintf(file, " \"%lx_n\" [label=\"%lx\\nkey=%u\\nscope=%lx\\nbit=%d\" fillcolor=\"lightskyblue1\" %s];\n",
+ (long)node, (long)node, node->key, node->node_s, node->node.bit,
+ (node == subj) ? (op < 0 ? "color=\"red\" style=\"dashed\"" : op > 0 ? "color=\"red\"" : "") : "");
fprintf(file, " \"%lx_n\" -> \"%lx_n\" [taillabel=\"%c\"];\n",
(long)node,
@@ -2269,8 +2284,9 @@
eb_gettag(node->node.branches.b[1]) == EB_LEAF ? 'l' : 'n');
}
- fprintf(file, " \"%lx_l\" [label=\"%lx\\nkey=%u\\nscope=%lx\\npfx=%u\" fillcolor=\"yellow\"];\n",
- (long)node, (long)node, node->key, node->leaf_s, node->node.pfx);
+ fprintf(file, " \"%lx_l\" [label=\"%lx\\nkey=%u\\nscope=%lx\\npfx=%u\" fillcolor=\"yellow\" %s];\n",
+ (long)node, (long)node, node->key, node->leaf_s, node->node.pfx,
+ (node == subj) ? (op < 0 ? "color=\"red\" style=\"dashed\"" : op > 0 ? "color=\"red\"" : "") : "");
fprintf(file, " \"%lx_l\" -> \"%lx_n\" [taillabel=\"%c\"];\n",
(long)node,