| 1 |
/** |
| 2 |
* @file |
| 3 |
* @ingroup cgraph_app |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "config.h" |
| 7 |
|
| 8 |
#include <assert.h> |
| 9 |
#include <cgraph/cghdr.h> |
| 10 |
#include <stddef.h> |
| 11 |
|
| 12 |
size_t graphviz_node_induce(Agraph_t *g, Agraph_t *edgeset) { |
| 13 |
|
| 14 |
assert(g != NULL); |
| 15 |
|
| 16 |
if (edgeset == NULL) { |
| 17 |
edgeset = agroot(g); |
| 18 |
} |
| 19 |
|
| 20 |
// if the graph and the edge set are the same, by implication the graph |
| 21 |
// already contains all the edges we would consider adding |
| 22 |
if (g == edgeset) { |
| 23 |
return 0; |
| 24 |
} |
| 25 |
|
| 26 |
size_t count = 0; |
| 27 |
for (Agnode_t *n = agfstnode(g); n != NULL; n = agnxtnode(g, n)) { |
| 28 |
for (Agedge_t *e = agfstout(edgeset, n); e != NULL; |
| 29 |
e = agnxtout(edgeset, e)) { |
| 30 |
if (agsubnode(g, aghead(e), 0)) { |
| 31 |
agsubedge(g, e, 1); |
| 32 |
++count; |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
return count; |
| 38 |
} |