Example #1
0
File: gc.c Project: aosm/graphviz
static void 
cc_dfs(Agraph_t* g, Agnode_t* n)
{
    Agedge_t*    e;
    Agnode_t*    nxt;

    ND_dfs_mark(n) = 1;
    for (e = agfstedge(g, n); e ; e = agnxtedge(g, e, n)) {
        if (n == e->tail) nxt = e->head;
        else nxt = e->tail;
        if (ND_dfs_mark(nxt) == 0) cc_dfs(g,nxt);
    }
}
Example #2
0
static void cc_dfs(Agraph_t* g, Agraph_t * comp, Agnode_t * n)
{
    Agedge_t *e;
    Agnode_t *other;

    CCMARK(n);
    agidnode(comp, AGID(n), 1);
    for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
	if (agtail(e) == n)
	    other = aghead(e);
	else
	    other = agtail(e);
	if (!CCMARKED(other))
	    cc_dfs(g, comp, other);
    }
}
Example #3
0
File: gc.c Project: aosm/graphviz
static int
cc_decompose(Agraph_t* g)
{
    int         c_cnt = 0;
    Agnode_t*   n;

    c_cnt = 0;
    for (n = agfstnode(g); n; n = agnxtnode(g,n))
        ND_dfs_mark(n) = 0;
    for (n = agfstnode(g); n; n = agnxtnode(g,n)) {
        if (ND_dfs_mark(n)) continue;
        c_cnt++;
        cc_dfs(g,n);
    }

    return c_cnt;
}
Example #4
0
/* compOf:
 * Return connected component of node.
 */
Agraph_t *compOf(Agraph_t * g, Agnode_t * n)
{
    Agraph_t *cg;
    Agnode_t *np;
    static int id;
    char name[64];

    if (!(n = agidnode(g, AGID(n), 0)))
	return 0;		/* n not in g */
    for (np = agfstnode(g); np; np = agnxtnode(g, np))
	CCUNMARK(np);

    sprintf(name, "_cc_%d", id++);
    cg = openSubg(g, name);
    cc_dfs(g, cg, n);

    return cg;
}