-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphviz.cpp
More file actions
40 lines (35 loc) · 1.11 KB
/
graphviz.cpp
File metadata and controls
40 lines (35 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <string>
#include "global.hpp"
#include <set>
using std::string;
using std::to_string;
string before = "digraph SuffixTree { \n\
node [shape=circle, label=\"\"];\n";
string after = "}\n";
string get_line(long ID1, long ID2, string label) {
return string(" ") + to_string(ID1) + " -> " + to_string(ID2) + ("[label=\"" + label + "\"];\n");
}
string visualize_graphviz(CST &T) {
Node root = T.root();
string lines = "";
std::set<Node> covered;
for (Node node : T) {
if (covered.count(node) != 0) {
continue;
}
if (node != T.root()) {
Node parent = T.parent(node);
string label = "";
for (long i = T.depth(parent)+1; i <= T.depth(node); i++) {
char c = T.edge(node, i);
label += (c ? c : '$');
}
if (label.length() > 4 && label[label.length() - 1] == '$') {
label = label.substr(0, 1) + "..$";
}
lines += get_line(T.id(parent), T.id(node), label);
}
covered.insert(node);
}
return before + lines + after;
}