aboutsummaryrefslogtreecommitdiff
path: root/trie.inc.h
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-03 13:27:20 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-03 13:27:20 +0100
commit1fd1232450a215a37915e3657964f2dad7ce72d6 (patch)
tree907cb87e027c12ffd550081513340db5aef3589a /trie.inc.h
parentMade .x files secoundary in makefile. (diff)
downloadcalp-1fd1232450a215a37915e3657964f2dad7ce72d6.tar.gz
calp-1fd1232450a215a37915e3657964f2dad7ce72d6.tar.xz
Add graphviz output for TRIE's.
Add simple output in dot format for trie structures. Along with a slightly updated main which handles a few more command line arguments. Also updated makefile to generate pdf's from dot files and dot-files from parse.
Diffstat (limited to 'trie.inc.h')
-rw-r--r--trie.inc.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/trie.inc.h b/trie.inc.h
index 50aeff29..316b54b2 100644
--- a/trie.inc.h
+++ b/trie.inc.h
@@ -110,4 +110,34 @@ int TRIE_FREE(TYPE) ( TRIE(TYPE)* trie ) {
return TRIE_NODE_FREE(TYPE)(trie->root);
}
+int TRIE_DOT(TYPE) ( TRIE(TYPE)* trie, FILE* f ) {
+ TRIE_NODE(TYPE)* n = trie->root->child;
+ fputs("root;", f);
+ while (n != NULL) {
+ fprintf(f, "root -> \"%p\"\n",
+ (void*) n);
+ fprintf(f, "subgraph \"cluster_%c\" {\n",
+ n->c);
+ TRIE_DOT_HELP(TYPE) ( n, f );
+ fputs("}", f);
+ n = n->next;
+ }
+ return 0;
+}
+
+int TRIE_DOT_HELP(TYPE) ( TRIE_NODE(TYPE)* root, FILE* f ) {
+ fprintf(f, "\"%p\"[label = \"%c\" style=filled fillcolor=\"%s\"];\n",
+ (void*) root, root->c,
+ root->value == NULL ? "white" : "green");
+ TRIE_NODE(TYPE)* child = root->child;
+
+ while (child != NULL) {
+ fprintf(f, "\"%p\" -> \"%p\";\n",
+ (void*) root, (void*) child);
+ TRIE_DOT_HELP(TYPE)(child, f);
+ child = child->next;
+ }
+ return 0;
+}
+
#endif /* TYPE */