]> granicus.if.org Git - graphviz/commitdiff
circogen ==> cgraph
authorellson <devnull@localhost>
Tue, 21 Oct 2008 22:00:26 +0000 (22:00 +0000)
committerellson <devnull@localhost>
Tue, 21 Oct 2008 22:00:26 +0000 (22:00 +0000)
lib/circogen/blockpath.c
lib/circogen/blocktree.c
lib/circogen/circular.c
lib/circogen/circularinit.c

index b8d52abf1003284957308f82ad52777ab964eff3..5eb8dd5becb10bd25009fc024b72590051397270 100644 (file)
@@ -44,22 +44,42 @@ static Agraph_t *clone_graph(Agraph_t * ing, Agraph_t ** xg)
     static int id = 0;
 
     sprintf(gname, "_clone_%d", id++);
+#ifndef WITH_CGRAPH
     clone = agsubg(ing, gname);
+#else /* WITH_CGRAPH */
+    clone = agsubg(ing, gname,1);
+    agbindrec(clone, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);      //node custom data
+#endif /* WITH_CGRAPH */
     sprintf(gname, "_clone_%d", id++);
+#ifndef WITH_CGRAPH
     xclone = agopen(gname, ing->kind);
-
     for (n = agfstnode(ing); n; n = agnxtnode(ing, n)) {
        aginsert(clone, n);
-       xn = agnode(xclone, n->name);
+       xn = agnode(xclone, agnameof(n));
+#else /* WITH_CGRAPH */
+    xclone = agopen(gname, ing->desc,NIL(Agdisc_t *));
+    for (n = agfstnode(ing); n; n = agnxtnode(ing, n)) {
+       agsubnode(clone,n,1);
+       xn = agnode(xclone, agnameof(n),1);
+        agbindrec(xn, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE);     //node custom data
+#endif /* WITH_CGRAPH */
        CLONE(n) = xn;
     }
 
     for (n = agfstnode(ing); n; n = agnxtnode(ing, n)) {
        xn = CLONE(n);
+#ifndef WITH_CGRAPH
        for (e = agfstout(ing, n); e; e = agnxtout(ing, e)) {
            aginsert(clone, e);
            xh = CLONE(e->head);
            xe = agedge(xclone, xn, xh);
+#else /* WITH_CGRAPH */
+       for (e = agfstout(ing, n); e; e = agnxtout(ing, e)) {
+           agsubedge(clone,e,1);
+           xh = CLONE(aghead(e));
+           xe = agedge(xclone, xn, xh,(char*)0,1);
+           agbindrec(xe, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);  //node custom data
+#endif /* WITH_CGRAPH */
            ORIGE(xe) = e;
            DEGREE(xn) += 1;
            DEGREE(xh) += 1;
@@ -78,7 +98,7 @@ static Agraph_t *clone_graph(Agraph_t * ing, Agraph_t ** xg)
     for (n = agfstnode(root); n; n = agnxtnode(root, n)) {
        Agnode_t *t = agnode(clone, n);
        for (e = agfstout(root, n); e; e = agnxtout(root, e)) {
-           Agnode_t *h = agnode(clone, e->head->name);
+           Agnode_t *h = agnode(clone, agnameof(aghead(e)));
            agedge(clone, t, h);
        }
     }
@@ -124,17 +144,21 @@ static void find_pair_edges(Agraph_t * g, Agnode_t * n, Agraph_t * outg)
     neighbors_without = N_GNEW(node_degree, Agnode_t *);
 
     for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
-       n1 = e->head;
+       n1 = aghead(e);
        if (n1 == n)
-           n1 = e->tail;
+           n1 = agtail(e);
        has_pair_edge = 0;
        for (ep = agfstedge(g, n); ep; ep = agnxtedge(g, ep, n)) {
            if (ep == e)
                continue;
-           n2 = ep->head;
+           n2 = aghead(ep);
            if (n2 == n)
-               n2 = ep->tail;
+               n2 = agtail(ep);
+#ifndef WITH_CGRAPH
            ex = agfindedge(g, n1, n2);
+#else /* WITH_CGRAPH */
+           ex = agedge(g, n1, n2,(char*)0,0);
+#endif /* WITH_CGRAPH */
            if (ex) {
                has_pair_edge = 1;
                if (n1 < n2) {  /* count edge only once */
@@ -167,7 +191,12 @@ static void find_pair_edges(Agraph_t * g, Agnode_t * n, Agraph_t * outg)
                    break;
                tp = neighbors_without[mark];
                hp = neighbors_without[mark + 1];
+#ifndef WITH_CGRAPH
                agedge(g, tp, hp);
+#else /* WITH_CGRAPH */
+               agbindrec(agedge(g, tp, hp,(char*)0,1), "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);    //node custom data
+
+#endif /* WITH_CGRAPH */
                DEGREE(tp)++;
                DEGREE(hp)++;
                diff--;
@@ -177,7 +206,13 @@ static void find_pair_edges(Agraph_t * g, Agnode_t * n, Agraph_t * outg)
            while (diff > 0) {
                tp = neighbors_without[0];
                hp = neighbors_without[mark];
+#ifndef WITH_CGRAPH
                agedge(g, tp, hp);
+#else /* WITH_CGRAPH */
+
+               agbindrec(agedge(g, tp, hp,(char*)0,1), "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);    //node custom data
+
+#endif /* WITH_CGRAPH */
                DEGREE(tp)++;
                DEGREE(hp)++;
                mark++;
@@ -189,7 +224,12 @@ static void find_pair_edges(Agraph_t * g, Agnode_t * n, Agraph_t * outg)
            tp = neighbors_with[0];
            for (mark = 0; mark < no_pair_count; mark++) {
                hp = neighbors_without[mark];
+#ifndef WITH_CGRAPH
                agedge(g, tp, hp);
+#else /* WITH_CGRAPH */
+               agbindrec(agedge(g, tp, hp,(char*)0,1), "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);    //node custom data
+
+#endif /* WITH_CGRAPH */
                DEGREE(tp)++;
                DEGREE(hp)++;
            }
@@ -223,18 +263,18 @@ static Agraph_t *remove_pair_edges(Agraph_t * ing)
 
        /* Remove all adjacent nodes since they have to be reinserted */
        for (e = agfstedge(g, currnode); e; e = agnxtedge(g, e, currnode)) {
-           adjNode = e->head;
+           adjNode = aghead(e);
            if (currnode == adjNode)
-               adjNode = e->tail;
+               adjNode = agtail(e);
            removeDeglist(dl, adjNode);
        }
 
        find_pair_edges(g, currnode, outg);
 
        for (e = agfstedge(g, currnode); e; e = agnxtedge(g, e, currnode)) {
-           adjNode = e->head;
+           adjNode = aghead(e);
            if (currnode == adjNode)
-               adjNode = e->tail;
+               adjNode = agtail(e);
 
            DEGREE(adjNode)--;
            insertDeglist(dl, adjNode);
@@ -357,13 +397,17 @@ static void dfs(Agraph_t * g, Agnode_t * n, Agraph_t * tree)
 
     SET_VISITED(n);
     for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
-       neighbor = e->head;
+       neighbor = aghead(e);
        if (neighbor == n)
-           neighbor = e->tail;
+           neighbor = agtail(e);
 
        if (!VISITED(neighbor)) {
            /* add the edge to the dfs tree */
+#ifndef WITH_CGRAPH
            aginsert(tree, e);
+#else /* WITH_CGRAPH */
+           agsubedge(tree,e,1);
+#endif /* WITH_CGRAPH */
            TPARENT(neighbor) = n;
            dfs(g, neighbor, tree);
        }
@@ -381,9 +425,19 @@ static Agraph_t *spanning_tree(Agraph_t * g)
     static int id = 0;
 
     sprintf(gname, "_span_%d", id++);
+#ifndef WITH_CGRAPH
     tree = agsubg(g, gname);
+#else /* WITH_CGRAPH */
+    tree = agsubg(g, gname,1);
+    agbindrec(tree, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);       //node custom data
+#endif /* WITH_CGRAPH */
+
     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
+#ifndef WITH_CGRAPH
        aginsert(tree, n);
+#else /* WITH_CGRAPH */
+       agsubnode(tree,n,1);
+#endif /* WITH_CGRAPH */
        DISTONE(n) = 0;
        DISTTWO(n) = 0;
        UNSET_VISITED(n);
@@ -410,8 +464,12 @@ static void block_graph(Agraph_t * g, block_t * sn)
 
     for (n = agfstnode(subg); n; n = agnxtnode(subg, n)) {
        for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
-           if (BLOCK(e->head) == sn)
+           if (BLOCK(aghead(e)) == sn)
+#ifndef WITH_CGRAPH
                aginsert(subg, e);
+#else /* WITH_CGRAPH */
+               agsubedge(subg,e,1);
+#endif /* WITH_CGRAPH */
        }
     }
 }
@@ -444,7 +502,7 @@ static int count_all_crossings(nodelist_t * list, Agraph_t * subg)
                     (edgelistitem *) dtnext(openEdgeList, eitem)) {
                    ep = eitem->edge;
                    if (EDGEORDER(ep) > EDGEORDER(e)) {
-                       if ((ep->head != n) && (ep->tail != n))
+                       if ((aghead(ep) != n) && (agtail(ep) != n))
                            crossings++;
                    }
                }
@@ -486,9 +544,9 @@ static nodelist_t *reduce(nodelist_t * list, Agraph_t * subg, int *cnt)
        /*  move curnode next to its neighbors */
        for (e = agfstedge(subg, curnode); e;
             e = agnxtedge(subg, e, curnode)) {
-           neighbor = e->tail;
+           neighbor = agtail(e);
            if (neighbor == curnode)
-               neighbor = e->head;
+               neighbor = aghead(e);
 
            for (j = 0; j < 2; j++) {
                listCopy = cloneNodelist(list);
@@ -561,12 +619,12 @@ static void place_node(Agraph_t * g, Agnode_t * n, nodelist_t * list)
     nodelistitem_t *one, *two;
 
     for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
-       appendNodelist(neighbors, NULL, e->head);
-       SET_NEIGHBOR(e->head);
+       appendNodelist(neighbors, NULL, aghead(e));
+       SET_NEIGHBOR(aghead(e));
     }
     for (e = agfstin(g, n); e; e = agnxtin(g, e)) {
-       appendNodelist(neighbors, NULL, e->tail);
-       SET_NEIGHBOR(e->tail);
+       appendNodelist(neighbors, NULL, agtail(e));
+       SET_NEIGHBOR(agtail(e));
     }
 
     /* Look for 2 neighbors consecutive on list */
index 52b4411a754ba36c58f843d939ab0407d4c8ae61..04b55d0d47973774e226d5546b699e274ef576bf 100644 (file)
@@ -26,7 +26,11 @@ static int min_value(int x, int y)
 
 static void addNode(block_t * bp, Agnode_t * n)
 {
+#ifndef WITH_CGRAPH
     aginsert(bp->sub_graph, n);
+#else /* WITH_CGRAPH */
+    agsubnode(bp->sub_graph, n,1);
+#endif /* WITH_CGRAPH */
     SET_BCDONE(n);
     BLOCK(n) = bp;
 }
@@ -37,7 +41,12 @@ static Agraph_t *makeBlockGraph(Agraph_t * g, circ_state * state)
     Agraph_t *subg;
 
     sprintf(name, "_block_%d", state->blockCount++);
+#ifndef WITH_CGRAPH
     subg = agsubg(g, name);
+#else /* WITH_CGRAPH */
+    subg = agsubg(g, name,1);
+    agbindrec(subg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);       //node custom data
+#endif /* WITH_CGRAPH */
     return subg;
 }
 
@@ -73,9 +82,9 @@ static void dfs(Agraph_t * g, Agnode_t * n, circ_state * state, int isRoot)
     stackPush(state->bcstack, n);
 
     for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
-       Agnode_t *neighbor = e->head;
+       Agnode_t *neighbor = aghead(e);
        if (neighbor == n)
-           neighbor = e->tail;
+           neighbor = agtail(e);
 
        if (neighbor == PARENT(n))
            continue;
@@ -196,7 +205,11 @@ static void find_blocks(Agraph_t * g, circ_state * state)
     /*      check to see if there is a node which is set to be the root
      */
     if (state->rootname) {
+#ifndef WITH_CGRAPH
        root = agfindnode(g, state->rootname);
+#else /* WITH_CGRAPH */
+       root = agnode(g, state->rootname,0);
+#endif /* WITH_CGRAPH */
     }
     if (!root && state->N_root) {
        for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
@@ -288,6 +301,7 @@ block_t *createBlocktree(Agraph_t * g, circ_state * state)
        Agraph_t *subg = bp->sub_graph;
 
        child = n = agfstnode(subg);
+
        min = VAL(n);
        parent = PARENT(n);
        for (n = agnxtnode(subg, n); n; n = agnxtnode(subg, n)) {
index fd2d8cbee1c4c0b8ca6824ba12cb18f9317c891f..322c4b439f233c2e0fc654b38fe42b42cd7ebfe9 100644 (file)
@@ -38,14 +38,23 @@ static void initGraphAttrs(Agraph_t * g, circ_state * state)
     attrsym_t *G_mindist;
     node_t *n = agfstnode(g);
 
-    rg = ORIGN(n)->graph;
+    rg = agraphof(ORIGN(n));
     if (rg != rootg) {         /* new root graph */
        state->blockCount = 0;
        rootg = rg;
+#ifndef WITH_CGRAPH
        G_mindist = agfindattr(rootg, "mindist");
+#else /* WITH_CGRAPH */
+       G_mindist = agattr(rootg,AGRAPH, "mindist",(char*)0);
+#endif /* WITH_CGRAPH */
        min_dist = late_double(rootg, G_mindist, MINDIST, 0.0);
+#ifndef WITH_CGRAPH
        N_artpos = agfindattr(rootg->proto->n, "articulation_pos");
        N_root = agfindattr(rootg->proto->n, "root");
+#else /* WITH_CGRAPH */
+       N_artpos = agattr(rootg,AGNODE, "articulation_pos",(char*)0);
+       N_root = agattr(rootg,AGNODE, "root",(char*)0);
+#endif /* WITH_CGRAPH */
        rootname = agget(rootg, "root");
     }
     initBlocklist(&state->bl);
index e0720ce38b3ddbd24231743481756303739ba56f..a2e60457aeb50ac96919d27acc31ff1e433e875e 100644 (file)
@@ -36,6 +36,9 @@
 
 static void circular_init_edge(edge_t * e)
 {
+#ifdef WITH_CGRAPH
+    agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);  //node custom data
+#endif /* WITH_CGRAPH */
     common_init_edge(e);
 
     ED_factor(e) = late_double(e, E_weight, 1.0, 0.0);
@@ -51,9 +54,9 @@ static void circular_init_node_edge(graph_t * g)
 
     GD_neato_nlist(g) = N_NEW(agnnodes(g) + 1, node_t *);
     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
+       neato_init_node(n);
        ND_alg(n) = alg + i;
        GD_neato_nlist(g)[i++] = n;
-       neato_init_node(n);
     }
     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
        for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
@@ -80,7 +83,12 @@ void circo_init_graph(graph_t * g)
 static node_t *makeDerivedNode(graph_t * dg, char *name, int isNode,
                               void *orig)
 {
+#ifndef WITH_CGRAPH
     node_t *n = agnode(dg, name);
+#else /* WITH_CGRAPH */
+    node_t *n = agnode(dg, name,1);
+    agbindrec(n, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE);  //node custom data
+#endif /* WITH_CGRAPH */
     ND_alg(n) = (void *) NEW(cdata);
     if (isNode) {
        ND_pos(n) = N_NEW(Ndim, double);
@@ -117,7 +125,11 @@ Agraph_t **circomps(Agraph_t * g, int *cnt)
     Agedge_t *me;
 #endif
 
+#ifndef WITH_CGRAPH
     dg = agopen("derived", AGFLAG_STRICT);
+#else /* WITH_CGRAPH */
+    dg = agopen("derived", Agstrictundirected,NIL(Agdisc_t *));
+#endif /* WITH_CGRAPH */
     GD_alg(g) = dg;  /* store derived graph for closing later */
 #ifdef USER_BLOCKS
     sg = g->meta_node->graph;
@@ -140,16 +152,21 @@ Agraph_t **circomps(Agraph_t * g, int *cnt)
     for (v = agfstnode(g); v; v = agnxtnode(g, v)) {
        if (DNODE(v))
            continue;
-       n = makeDerivedNode(dg, v->name, 1, v);
+       n = makeDerivedNode(dg, agnameof(v), 1, v);
        DNODE(v) = n;
     }
 
     for (v = agfstnode(g); v; v = agnxtnode(g, v)) {
        for (e = agfstout(g, v); e; e = agnxtout(g, e)) {
-           dt = DNODE(e->tail);
-           dh = DNODE(e->head);
-           if (dt != dh)
+           dt = DNODE(agtail(e));
+           dh = DNODE(aghead(e));
+           if (dt != dh) {
+#ifndef WITH_CGRAPH
                agedge(dg, dt, dh);
+#else /* WITH_CGRAPH */
+               agbindrec(agedge(dg, dt, dh,(char*)0,1), "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);   //node custom data
+#endif /* WITH_CGRAPH */
+           }
        }
     }
 
@@ -182,11 +199,17 @@ Agraph_t **circomps(Agraph_t * g, int *cnt)
        for (n = agfstnode(sg); n; n = agnxtnode(sg, n)) {
            p = ORIGN(n);
            for (e = agfstout(g, p); e; e = agnxtout(g, e)) {
-               /* n = DNODE(e->tail); by construction since e->tail == p */
-               dh = DNODE(e->head);
+               /* n = DNODE(agtail(e)); by construction since agtail(e) == p */
+               dh = DNODE(aghead(e));
                if (n != dh) {
+#ifndef WITH_CGRAPH
                    ep = agedge(dg, n, dh);
                    aginsert(sg, ep);
+#else /* WITH_CGRAPH */
+                   ep = agedge(dg, n, dh,(char*)0,1);
+                   agbindrec(ep, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);  //node custom data
+                   agsubedge(sg,ep,1);
+#endif /* WITH_CGRAPH */
                }
            }
        }
@@ -313,5 +336,10 @@ void circo_cleanup(graph_t * g)
        gv_cleanup_node(n);
     }
     free(GD_neato_nlist(g));
-    if (g != g->root) memset(&(g->u), 0, sizeof(Agraphinfo_t));
+    if (g != agroot(g)) 
+#ifndef WITH_CGRAPH
+       memset(&(g->u), 0, sizeof(Agraphinfo_t));
+#else /* WITH_CGRAPH */
+       agclean (g,AGRAPH,"Agraphinfo_t");
+#endif /* WITH_CGRAPH */
 }