]> granicus.if.org Git - graphviz/commitdiff
dotgen -> cgraph
authorellson <devnull@localhost>
Tue, 21 Oct 2008 19:48:31 +0000 (19:48 +0000)
committerellson <devnull@localhost>
Tue, 21 Oct 2008 19:48:31 +0000 (19:48 +0000)
lib/dotgen/fastgr.c
lib/dotgen/flat.c
lib/dotgen/mincross.c

index 7bbad2b15d985f202b22358dfa925957c30eb553..8e54a9d8ce803012364226662da1f41fc9ba8b14 100644 (file)
@@ -30,11 +30,11 @@ static edge_t *ffe(node_t * u, elist uL, node_t * v, elist vL)
     if ((uL.size > 0) && (vL.size > 0)) {
        if (uL.size < vL.size) {
            for (i = 0; (e = uL.list[i]); i++)
-               if (e->head == v)
+               if (aghead(e) == v)
                    break;
        } else {
            for (i = 0; (e = vL.list[i]); i++)
-               if (e->tail == u)
+               if (agtail(e) == u)
                    break;
        }
     } else
@@ -79,23 +79,23 @@ edge_t *fast_edge(edge_t * e)
 #ifdef DEBUG
     int i;
     edge_t *f;
-    for (i = 0; (f = ND_out(e->tail).list[i]); i++) {
+    for (i = 0; (f = ND_out(agtail(e)).list[i]); i++) {
        if (e == f) {
            fprintf(stderr, "duplicate fast edge\n");
            return;
        }
-       assert(e->head != f->head);
+       assert(aghead(e) != aghead(f));
     }
-    for (i = 0; (f = ND_in(e->head).list[i]); i++) {
+    for (i = 0; (f = ND_in(aghead(e)).list[i]); i++) {
        if (e == f) {
            fprintf(stderr, "duplicate fast edge\n");
            return;
        }
-       assert(e->tail != f->tail);
+       assert(agtail(e) != agtail(f));
     }
 #endif
-    elist_append(e, ND_out(e->tail));
-    elist_append(e, ND_in(e->head));
+    elist_append(e, ND_out(agtail(e)));
+    elist_append(e, ND_in(aghead(e)));
     return e;
 }
 
@@ -118,8 +118,8 @@ void zapinlist(elist * L, edge_t * e)
 void delete_fast_edge(edge_t * e)
 {
     assert(e != NULL);
-    zapinlist(&(ND_out(e->tail)), e);
-    zapinlist(&(ND_in(e->head)), e);
+    zapinlist(&(ND_out(agtail(e))), e);
+    zapinlist(&(ND_in(aghead(e))), e);
 }
 
 static void 
@@ -129,22 +129,22 @@ safe_delete_fast_edge(edge_t * e)
     edge_t *f;
 
     assert(e != NULL);
-    for (i = 0; (f = ND_out(e->tail).list[i]); i++)
+    for (i = 0; (f = ND_out(agtail(e)).list[i]); i++)
        if (f == e)
-           zapinlist(&(ND_out(e->tail)), e);
-    for (i = 0; (f = ND_in(e->head).list[i]); i++)
+           zapinlist(&(ND_out(agtail(e))), e);
+    for (i = 0; (f = ND_in(aghead(e)).list[i]); i++)
        if (f == e)
-           zapinlist(&(ND_in(e->head)), e);
+           zapinlist(&(ND_in(aghead(e))), e);
 }
 
 void other_edge(edge_t * e)
 {
-    elist_append(e, ND_other(e->tail));
+    elist_append(e, ND_other(agtail(e)));
 }
 
 void safe_other_edge(edge_t * e)
 {
-    safe_list_append(e, &(ND_other(e->tail)));
+    safe_list_append(e, &(ND_other(agtail(e))));
 }
 
 #ifdef OBSOLETE
@@ -152,7 +152,7 @@ void
 delete_other_edge(edge_t * e)
 {
     assert(e != NULL);
-    zapinlist(&(ND_other(e->tail)), e);
+    zapinlist(&(ND_other(agtail(e))), e);
 }
 #endif
 
