#include "config.h"
#include <assert.h>
#include <cgraph/alloc.h>
+#include <cgraph/list.h>
#include <fdpgen/clusteredges.h>
#include <fdpgen/fdp.h>
#include <limits.h>
#include <pack/pack.h>
#include <stdbool.h>
-typedef struct {
- size_t cnt;
- size_t sz;
- Ppoly_t **obs;
-} objlist;
-
-/* addObj:
- * Add an object to the list. The array is increased if necessary.
- */
-#define INIT_SZ 100
+DEFINE_LIST(objlist, Ppoly_t*)
#if defined(DEBUG) && DEBUG > 1
static void dumpObj(Ppoly_t * p)
fputs("\n", stderr);
}
-static void dumpObjlist(objlist * l)
-{
- for (size_t i = 0; i < l->cnt; i++) {
- dumpObj(l->obs[i]);
+static void dumpObjlist(const objlist_t *l) {
+ for (size_t i = 0; i < objlist_size(l); i++) {
+ dumpObj(objlist_get(l, i));
}
}
#endif
-static void addObj(objlist * l, Ppoly_t * obj)
-{
- if (l->sz == l->cnt) {
- if (l->obs) {
- l->obs = gv_recalloc(l->obs, l->sz, l->sz * 2, sizeof(Ppoly_t*));
- l->sz *= 2;
- } else {
- l->obs = gv_calloc(INIT_SZ, sizeof(Ppoly_t*));
- l->sz = INIT_SZ;
- }
- }
- l->obs[l->cnt++] = obj;
-}
-
-/* freeObjlist:
- * Release memory.
- */
-static void freeObjlist(objlist * l)
-{
- if (l) {
- free(l->obs);
- free(l);
- }
-}
-
/* makeClustObs:
* Create an obstacle corresponding to a cluster's bbox.
*/
* Return the list.
*/
static void
-addGraphObjs(objlist * l, graph_t * g, void *tex, void *hex, expand_t* pm)
-{
+addGraphObjs(objlist_t *l, graph_t *g, void *tex, void *hex, expand_t *pm) {
node_t *n;
graph_t *sg;
int i;
for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
if (PARENT(n) == g && n != tex && n != hex && !IS_CLUST_NODE(n)) {
- addObj(l, makeObstacle(n, pm, false));
+ objlist_append(l, makeObstacle(n, pm, false));
}
}
for (i = 1; i <= GD_n_cluster(g); i++) {
sg = GD_clust(g)[i];
if (sg != tex && sg != hex) {
- addObj(l, makeClustObs(sg, pm));
+ objlist_append(l, makeClustObs(sg, pm));
}
}
}
* Return appended list, plus pass back last cluster processed in gp.
*/
static void
-raiseLevel(objlist * l, int maxlvl, void *ex, int minlvl, graph_t ** gp,
+raiseLevel(objlist_t *l, int maxlvl, void *ex, int minlvl, graph_t **gp,
expand_t* pm)
{
graph_t *g = *gp;
* Return the list.
* Assume e is not a loop.
*/
-static objlist *objectList(edge_t * ep, expand_t* pm)
-{
+static objlist_t objectList(edge_t *ep, expand_t *pm) {
node_t *h = aghead(ep);
node_t *t = agtail(ep);
graph_t *hg = PARENT(h);
int tlevel;
void *hex; /* Objects to be excluded from list */
void *tex;
- objlist *list = gv_alloc(sizeof(objlist));
+ objlist_t list = {0};
/* If either endpoint is a cluster node, we move up one level */
if (IS_CLUST_NODE(h)) {
hlevel = LEVEL(hg);
tlevel = LEVEL(tg);
if (hlevel > tlevel) {
- raiseLevel(list, hlevel, hex, tlevel, &hg, pm);
+ raiseLevel(&list, hlevel, hex, tlevel, &hg, pm);
hex = hg;
hg = GPARENT(hg);
} else if (tlevel > hlevel) {
- raiseLevel(list, tlevel, tex, hlevel, &tg, pm);
+ raiseLevel(&list, tlevel, tex, hlevel, &tg, pm);
tex = tg;
tg = GPARENT(tg);
}
/* hg and tg always have the same level */
while (hg != tg) {
- addGraphObjs(list, hg, NULL, hex, pm);
- addGraphObjs(list, tg, tex, NULL, pm);
+ addGraphObjs(&list, hg, NULL, hex, pm);
+ addGraphObjs(&list, tg, tex, NULL, pm);
hex = hg;
hg = GPARENT(hg);
tex = tg;
tg = GPARENT(tg);
}
- addGraphObjs(list, tg, tex, hex, pm);
+ addGraphObjs(&list, tg, tex, hex, pm);
return list;
}
if (n == head && ED_count(e)) { /* self arc */
makeSelfArcs(e, GD_nodesep(g));
} else if (ED_count(e)) {
- objlist *objl = objectList(e, pm);
- assert(objl->cnt <= INT_MAX);
- if (Plegal_arrangement(objl->obs, (int)objl->cnt)) {
- vconfig = Pobsopen(objl->obs, (int)objl->cnt);
+ objlist_t objl = objectList(e, pm);
+ assert(objlist_size(&objl) <= INT_MAX);
+ if (Plegal_arrangement(objlist_at(&objl, 0), (int)objlist_size(&objl))) {
+ vconfig = Pobsopen(objlist_at(&objl, 0), (int)objlist_size(&objl));
if (!vconfig) {
agerr(AGWARN, "compoundEdges: could not construct obstacles - falling back to straight line edges\n");
rv = 1;
- freeObjlist(objl);
+ objlist_free(&objl);
continue;
}
}
margin.x, margin.y, pm->x, pm->y);
rv = 1;
}
- freeObjlist(objl);
+ objlist_free(&objl);
continue;
}
*/
for (e0 = e; e0; e0 = ED_to_virt(e0)) {
ED_path(e0) = getPath(e0, vconfig, 0);
- assert(objl->cnt <= INT_MAX);
- makeSpline(e0, objl->obs, (int)objl->cnt, false);
+ assert(objlist_size(&objl) <= INT_MAX);
+ makeSpline(e0, objlist_at(&objl, 0), (int)objlist_size(&objl), false);
}
- freeObjlist(objl);
+ objlist_free(&objl);
}
}
}