Agedge_t *e = NILedge;
sn = agsubrep(g, n);
- dtrestore(g->e_seq, sn->out_seq);
- e = (Agedge_t *) dtfirst(g->e_seq);
- sn->out_seq = dtextract(g->e_seq);
+ if (sn) {
+ dtrestore(g->e_seq, sn->out_seq);
+ e = (Agedge_t *) dtfirst(g->e_seq);
+ sn->out_seq = dtextract(g->e_seq);
+ }
return e;
}
{
Agnode_t *n;
Agsubnode_t *sn;
- Agedge_t *f;
+ Agedge_t *f = NILedge;
n = AGTAIL(e);
sn = agsubrep(g, n);
- dtrestore(g->e_seq, sn->out_seq);
- f = (Agedge_t *) dtnext(g->e_seq, e);
- sn->out_seq = dtextract(g->e_seq);
+ if (sn) {
+ dtrestore(g->e_seq, sn->out_seq);
+ f = (Agedge_t *) dtnext(g->e_seq, e);
+ sn->out_seq = dtextract(g->e_seq);
+ }
return f;
}
Agedge_t *e = NILedge;
sn = agsubrep(g, n);
- dtrestore(g->e_seq, sn->in_seq);
- e = (Agedge_t *) dtfirst(g->e_seq);
- sn->in_seq = dtextract(g->e_seq);
+ if (sn) {
+ dtrestore(g->e_seq, sn->in_seq);
+ e = (Agedge_t *) dtfirst(g->e_seq);
+ sn->in_seq = dtextract(g->e_seq);
+ }
return e;
}
{
Agnode_t *n;
Agsubnode_t *sn;
- Agedge_t *f;
+ Agedge_t *f = NILedge;
n = AGHEAD(e);
sn = agsubrep(g, n);
- dtrestore(g->e_seq, sn->in_seq);
- f = (Agedge_t *) dtnext(g->e_seq, e);
- sn->in_seq = dtextract(g->e_seq);
- return f;
+ if (sn) {
+ dtrestore(g->e_seq, sn->in_seq);
+ f = (Agedge_t *) dtnext(g->e_seq, e);
+ sn->in_seq = dtextract(g->e_seq);
+ }
+ return f;
}
Agedge_t *agfstedge(Agraph_t * g, Agnode_t * n)
static void del(Dict_t * d, Dtlink_t ** set, Agedge_t * e)
{
+ void *x;
dtrestore(d, *set);
- dtdelete(d, e);
+ x = dtdelete(d, e);
+ assert(x);
*set = dtextract(d);
}
int rv = 0;
sn = agsubrep(g, n);
- if (want_out) rv += cnt(g->e_seq,&(sn->out_seq));
- if (want_in) rv += cnt(g->e_seq,&(sn->in_seq));
+ if (sn) {
+ if (want_out) rv += cnt(g->e_seq,&(sn->out_seq));
+ if (want_in) rv += cnt(g->e_seq,&(sn->in_seq));
+ }
return rv;
}
{
void *rv;
rv = vmalloc((Vmalloc_t *) heap, request);
- memset(rv, 0, request);
+ if (rv) memset(rv, 0, request);
return rv;
}
{
Agsubnode_t *sn;
sn = agsubrep(g, n);
- sn = ((Agsubnode_t *) dtnext(g->n_seq, sn));
+ if (sn) sn = ((Agsubnode_t *) dtnext(g->n_seq, sn));
return sn ? sn->node : NILnode;
}
{
Agsubnode_t *sn;
sn = agsubrep(g, n);
- sn = ((Agsubnode_t *) dtprev(g->n_seq, sn));
+ if (sn) sn = ((Agsubnode_t *) dtprev(g->n_seq, sn));
return sn ? sn->node : NILnode;
}
static void installnode(Agraph_t * g, Agnode_t * n)
{
Agsubnode_t *sn;
+ int osize;
+
+ assert(dtsize(g->n_id) == dtsize(g->n_seq));
+ osize = dtsize(g->n_id);
if (g == agroot(g)) sn = &(n->mainsub);
else sn = agalloc(g, sizeof(Agsubnode_t));
sn->node = n;
dtinsert(g->n_id, sn);
dtinsert(g->n_seq, sn);
+ assert(dtsize(g->n_id) == dtsize(g->n_seq));
+ assert(dtsize(g->n_id) == osize + 1);
}
static void installnodetoroot(Agraph_t * g, Agnode_t * n)
n = newnode(g, id, agnextseq(g, AGNODE));
installnodetoroot(g, n);
initnode(g, n);
+ assert(agsubrep(g,n));
return n;
}
int agsubnodeidcmpf(Dict_t * d, void *arg0, void *arg1, Dtdisc_t * disc)
{
+ long v;
Agsubnode_t *sn0, *sn1;
sn0 = (Agsubnode_t *) arg0;
sn1 = (Agsubnode_t *) arg1;
- return (AGID(sn0->node) - AGID(sn1->node));
+ v = (AGID(sn0->node) - AGID(sn1->node));
+ return ((v==0)?0:(v<0?-1:1));
}
int agsubnodeseqcmpf(Dict_t * d, void *arg0, void *arg1, Dtdisc_t * disc)
{
Agsubnode_t *sn0, *sn1;
+ long v;
sn0 = (Agsubnode_t *) arg0;
sn1 = (Agsubnode_t *) arg1;
- return (AGSEQ(sn0->node) - AGSEQ(sn1->node));
+ v = (AGSEQ(sn0->node) - AGSEQ(sn1->node));
+ return ((v==0)?0:(v<0?-1:1));
}
Dtdisc_t Ag_subnode_id_disc = {
Agnode_t *n;
Agedge_t *e;
Agraph_t *s;
- int rec;
+ int rec; /* if recursive on subgraphs */
rec = (rec_size < 0);
if (rec) rec_size = -rec_size;