@@ -166,24 +166,29 @@ edge_t *new_virtual_edge(node_t * u, node_t * v, edge_t * orig)
 {
     edge_t *e;
 
+#ifndef WITH_CGRAPH
     e = NEW(edge_t);
-    e->tail = u;
-    e->head = v;
+#else /* WITH_CGRAPH */
+    e=agedge(agraphof(orig),u,v,"",1);
+    agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE);  //graph custom data
+#endif /* WITH_CGRAPH */
+    agtail(e) = u;
+    aghead(e) = v;
     ED_edge_type(e) = VIRTUAL;
 
     if (orig) {
-       e->id = orig->id;
+       AGID(e) = AGID(orig);
        ED_count(e) = ED_count(orig);
        ED_xpenalty(e) = ED_xpenalty(orig);
        ED_weight(e) = ED_weight(orig);
        ED_minlen(e) = ED_minlen(orig);
-       if (e->tail == orig->tail)
+       if (agtail(e) == agtail(orig))
            ED_tail_port(e) = ED_tail_port(orig);
-       else if (e->tail == orig->head)
+       else if (agtail(e) == aghead(orig))
            ED_tail_port(e) = ED_head_port(orig);
-       if (e->head == orig->head)
+       if (aghead(e) == aghead(orig))
            ED_head_port(e) = ED_head_port(orig);
-       else if (e->head == orig->tail)
+       else if (aghead(e) == agtail(orig))
            ED_head_port(e) = ED_tail_port(orig);
 
        if (ED_to_virt(orig) == NULL)
@@ -207,7 +212,7 @@ void fast_node(graph_t * g, Agnode_t * n)
 #endif
     ND_next(n) = GD_nlist(g);
     if (ND_next(n))
-       ND_next(n)->u.prev = n;
+       ND_prev(ND_next(n)) = n;
     GD_nlist(g) = n;
     ND_prev(n) = NULL;
     assert(n != ND_next(n));
@@ -219,7 +224,7 @@ void fast_nodeapp(node_t * u, node_t * v)
     assert(ND_next(v) == NULL);
     ND_next(v) = ND_next(u);
     if (ND_next(u))
-       ND_next(u)->u.prev = v;
+       ND_prev(ND_next(u)) = v;
     ND_prev(v) = u;
     ND_next(u) = v;
 }
@@ -228,9 +233,9 @@ void delete_fast_node(graph_t * g, node_t * n)
 {
     assert(find_fast_node(g, n));
     if (ND_next(n))
-       ND_next(n)->u.prev = ND_prev(n);
+       ND_prev(ND_next(n)) = ND_prev(n);
     if (ND_prev(n))
-       ND_prev(n)->u.next = ND_next(n);
+       ND_next(ND_prev(n)) = ND_next(n);
     else
        GD_nlist(g) = ND_next(n);
 }
@@ -240,8 +245,13 @@ node_t *virtual_node(graph_t * g)
     node_t *n;
 
     n = NEW(node_t);
+#ifndef WITH_CGRAPH
     n->name = "virtual";
     n->graph = g;
+#else /* WITH_CGRAPH */
+//  agnameof(n) = "virtual";
+    n->root = g;
+#endif /* WITH_CGRAPH */
     ND_node_type(n) = VIRTUAL;
     ND_lw(n) = ND_rw(n) = 1;
     ND_ht(n) = 1;
@@ -255,9 +265,9 @@ node_t *virtual_node(graph_t * g)
 
 void flat_edge(graph_t * g, edge_t * e)
 {
-    elist_append(e, ND_flat_out(e->tail));
-    elist_append(e, ND_flat_in(e->head));
-    GD_has_flat_edges(g->root) = GD_has_flat_edges(g) = TRUE;
+    elist_append(e, ND_flat_out(agtail(e)));
+    elist_append(e, ND_flat_in(aghead(e)));
+    GD_has_flat_edges(agroot(g)) = GD_has_flat_edges(g) = TRUE;
 }
 
 void delete_flat_edge(edge_t * e)
@@ -265,8 +275,8 @@ void delete_flat_edge(edge_t * e)
     assert(e != NULL);
     if (ED_to_orig(e) && ED_to_virt(ED_to_orig(e)) == e)
        ED_to_virt(ED_to_orig(e)) = NULL;
-    zapinlist(&(ND_flat_out(e->tail)), e);
-    zapinlist(&(ND_flat_in(e->head)), e);
+    zapinlist(&(ND_flat_out(agtail(e))), e);
+    zapinlist(&(ND_flat_in(aghead(e))), e);
 }
 
 #ifdef DEBUG
