Debian Codegraph @

cmd/gvpr/lib/clustg

raw
1 /* Create derived graph whose nodes are top-level clusters (any nodes not in top-level clusters are trivial top-level clusters),
2 * and there is an edge between two nodes in the derived graph if there is an edge between the clusters in the original graph.
3 * The new graph is directed if the original one is; it is strict. Edges within clusters are ignored.
4 * Nodes and edges have a _cnt attribute indicating the number of node in a cluster and the number of equivalent edges, respectively.
5 */
6 BEGIN {
7 graph_t dg;
8 graph_t c[node_t];
9 node_t nmap[node_t];
10 node_t n, n0, dn, dn0;
11 edge_t e;
12
13 void proc (graph_t h, graph_t g)
14 {
15 if (h.name == "cluster*") {
16 dn = node(dg, h.name);
17 dn._cnt = (string)(h.n_nodes);
18 for (n = fstnode(h); n; n = nxtnode_sg(h,n)) {
19 n0 = nmap[n];
20 if (n0) {
21 printf(2,"node %s in %s and %s\n", n.name, h.name, n0.name);
22 exit(1);
23 }
24 nmap[n] = dn;
25 }
26 return;
27 }
28 for (g = fstsubg(h); g; g = nxtsubg(g)) {
29 proc(g,NULL);
30 }
31 }
32 }
33 BEG_G{
34 dg = graph("clust"+name, isDirect($)?"DS":"US");
35 setDflt(dg,"E","_cnt","0");
36 setDflt(dg,"N","_cnt","0");
37 proc($,NULL);
38 $tvtype = TV_ne;
39 }
40 N[!nmap[$]]{
41 dn = node(dg, name);
42 nmap[$] = dn;
43 }
44 E{
45 dn0 = nmap[$.tail];
46 dn = nmap[$.head];
47 if (dn != dn0) {
48 e = edge(dn0,dn,"");
49 e._cnt = (string)(1+(int)e._cnt);
50 }
51 }
52 END_G {
53 write(dg);
54 }