@@ -288,8 +298,8 @@ void fastgr(graph_t * g)
     for (n = GD_nlist(g); n; n = ND_next(n)) {
        fprintf(stderr, "%s %d: (", NAME(n), ND_rank(n));
        for (i = 0; e = ND_out(n).list[i]; i++) {
-           fprintf(stderr, " %s:%d", NAME(e->head), ED_count(e));
-           w = e->head;
+           fprintf(stderr, " %s:%d", NAME(aghead(e)), ED_count(e));
+           w = aghead(e);
            if (g == g->root) {
                for (j = 0; f = ND_in(w).list[j]; j++)
                    if (e == f)
@@ -299,8 +309,8 @@ void fastgr(graph_t * g)
        }
        fprintf(stderr, " ) (");
        for (i = 0; e = ND_in(n).list[i]; i++) {
-           fprintf(stderr, " %s:%d", NAME(e->tail), ED_count(e));
-           w = e->tail;
+           fprintf(stderr, " %s:%d", NAME(agtail(e)), ED_count(e));
+           w = agtail(e);
            if (g == g->root) {
                for (j = 0; f = ND_out(w).list[j]; j++)
                    if (e == f)
@@ -357,9 +367,9 @@ void unmerge_oneway(edge_t * e)
 
        /* unmerge from a virtual edge chain */
        while ((ED_edge_type(rep) == VIRTUAL)
-              && (ND_node_type(rep->head) == VIRTUAL)
-              && (ND_out(rep->head).size == 1)) {
-           rep = ND_out(rep->head).list[0];
+              && (ND_node_type(aghead(rep)) == VIRTUAL)
+              && (ND_out(aghead(rep)).size == 1)) {
+           rep = ND_out(aghead(rep)).list[0];
            unrep(rep, e);
        }
     }
index 38698729b4b54795d6de678940956dd779c3a92f..1527a870f1a307fb308277fb4bad9a1c194d022c 100644 (file)
@@ -27,7 +27,7 @@ static node_t *make_vn_slot(graph_t * g, int r, int pos)
        ALLOC(GD_rank(g)[r].n + 2, GD_rank(g)[r].v, node_t *);
     for (i = GD_rank(g)[r].n; i > pos; i--) {
        v[i] = v[i - 1];
-       v[i]->u.order++;
+       ND_order(v[i])++;
     }
     n = v[pos] = virtual_node(g);
     ND_order(n) = pos;
@@ -64,7 +64,7 @@ static void setbounds(node_t * v, int *bounds, int lpos, int rpos)
        ord = ND_order(v);
        if (ND_in(v).size == 0) {       /* flat */
            assert(ND_out(v).size == 2);
-           findlr(ND_out(v).list[0]->head, ND_out(v).list[1]->head, &l,
+           findlr(aghead(ND_out(v).list[0]), aghead(ND_out(v).list[1]), &l,
                   &r);
            /* the other flat edge could be to the left or right */
            if (r <= lpos)
@@ -84,11 +84,11 @@ static void setbounds(node_t * v, int *bounds, int lpos, int rpos)
            boolean onleft, onright;
            onleft = onright = FALSE;
            for (i = 0; (f = ND_out(v).list[i]); i++) {
-               if (ND_order(f->head) <= lpos) {
+               if (ND_order(aghead(f)) <= lpos) {
                    onleft = TRUE;
                    continue;
                }
-               if (ND_order(f->head) >= rpos) {
+               if (ND_order(aghead(f)) >= rpos) {
                    onright = TRUE;
                    continue;
                }
@@ -106,13 +106,13 @@ static int flat_limits(graph_t * g, edge_t * e)
     int lnode, rnode, r, bounds[4], lpos, rpos, pos;
     node_t **rank;
 
-    r = ND_rank(e->tail) - 1;
+    r = ND_rank(agtail(e)) - 1;
     rank = GD_rank(g)[r].v;
     lnode = 0;
     rnode = GD_rank(g)[r].n - 1;
     bounds[HLB] = bounds[SLB] = lnode - 1;
     bounds[HRB] = bounds[SRB] = rnode + 1;
-    findlr(e->tail, e->head, &lpos, &rpos);
+    findlr(agtail(e), aghead(e), &lpos, &rpos);
     while (lnode <= rnode) {
        setbounds(rank[lnode], bounds, lpos, rpos);
        if (lnode != rnode)
@@ -146,8 +146,8 @@ flat_node(edge_t * e)
 
     if (ED_label(e) == NULL)
        return;
-    g = e->tail->graph;
-    r = ND_rank(e->tail);
+    g = agraphof(agtail(e));
+    r = ND_rank(agtail(e));
 
     place = flat_limits(g, e);
     /* grab ypos = LL.y of label box before make_vn_slot() */
@@ -169,13 +169,13 @@ flat_node(edge_t * e)
     ND_lw(vn) = ND_rw(vn) = dimen.x / 2;
     ND_label(vn) = ED_label(e);
     ND_coord(vn).y = ypos + h2;
-    ve = virtual_edge(vn, e->tail, e); /* was NULL? */
+    ve = virtual_edge(vn, agtail(e), e);       /* was NULL? */
     ED_tail_port(ve).p.x = -ND_lw(vn);
-    ED_head_port(ve).p.x = ND_rw(e->tail);
+    ED_head_port(ve).p.x = ND_rw(agtail(e));
     ED_edge_type(ve) = FLATORDER;
-    ve = virtual_edge(vn, e->head, e);
+    ve = virtual_edge(vn, aghead(e), e);
     ED_tail_port(ve).p.x = ND_rw(vn);
-    ED_head_port(ve).p.x = ND_lw(e->head);
+    ED_head_port(ve).p.x = ND_lw(aghead(e));
     ED_edge_type(ve) = FLATORDER;
     /* another assumed symmetry of ht1/ht2 of a label node */
     if (GD_rank(g)[r - 1].ht1 < h2)
@@ -212,8 +212,8 @@ static void abomination(graph_t * g)
 static int
 flatAdjacent (edge_t* e)
 {
-    node_t* tn = e->tail;
-    node_t* hn = e->head;
+    node_t* tn = agtail(e);
+    node_t* hn = aghead(e);
     int i, lo, hi;
     node_t* n;
     rank_t *rank;
@@ -226,7 +226,7 @@ flatAdjacent (edge_t* e)
        lo = ND_order(hn);
        hi = ND_order(tn);
     }
-    rank = &(GD_rank(tn->graph)[ND_rank(tn)]);
+    rank = &(GD_rank(agraphof(tn))[ND_rank(tn)]);
     for (i = lo + 1; i < hi; i++) {
        n = rank->v[i];
        if ((ND_node_type(n) == VIRTUAL && ND_label(n)) || 
@@ -302,8 +302,8 @@ flat_edges(graph_t * g)
            for (j = 0; j < ND_other(n).size; j++) {
                edge_t* le;
                e = ND_other(n).list[j];
-               if (ND_rank(e->tail) != ND_rank(e->head)) continue;
-               if (e->tail == e->head) continue; /* skip loops */
+               if (ND_rank(agtail(e)) != ND_rank(aghead(e))) continue;
+               if (agtail(e) == aghead(e)) continue; /* skip loops */
                le = e;
                while (ED_to_virt(le)) le = ED_to_virt(le);
                ED_adjacent(e) = ED_adjacent(le); 
index 8d6186f7625190b2d9e576e2f383bd033ec16809..8ed2122d68c5ead2c932d14a2f7ff65d5970fbfe 100644 (file)
@@ -25,9 +25,9 @@
 #include "dot.h"
 
 /* #define DEBUG */
-#define MARK(v)                        ((v)->u.mark)
-#define saveorder(v)   ((v)->u.coord.x)
-#define flatindex(v)   ((v)->u.low)
+#define MARK(v)                (ND_mark(v))
+#define saveorder(v)   (ND_coord(v)).x
+#define flatindex(v)   ND_low(v)
 
        /* forward declarations */
 static boolean medians(graph_t * g, int r0, int r1);
@@ -144,7 +144,7 @@ static int betweenclust(edge_t * e)
 {
     while (ED_to_orig(e))
        e = ED_to_orig(e);
-    return (ND_clust(e->tail) != ND_clust(e->head));
+    return (ND_clust(agtail(e)) != ND_clust(aghead(e)));
 }
 
 static void do_ordering(graph_t * g, int outflag)
@@ -175,11 +175,11 @@ static void do_ordering(graph_t * g, int outflag)
        for (ne = 1; (f = sortlist[ne]); ne++) {
            e = sortlist[ne - 1];
            if (outflag) {
-               u = e->head;
-               v = f->head;
+               u = aghead(e);
+               v = aghead(f);
            } else {
-               u = e->tail;
-               v = f->tail;
+               u = agtail(e);
+               v = agtail(f);
            }
            if (find_flat_edge(u, v))
                continue;
@@ -205,9 +205,10 @@ static void ordered_edges(graph_t * g)
        else if (ordering[0])
            agerr(AGERR, "ordering '%s' not recognized.\n", ordering);
     }
-
-    else {
+    else
+    {
        /* search meta-graph to find subgraphs that may be ordered */
+#ifndef WITH_CGRAPH
        graph_t *mg, *subg;
        node_t *mm, *mn;
        edge_t *me;
@@ -218,6 +219,11 @@ static void ordered_edges(graph_t * g)
            mn = me->head;
            subg = agusergraph(mn);
            /* clusters are processed by seperate calls to ordered_edges */
+#else /* WITH_CGRAPH */
+       graph_t *subg;
+
+       for (subg = agfstsubg(g); subg; subg = agnxtsubg(subg)) {
+#endif /* WITH_CGRAPH */
            if (!is_cluster(subg))
                ordered_edges(subg);
        }
@@ -283,15 +289,16 @@ static int in_cross(node_t * v, node_t * w)
     register int inv, cross = 0, t;
 
     for (e2 = ND_in(w).list; *e2; e2++) {
-       register int cnt = (*e2)->u.xpenalty;
-       inv = ((*e2)->tail)->u.order;
+       register int cnt = ED_xpenalty(*e2);            
+               
+       inv = ND_order((agtail(*e2)));
 
        for (e1 = ND_in(v).list; *e1; e1++) {
-           t = ((*e1)->tail)->u.order - inv;
+           t = ND_order(agtail(*e1)) - inv;
            if ((t > 0)
                || ((t == 0)
-                   && ((*e1)->u.tail_port.p.x > (*e2)->u.tail_port.p.x)))
-               cross += (*e1)->u.xpenalty * cnt;
+                   && (  ED_tail_port(*e1).p.x > ED_tail_port(*e2).p.x)))
+               cross += ED_xpenalty(*e1) * cnt;
        }
     }
     return cross;
@@ -303,15 +310,15 @@ static int out_cross(node_t * v, node_t * w)
     register int inv, cross = 0, t;
 
     for (e2 = ND_out(w).list; *e2; e2++) {
-       register int cnt = (*e2)->u.xpenalty;
-       inv = ((*e2)->head)->u.order;
+       register int cnt = ED_xpenalty(*e2);
+       inv = ND_order(aghead(*e2));
 
        for (e1 = ND_out(v).list; *e1; e1++) {
-           t = ((*e1)->head)->u.order - inv;
+           t = ND_order(aghead(*e1)) - inv;
            if ((t > 0)
                || ((t == 0)
-                   && ((*e1)->u.head_port.p.x > (*e2)->u.head_port.p.x)))
-               cross += (*e1)->u.xpenalty * cnt;
+                   && ((ED_head_port(*e1)).p.x > (ED_head_port(*e2)).p.x)))
+               cross += ((ED_xpenalty(*e1)) * cnt);
        }
     }
     return cross;
@@ -552,7 +559,7 @@ static int mincross(graph_t * g, int startpass, int endpass, int doBalance)
     for (pass = startpass; pass <= endpass; pass++) {
        if (pass <= 1) {
            maxthispass = MIN(4, MaxIter);
-           if (g == g->root)
+           if (g == agroot(g))
                build_ranks(g, pass);
            if (pass == 0)
                flat_breakcycles(g);
@@ -669,7 +676,7 @@ static void merge2(graph_t * g)
                if (Verbose)
                    fprintf(stderr,
                            "merge2: graph %s, rank %d has only %d < %d nodes\n",
-                           g->name, r, i, GD_rank(g)[r].n);
+                           agnameof(g), r, i, GD_rank(g)[r].n);
                GD_rank(g)[r].n = i;
                break;
            }
@@ -714,7 +721,7 @@ static void cleanup2(graph_t * g, int nc)
     }
     if (Verbose)
        fprintf(stderr, "mincross %s: %d crossings, %.2f secs.\n",
-               g->name, nc, elapsed_sec());
+               agnameof(g), nc, elapsed_sec());
 }
 
 static node_t *neighbor(node_t * v, int dir)
@@ -808,7 +815,11 @@ void rec_reset_vlists(graph_t * g)
 #ifdef DEBUG
            assert(GD_rank(g->root)[r].v[ND_order(u)] == u);
 #endif
+#ifndef WITH_CGRAPH
            GD_rank(g)[r].v = ND_rank(g->root)[r].v + ND_order(u);
+#else /* WITH_CGRAPH */
+           GD_rank(g)[r].v = GD_rank(agroot(g))[r].v + ND_order(u);
+#endif /* WITH_CGRAPH */
            GD_rank(g)[r].n = ND_order(w) - ND_order(u) + 1;
        }
 }
@@ -825,7 +836,7 @@ static void init_mincross(graph_t * g)
     /* alloc +1 for the null terminator usage in do_ordering() */
     /* also, the +1 avoids attempts to alloc 0 sizes, something
        that efence complains about */
-    size = agnedges(g->root) + 1;
+    size = agnedges(agroot(g)) + 1;
     TE_list = N_NEW(size, edge_t *);
     TI_list = N_NEW(size, int);
     mincross_options(g);
@@ -842,11 +853,11 @@ void flat_rev(Agraph_t * g, Agedge_t * e)
     int j;
     Agedge_t *rev;
 
-    if (!ND_flat_out(e->head).list)
+    if (!ND_flat_out(aghead(e)).list)
        rev = NULL;
     else
-       for (j = 0; (rev = ND_flat_out(e->head).list[j]); j++)
-           if (rev->head == e->tail)
+       for (j = 0; (rev = ND_flat_out(aghead(e)).list[j]); j++)
+           if (aghead(rev) == agtail(e))
                break;
     if (rev) {
        merge_oneway(e, rev);
@@ -855,9 +866,9 @@ void flat_rev(Agraph_t * g, Agedge_t * e)
        if ((ED_edge_type(rev) == FLATORDER)
            && (ED_to_orig(rev) == 0))
            ED_to_orig(rev) = e;
-       elist_append(e, ND_other(e->tail));
+       elist_append(e, ND_other(agtail(e)));
     } else {
-       rev = new_virtual_edge(e->head, e->tail, e);
+       rev = new_virtual_edge(aghead(e), agtail(e), e);
        if (ED_edge_type(e) == FLATORDER)
            ED_edge_type(rev) = FLATORDER;
        else
@@ -876,29 +887,33 @@ static void flat_search(graph_t * g, node_t * v)
 
     ND_mark(v) = TRUE;
     ND_onstack(v) = TRUE;
+#ifndef WITH_CGRAPH
     hascl = (ND_n_cluster(g->root) > 0);
+#else /* WITH_CGRAPH */
+    hascl = (GD_n_cluster(agroot(g)) > 0);
+#endif /* WITH_CGRAPH */
     if (ND_flat_out(v).list)
        for (i = 0; (e = ND_flat_out(v).list[i]); i++) {
            if (hascl
-               && NOT(agcontains(g, e->tail) && agcontains(g, e->head)))
+               && NOT(agcontains(g, agtail(e)) && agcontains(g, aghead(e))))
                continue;
            if (ED_weight(e) == 0)
                continue;
-           if (ND_onstack(e->head) == TRUE) {
-               assert(flatindex(e->head) < M->nrows);
-               assert(flatindex(e->tail) < M->ncols);
-               ELT(M, flatindex(e->head), flatindex(e->tail)) = 1;
+           if (ND_onstack(aghead(e)) == TRUE) {
+               assert(flatindex(aghead(e)) < M->nrows);
+               assert(flatindex(agtail(e)) < M->ncols);
+               ELT(M, flatindex(aghead(e)), flatindex(agtail(e))) = 1;
                delete_flat_edge(e);
                i--;
                if (ED_edge_type(e) == FLATORDER)
                    continue;
                flat_rev(g, e);
            } else {
-               assert(flatindex(e->head) < M->nrows);
-               assert(flatindex(e->tail) < M->ncols);
-               ELT(M, flatindex(e->tail), flatindex(e->head)) = 1;
-               if (ND_mark(e->head) == FALSE)
-                   flat_search(g, e->head);
+               assert(flatindex(aghead(e)) < M->nrows);
+               assert(flatindex(agtail(e)) < M->ncols);
+               ELT(M, flatindex(agtail(e)), flatindex(aghead(e))) = 1;
+               if (ND_mark(aghead(e)) == FALSE)
+                   flat_search(g, aghead(e));
            }
        }
     ND_onstack(v) = FALSE;
@@ -945,8 +960,8 @@ void allocate_ranks(graph_t * g)
     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
        cn[ND_rank(n)]++;
        for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
-           low = ND_rank(e->tail);
-           high = ND_rank(e->head);
+           low = ND_rank(agtail(e));
+           high = ND_rank(aghead(e));
            if (low > high) {
                int t = low;
                low = high;
@@ -973,7 +988,7 @@ void install_in_rank(graph_t * g, node_t * n)
     i = GD_rank(g)[r].n;
     if (GD_rank(g)[r].an <= 0) {
        agerr(AGERR, "install_in_rank %s %s rank %d i = %d an = 0\n",
-             g->name, n->name, r, i);
+             agnameof(g), agnameof(n), r, i);
        abort();
     }
 
@@ -1020,9 +1035,9 @@ void build_ranks(graph_t * g, int pass)
        edge_t *e;
        for (n = GD_nlist(g); n; n = ND_next(n)) {
            for (i = 0; (e = ND_out(n).list[i]); i++)
-               assert(MARK(e->head) == FALSE);
+               assert(MARK(aghead(e)) == FALSE);
            for (i = 0; (e = ND_in(n).list[i]); i++)
-               assert(MARK(e->tail) == FALSE);
+               assert(MARK(agtail(e)) == FALSE);
        }
     }
 #endif
@@ -1061,7 +1076,7 @@ void build_ranks(graph_t * g, int pass)
        }
     }
 
-    if ((g == g->root) && ncross(g) > 0)
+    if ((g == agroot(g)) && ncross(g) > 0)
        transpose(g, FALSE);
     free_queue(q);
 }
@@ -1074,17 +1089,17 @@ void enqueue_neighbors(nodequeue * q, node_t * n0, int pass)
     if (pass == 0) {
        for (i = 0; i < ND_out(n0).size; i++) {
            e = ND_out(n0).list[i];
-           if ((MARK(e->head)) == FALSE) {
-               MARK(e->head) = TRUE;
-               enqueue(q, e->head);
+           if ((MARK(aghead(e))) == FALSE) {
+               MARK(aghead(e)) = TRUE;
+               enqueue(q, aghead(e));
            }
        }
     } else {
        for (i = 0; i < ND_in(n0).size; i++) {
            e = ND_in(n0).list[i];
-           if ((MARK(e->tail)) == FALSE) {
-               MARK(e->tail) = TRUE;
-               enqueue(q, e->tail);
+           if ((MARK(agtail(e))) == FALSE) {
+               MARK(agtail(e)) = TRUE;
+               enqueue(q, agtail(e));
            }
        }
     }
@@ -1103,14 +1118,14 @@ static int postorder(graph_t * g, node_t * v, node_t ** list, int r)
        for (i = 0; (e = ND_flat_out(v).list[i]); i++) {
            if (ED_weight(e) == 0)
                continue;
-           if ((ND_node_type(e->head) == NORMAL) &
-               (NOT(agcontains(g, e->head))))
+           if ((ND_node_type(aghead(e)) == NORMAL) &
+               (NOT(agcontains(g, aghead(e)))))
                continue;
-           if (ND_clust(e->head) != ND_clust(e->tail))
+           if (ND_clust(aghead(e)) != ND_clust(agtail(e)))
                continue;
 
-           if (MARK(e->head) == FALSE)
-               cnt += postorder(g, e->head, list + cnt, r);
+           if (MARK(aghead(e)) == FALSE)
+               cnt += postorder(g, aghead(e), list + cnt, r);
        }
     }
     assert(ND_rank(v) == r);
@@ -1139,13 +1154,13 @@ static void flat_reorder(graph_t * g)
            for (j = 0; j < ND_flat_in(v).size; j++) {
                flat_e = ND_flat_in(v).list[j];
                if ((ED_weight(flat_e) > 0)
-                   && (inside_cluster(g, flat_e->tail)))
+                   && (inside_cluster(g, aghead(flat_e))))
                    local_in_cnt++;
            }
            for (j = 0; j < ND_flat_out(v).size; j++) {
                flat_e = ND_flat_out(v).list[j];
                if ((ED_weight(flat_e) > 0)
-                   && (inside_cluster(g, flat_e->head)))
+                   && (inside_cluster(g, aghead(flat_e))))
                    local_out_cnt++;
            }
            if ((local_in_cnt == 0) && (local_out_cnt == 0))
@@ -1179,7 +1194,7 @@ static void flat_reorder(graph_t * g)
                v = GD_rank(g)[r].v[i];
                if (ND_flat_out(v).list) {
                    for (j = 0; (e = ND_flat_out(v).list[j]); j++) {
-                       if (ND_order(e->head) < ND_order(e->tail)) {
+                       if (ND_order(aghead(e)) < ND_order(agtail(e))) {
                            /*assert(ED_weight(e) == 0); */
                            delete_flat_edge(e);
                            j--;
@@ -1207,29 +1222,29 @@ static void reorder(graph_t * g, int r, int reverse, int hasfixed)
        lp = vlist;
        while (lp < ep) {
            /* find leftmost node that can be compared */
-           while ((lp < ep) && ((*lp)->u.mval < 0))
+           while ((lp < ep) && (ND_mval(*lp) < 0))
                lp++;
            if (lp >= ep)
                break;
            /* find the node that can be compared */
            sawclust = muststay = FALSE;
            for (rp = lp + 1; rp < ep; rp++) {
-               if (sawclust && (*rp)->u.clust)
+               if (sawclust && ND_clust(*rp))
                    continue;   /* ### */
                if (left2right(g, *lp, *rp)) {
                    muststay = TRUE;
                    break;
                }
-               if ((*rp)->u.mval >= 0)
+               if (ND_mval(*rp) >= 0)
                    break;
-               if ((*rp)->u.clust)
+               if (ND_clust(*rp))
                    sawclust = TRUE;    /* ### */
            }
            if (rp >= ep)
                break;
            if (muststay == FALSE) {
-               register int p1 = ((*lp)->u.mval);
-               register int p2 = ((*rp)->u.mval);
+               register int p1 = (ND_mval(*lp));
+               register int p2 = (ND_mval(*rp));
                if ((p1 > p2) || ((p1 == p2) && (reverse))) {
                    exchange(*lp, *rp);
                    changed++;
@@ -1300,15 +1315,13 @@ static int local_cross(elist l, int dir)
     for (i = 0; (e = l.list[i]); i++) {
        if (is_out)
            for (j = i + 1; (f = l.list[j]); j++) {
-               if ((ND_order(f->head) -
-                    ND_order(e->head)) * (ED_tail_port(f).p.x -
-                                          ED_tail_port(e).p.x) < 0)
+               if ((ND_order(aghead(f)) - ND_order(aghead(e)))
+                        * (ED_tail_port(f).p.x - ED_tail_port(e).p.x) < 0)
                    cross += ED_xpenalty(e) * ED_xpenalty(f);
        } else
            for (j = i + 1; (f = l.list[j]); j++) {
-               if ((ND_order(f->tail) -
-                    ND_order(e->tail)) * (ED_head_port(f).p.x -
-                                          ED_head_port(e).p.x) < 0)
+               if ((ND_order(agtail(f)) - ND_order(agtail(e)))
+                       * (ED_head_port(f).p.x - ED_head_port(e).p.x) < 0)
                    cross += ED_xpenalty(e) * ED_xpenalty(f);
            }
     }
@@ -1336,13 +1349,13 @@ static int rcross(graph_t * g, int r)
     for (top = 0; top < GD_rank(g)[r].n; top++) {
        register edge_t *e;
        if (max > 0) {
-           for (i = 0; (e = rtop[top]->u.out.list[i]); i++) {
-               for (k = ND_order(e->head) + 1; k <= max; k++)
+           for (i = 0; (e = ND_out(rtop[top]).list[i]); i++) {
+               for (k = ND_order(aghead(e)) + 1; k <= max; k++)
                    cross += Count[k] * ED_xpenalty(e);
            }
        }
-       for (i = 0; (e = rtop[top]->u.out.list[i]); i++) {
-           register int inv = ND_order(e->head);
+       for (i = 0; (e = ND_out(rtop[top]).list[i]); i++) {
+           register int inv = ND_order(aghead(e));
            if (inv > max)
                max = inv;
            Count[inv] += ED_xpenalty(e);
@@ -1402,20 +1415,20 @@ static int flat_mval(node_t * n)
 
     if (ND_flat_in(n).size > 0) {
        fl = ND_flat_in(n).list;
-       nn = fl[0]->tail;
+       nn = agtail(fl[0]);
        for (i = 1; (e = fl[i]); i++)
-           if (ND_order(e->tail) > ND_order(nn))
-               nn = e->tail;
+           if (ND_order(agtail(e)) > ND_order(nn))
+               nn = agtail(e);
        if (ND_mval(nn) >= 0) {
            ND_mval(n) = ND_mval(nn) + 1;
            return FALSE;
        }
     } else if (ND_flat_out(n).size > 0) {
        fl = ND_flat_out(n).list;
-       nn = fl[0]->head;
+       nn = aghead(fl[0]);
        for (i = 1; (e = fl[i]); i++)
-           if (ND_order(e->head) < ND_order(nn))
-               nn = e->head;
+           if (ND_order(aghead(e)) < ND_order(nn))
+               nn = aghead(e);
        if (ND_mval(nn) > 0) {
            ND_mval(n) = ND_mval(nn) - 1;
            return FALSE;
@@ -1424,7 +1437,7 @@ static int flat_mval(node_t * n)
     return TRUE;
 }
 
-#define VAL(node,port) (MC_SCALE * (node)->u.order + (port).order)
+#define VAL(node,port) (MC_SCALE * ND_order(node) + (port).order)
 
 static boolean medians(graph_t * g, int r0, int r1)
 {
@@ -1441,11 +1454,11 @@ static boolean medians(graph_t * g, int r0, int r1)
        if (r1 > r0)
            for (j0 = 0; (e = ND_out(n).list[j0]); j0++) {
                if (ED_xpenalty(e) > 0)
-                   list[j++] = VAL(e->head, ED_head_port(e));
+                   list[j++] = VAL(aghead(e), ED_head_port(e));
        } else
            for (j0 = 0; (e = ND_in(n).list[j0]); j0++) {
                if (ED_xpenalty(e) > 0)
-                   list[j++] = VAL(e->tail, ED_tail_port(e));
+                   list[j++] = VAL(agtail(e), ED_tail_port(e));
            }
        switch (j) {
        case 0:
@@ -1486,12 +1499,12 @@ static boolean medians(graph_t * g, int r0, int r1)
 
 static int nodeposcmpf(node_t ** n0, node_t ** n1)
 {
-    return ((*n0)->u.order - (*n1)->u.order);
+    return (ND_order(*n0) - ND_order(*n1));
 }
 
 static int edgeidcmpf(edge_t ** e0, edge_t ** e1)
 {
-    return ((*e0)->id - (*e1)->id);
+    return (AGID(*e0) - AGID(*e1));
 }
 
 /* following code deals with weights of edges of "virtual" nodes */
@@ -1523,7 +1536,7 @@ static int endpoint_class(node_t * n)
 void virtual_weight(edge_t * e)
 {
     int t;
-    t = table[endpoint_class(e->tail)][endpoint_class(e->head)];
+    t = table[endpoint_class(agtail(e))][endpoint_class(aghead(e))];
     ED_weight(e) *= t;
 }