Esempio n. 1
0
vertex_t *createvertex (xy_t xy) {
    vertex_t *vmemp, *vp;

    vmemp = vp = NULL;
    if (!(vmemp = vmalloc (vvm, sizeof (vertex_t))))
        goto abortcreatevertex;
    vmemp->xy = xy;
    if (!(vp = dtinsert (vertexdict, vmemp)))
        goto abortcreatevertex;
    if (vp != vmemp) {
        vmfree (vvm, vmemp);
        return vp;
    }
    if (!(vp->edgeps = vmalloc (Vmheap, 4 * sizeof (edge_t *))))
        goto abortcreatevertex;
    vp->edgepn = 4;
    vp->edgepl = 0;
    return vp;

abortcreatevertex:
    SUwarning (
        1, "createvertex", "create failed for vertex (%d,%d)", xy.x, xy.y
    );
    if (vp) {
        if (vp == vmemp)
            dtdelete (vertexdict, vp);
        if (vp->edgeps)
            vmfree (Vmheap, vp->edgeps);
    }
    if (vmemp)
        vmfree (vvm, vmemp);
    return NULL;
}
Esempio n. 2
0
static void vmapAdd(Dt_t * map, int i, int j)
{
    Ipair obj;
    obj.i = i;
    obj.j = j;
    dtinsert(map, &obj);
}
Esempio n. 3
0
/* insertEdge:
 */
static void insertEdge(Dt_t * map, void *t, void *h, edge_t * e)
{
    item dummy;

    dummy.p[0] = t;
    dummy.p[1] = h;
    dummy.t = e->tail;
    dummy.h = e->head;
    dtinsert(map, &dummy);

    dummy.p[0] = h;
    dummy.p[1] = t;
    dummy.t = e->head;
    dummy.h = e->tail;
    dtinsert(map, &dummy);
}
Esempio n. 4
0
/* constrainX:
 * Create the X constrains and solve. We use a linear objective function
 * (absolute values rather than squares), so we can reuse network simplex.
 * The constraints are encoded as a dag with edges having a minimum length.
 */
static void constrainX(graph_t* g, nitem* nlist, int nnodes, intersectfn ifn,
                       int ortho)
{
    Dt_t *list = dtopen(&constr, Dtobag);
    nitem *p = nlist;
    graph_t *cg;
    int i;

    for (i = 0; i < nnodes; i++) {
	p->val = p->pos.x;
	dtinsert(list, p);
	p++;
    }
    if (ortho)
	cg = mkConstraintG(g, list, ifn, distX);
    else
	cg = mkNConstraintG(g, list, ifn, distX);
    rank(cg, 2, INT_MAX);

    p = nlist;
    for (i = 0; i < nnodes; i++) {
	int newpos, oldpos, delta;
	oldpos = p->pos.x;
	newpos = ND_rank(p->cnode);
	delta = newpos - oldpos;
	p->pos.x = newpos;
	p->bb.LL.x += delta;
	p->bb.UR.x += delta;
	p++;
    }

    closeGraph(cg);
    dtclose(list);
}
Esempio n. 5
0
static void update(Dict_t * Q, Agnode_t * dest, Agnode_t * src, double len)
{
    double newlen = getdist(src) + len;
    double oldlen = getdist(dest);

    if (oldlen == 0) {		/* first time to see dest */
	setdist(dest, newlen);
	if (doPath) setprev(dest, src);
	dtinsert(Q, dest);
    } else if (newlen < oldlen) {
	dtdelete(Q, dest);
	setdist(dest, newlen);
	if (doPath) setprev(dest, src);
	dtinsert(Q, dest);
    }
}
Esempio n. 6
0
void add_edge(edgelist * list, Agedge_t * e)
{
    edgelistitem temp;

    temp.edge = e;
    dtinsert(list, &temp);
}
Esempio n. 7
0
void push(queue * nq, void *n)
{
    nsitem obj;

    obj.np = n;
    dtinsert(nq, &obj);
}
Esempio n. 8
0
/* insertEdge:
 */
static void insertEdge(Dt_t * map, void *t, void *h, edge_t * e)
{
    item dummy;

    dummy.p[0] = t;
    dummy.p[1] = h;
    dummy.t = agtail(e);
    dummy.h = aghead(e);
    dtinsert(map, &dummy);

    dummy.p[0] = h;
    dummy.p[1] = t;
    dummy.t = aghead(e);
    dummy.h = agtail(e);
    dtinsert(map, &dummy);
}
static void storeline(GVC_t *gvc, textlabel_t *lp, char *line, char terminator)
{
    pointf size;
    textspan_t *span;
    static textfont_t tf;
    int oldsz = lp->u.txt.nspans + 1;

    lp->u.txt.span = ZALLOC(oldsz + 1, lp->u.txt.span, textspan_t, oldsz);
    span = &(lp->u.txt.span[lp->u.txt.nspans]);
    span->str = line;
    span->just = terminator;
    if (line && line[0]) {
	tf.name = lp->fontname;
	tf.size = lp->fontsize;
	span->font = dtinsert(gvc->textfont_dt, &tf);
        size = textspan_size(gvc, span);
    }
    else {
	size.x = 0.0;
	span->size.y = size.y = (int)(lp->fontsize * LINESPACING);
    }

    lp->u.txt.nspans++;
    /* width = max line width */
    lp->dimen.x = MAX(lp->dimen.x, size.x);
    /* accumulate height */
    lp->dimen.y += size.y;
}
Esempio n. 10
0
/* insertNodeset:
 * Add a node into the nodeset.
 */
void insertNodeset(nodeset_t * ns, Agnode_t * n)
{
    nsitem_t key;

    key.np = n;
    dtinsert(ns, &key);
}
Esempio n. 11
0
poly_t *createpoly (polydata_t *pdp) {
    poly_t *pmemp, *pp;

    pmemp = pp = NULL;
    if (!(pmemp = vmalloc (pvm, sizeof (poly_t))))
        goto abortcreatepoly;
    pmemp->cenid = pdp->cenid;
    pmemp->polyid = pdp->polyid;
    if (!(pp = dtinsert (polydict, pmemp)))
        goto abortcreatepoly;
    if (pp != pmemp) {
        vmfree (pvm, pmemp);
        return pp;
    }
    if (!(pp->edgeps = vmalloc (Vmheap, 4 * sizeof (edge_t *))))
        goto abortcreatepoly;
    pp->edgepn = 4;
    pp->edgepl = 0;
    pp->mark = 0;
    return pp;

abortcreatepoly:
    SUwarning (
        1, "createpoly", "create failed for poly %d/%d", pdp->cenid, pdp->polyid
    );
    if (pp) {
        if (pp == pmemp)
            dtdelete (polydict, pp);
        if (pp->edgeps)
            vmfree (Vmheap, pp->edgeps);
    }
    if (pmemp)
        vmfree (pvm, pmemp);
    return NULL;
}
Esempio n. 12
0
void addPS(PointSet * ps, int x, int y)
{
    point pt;

    pt.x = x;
    pt.y = y;
    dtinsert(ps, mkPair(pt));
}
Esempio n. 13
0
void 
addIntSet (Dt_t* is, int v)
{
    intitem obj;

    obj.id = v;
    dtinsert(is, &obj);
}
Esempio n. 14
0
int
ptdelete(Pt_t* tab, Ptaddr_t min, Ptaddr_t max)
{
	register Ptprefix_t*	xp;
	Ptprefix_t		key;
	Ptprefix_t		cur;

	tab->entries++;
	key.min = min;
	key.max = max;
	if (xp = (Ptprefix_t*)dtsearch(tab->dict, &key))
	{
		do
		{
			cur.min = xp->min;
			cur.max = xp->max;
			dtdelete(tab->dict, xp);
			if (key.min > cur.min)
			{
				max = cur.max;
				cur.max = key.min - 1;
				if (!dtinsert(tab->dict, &cur))
					goto bad;
				if (key.max < max)
				{
					cur.min = key.max + 1;
					cur.max = max;
					if (!dtinsert(tab->dict, &cur))
						goto bad;
					break;
				}
			}
			else if (key.max < xp->max)
			{
				xp->min = key.max + 1;
				if (!dtinsert(tab->dict, xp))
					goto bad;
			}
		} while (xp = (Ptprefix_t*)dtnext(tab->dict, xp));
	}
	return 0;
 bad:
	if (tab->disc->errorf)
		(*tab->disc->errorf)(NiL, tab->disc, ERROR_SYSTEM|2, "out of space");
	return -1;
}
Esempio n. 15
0
void insertPS(PointSet * ps, point pt)
{
    pair *pp;

    pp = mkPair(pt);
    if (dtinsert(ps, pp) != pp)
        free(pp);
}
Esempio n. 16
0
/* insertDeglist:
 * Add a node to the node list.
 * Nodes are kept sorted by DEGREE, smallest degrees first.
 */
void insertDeglist(deglist_t * ns, Agnode_t * n)
{
    degitem key;
    degitem *kp;

    key.deg = DEGREE(n);
    kp = dtinsert(ns, &key);
    ND_next(n) = kp->np;
    kp->np = n;
}
Esempio n. 17
0
static textfont_t *mkFont(GVC_t *gvc, char **atts, int flags, int ul)
{
    textfont_t tf = {NULL,NULL,NULL,0.0,0,0};

    tf.size = -1.0;		/* unassigned */
    tf.flags = flags;
    if (atts)
	doAttrs(&tf, font_items, sizeof(font_items) / ISIZE, atts, "<FONT>");

    return dtinsert(gvc->textfont_dt, &tf);
}
Esempio n. 18
0
void addPS(PointSet * ps, int x, int y)
{
    point pt;
    pair *pp;

    pt.x = x;
    pt.y = y;
    pp = mkPair(pt);
    if (dtinsert(ps, pp) != pp)
        free(pp);
}
Esempio n. 19
0
int insertPM(PointMap * pm, int x, int y, int v)
{
    mpair *p;
    mpair dummy;

    dummy.id.x = x;
    dummy.id.y = y;
    dummy.v = v;
    p = dtinsert(pm, &dummy);
    return p->v;
}
Esempio n. 20
0
static void associate(Agraph_t *model, void *key, rep_t val)
{
	Dict_t		*dict;
	repkey_t	*newelt;

	assert(association(model,key).type == 0);
	dict = repdict(model);
	newelt = NEW(repkey_t);
	newelt->key = key;
	newelt->val = val;
	dtinsert(dict,newelt);
}
Esempio n. 21
0
int
pssttyadd(register Pss_t* pss, const char* name, Pss_dev_t dev)
{
	register Tty_t*	tty;

	if (!dtmatch(pss->ttybyname, name))
	{
		if (!(tty = vmnewof(pss->vm, 0, Tty_t, 1, strlen(name))))
		{
			if (pss->disc->errorf)
				(*pss->disc->errorf)(pss, pss->disc, ERROR_SYSTEM|2, "out of space");
			return -1;
		}
		strcpy(tty->name, name);
		tty->dev = dev;
		dtinsert(pss->ttybyname, tty);
		if (!dtmatch(pss->ttybydev, &dev))
			dtinsert(pss->ttybydev, tty);
	}
	return 0;
}
Esempio n. 22
0
tmain()
{
	Dt_t*	dt;
	Obj_t	*o, proto;
	long	i, k, count, n;

	for(i = 0; i < N_OBJ; i = k)
	{	for(k = i; k < i+R_OBJ && k < N_OBJ; ++k)
		{	Obj[k].key = i;
			Obj[k].ord = k;
		}
	}

	for(k = 0; k < 2; ++k)
	{	if(!(dt = dtopen(&Disc, k == 0 ? Dtrhbag : Dtobag)) )
			terror("Opening dictionary");
		dtcustomize(dt, DT_SHARE, 1); /* turn on sharing */

		for(i = 0; i < N_OBJ; ++i)
		{	if(dtinsert(dt, Obj+i) != Obj+i)
				terror("Insert %d,%d", Obj[i].key, Obj[i].ord);

			if(i > 0 && (i%N_CHK) == 0)
				if((count = dtsize(dt)) != i+1)
					terror("Bad size %d (need %d)", count, i+1);
		}

		count = n = 0; /* count the group of elements with key == 0 */
		for(o = (Obj_t*)dtflatten(dt); o; o = (Obj_t*)dtlink(dt,o), count += 1)
			if(o->key == 0)
				n += 1;
		if(count != N_OBJ || n != R_OBJ)
			terror("flatten %s: count=%d(need=%d) n=%d(need=%d)",
				k == 0 ? "bag" : "obag", count, N_OBJ, n, R_OBJ);

		/* delete a bunch of objects */
		for(n = 0, i = 0; i < N_OBJ; i += R_OBJ, n += 1)
			if(!dtdelete(dt, Obj+i))
				terror("delete %s: i=%d",
					k == 0 ? "bag" : "obag", i);

		count = 0; /* count the left over */
		for(o = (Obj_t*)dtflatten(dt); o; o = (Obj_t*)dtlink(dt,o))
			count += 1;
		if(count != N_OBJ-n)
			terror("%s wrong count %d",
				k == 0 ? "bag" : "obag", count);

		dtclose(dt);
	}

	texit(0);
}
Esempio n. 23
0
File: tvthread.c Progetto: att/ast
tmain() {
    UNUSED(argc);
    UNUSED(argv);
    pthread_t thread[N_THREADS];
    size_t k, p, n;
    Mydisc_t disc[2];
    Obj_t *o, *list[2], obj;

    topts();

    /* create two dictionaries to volley objects back and forth */
    for (n = 0; n < 2; ++n) {
        if (!(Dict[n] = opendictionary(&disc[n]))) terror("Can't open dictionary %d", n);

        /* make objects */
        if (!(list[n] = malloc((N_OBJ / 2) * sizeof(Obj_t)))) terror("malloc failed %d", n);
        memset(list[n], 0, (N_OBJ / 2) * sizeof(Obj_t));

        for (o = list[n], k = 0; k < N_OBJ / 2; ++k, ++o) {
            o->value = n == 0 ? k : k + N_OBJ / 2;

            if (dtinsert(Dict[n], o) != o) terror("Insert failed n=%d k=%d", n, k);
            if (dtsearch(Dict[n], o) != o) { /* verify insert succeeded */
                terror("Search failed n=%d k=%d", n, k);
            }

            o->ins[n] += 1;
        }
    }

    for (p = 0; p < N_THREADS; ++p) pthread_create(&thread[p], 0, volley, (void *)((long)(p % 2)));

    for (p = 0; p < N_THREADS; ++p) pthread_join(thread[p], 0);

    tinfo("\tCheck integrity");
    n = dtsize(Dict[0]);
    p = dtsize(Dict[1]);
    tinfo("Dict[0]=%d Dict[1]=%d", n, p);
    if ((n + p) != N_OBJ) {
        for (k = 0; k < N_OBJ; ++k) {
            obj.value = k;
            if ((o = dtsearch(Dict[0], &obj))) continue;
            if ((o = dtsearch(Dict[1], &obj))) continue;
            terror("%d not found", k);
            dtsearch(Dict[0], &obj);
            dtsearch(Dict[1], &obj);
        }

        terror("Expecting %d objects but got (Dict[0]=%d + Dict[1]=%d) = %d", N_OBJ, n, p, n + p);
    }

    texit(0);
}
Esempio n. 24
0
File: tqueue.c Progetto: att/ast
tmain() {
    UNUSED(argc);
    UNUSED(argv);
    Dt_t *dt;

    /* testing Dtqueue */
    if (!(dt = dtopen(&Disc, Dtqueue))) terror("dtopen queue");
    if ((long)dtinsert(dt, 1L) != 1) terror("Dtqueue insert 1");
    if ((long)dtinsert(dt, 3L) != 3) terror("Dtqueue insert 3.1");
    if ((long)dtinsert(dt, 2L) != 2) terror("Dtqueue insert 2.1");
    if ((long)dtinsert(dt, 3L) != 3) terror("Dtqueue insert 3.2");
    if ((long)dtinsert(dt, 2L) != 2) terror("Dtqueue insert 2.2");
    if ((long)dtinsert(dt, 3L) != 3) terror("Dtqueue insert 3.3");

    if ((long)dtlast(dt) != 3) terror("Dtqueue dtlast");
    if ((long)dtprev(dt, 3L) != 2) terror("Dtqueue dtprev 3.3");
    if ((long)dtprev(dt, 2L) != 3) terror("Dtqueue dtprev 2.2");
    if ((long)dtprev(dt, 3L) != 2) terror("Dtqueue dtprev 3.2");
    if ((long)dtprev(dt, 2L) != 3) terror("Dtqueue dtprev 2.1");
    if ((long)dtprev(dt, 3L) != 1) terror("Dtqueue dtprev 3.1");
    if ((long)dtprev(dt, 1L) != 0) terror("Dtqueue dtprev 1");

    if ((long)dtdelete(dt, NULL) != 1) terror("Dtqueue pop 1");
    if ((long)dtdelete(dt, NULL) != 3) terror("Dtqueue delete 3.1");
    if ((long)dtdelete(dt, NULL) != 2) terror("Dtqueue delete 2");
    if ((long)dtdelete(dt, NULL) != 3) terror("Dtqueue delete 3.2");
    if ((long)dtdelete(dt, NULL) != 2) terror("Dtqueue delete 2.1");
    if ((long)dtdelete(dt, NULL) != 3) terror("Dtqueue delete 3.3");

    if (dtsize(dt) != 0) terror("Dtqueue size");

    texit(0);
}
Esempio n. 25
0
/* addGrid:
 * Add node n to cell (i,j) in grid g.
 */
void addGrid(Grid * g, int i, int j, Agnode_t * n)
{
    cell *cellp;
    cell key;

    key.p.i = i;
    key.p.j = j;
    cellp = dtinsert(g->data, &key);
    cellp->nodes = newNode(g, n, cellp->nodes);
    if (Verbose >= 3) {
	fprintf(stderr, "grid(%d,%d): %s\n", i, j, agnameof(n));
    }
}
Esempio n. 26
0
/* constrainY:
 * See constrainX.
 */
static void constrainY(graph_t* g, nitem* nlist, int nnodes, intersectfn ifn,
                       int ortho)
{
    Dt_t *list = dtopen(&constr, Dtobag);
    nitem *p = nlist;
    graph_t *cg;
    int i;

    for (i = 0; i < nnodes; i++) {
	p->val = p->pos.y;
	dtinsert(list, p);
	p++;
    }
    if (ortho)
	cg = mkConstraintG(g, list, ifn, distY);
    else
	cg = mkNConstraintG(g, list, ifn, distY);
    rank(cg, 2, INT_MAX);
#ifdef DEBUG
    {
	Agsym_t *mlsym = agedgeattr(cg, "minlen", "");
	Agsym_t *rksym = agnodeattr(cg, "rank", "");
	char buf[100];
	node_t *n;
	edge_t *e;
	for (n = agfstnode(cg); n; n = agnxtnode(cg, n)) {
	    sprintf(buf, "%d", ND_rank(n));
	    agxset(n, rksym->index, buf);
	    for (e = agfstedge(cg, n); e; e = agnxtedge(cg, e, n)) {
		sprintf(buf, "%d", ED_minlen(e));
		agxset(e, mlsym->index, buf);
	    }
	}
    }
#endif

    p = nlist;
    for (i = 0; i < nnodes; i++) {
	int newpos, oldpos, delta;
	oldpos = p->pos.y;
	newpos = ND_rank(p->cnode);
	delta = newpos - oldpos;
	p->pos.y = newpos;
	p->bb.LL.y += delta;
	p->bb.UR.y += delta;
	p++;
    }

    closeGraph(cg);
    dtclose(list);
}
Esempio n. 27
0
tmain()
{
	Dt_t*		dt;

	/* testing Dtstack */
	if(!(dt = dtopen(&Disc,Dtstack)) )
		terror("dtopen stack");
	if((long)dtinsert(dt,1L) != 1)
		terror("Dtstack insert 1");
	if((long)dtinsert(dt,3L) != 3)
		terror("Dtstack insert 3.1");
	if((long)dtinsert(dt,2L) != 2)
		terror("Dtstack insert 2.1");
	if((long)dtinsert(dt,3L) != 3)
		terror("Dtstack insert 3.2");
	if((long)dtinsert(dt,2L) != 2)
		terror("Dtstack insert 2.2");
	if((long)dtinsert(dt,3L) != 3)
		terror("Dtstack insert 3.3");

	if((long)dtlast(dt) != 1)
		terror("Dtstack dtlast");
	if((long)dtprev(dt,1L) != 3)
		terror("Dtstack dtprev 1");
	if((long)dtprev(dt,3L) != 2)
		terror("Dtstack dtprev 3.1");
	if((long)dtprev(dt,2L) != 3)
		terror("Dtstack dtprev 2.1");
	if((long)dtprev(dt,3L) != 2)
		terror("Dtstack dtprev 3.2");
	if((long)dtprev(dt,2L) != 3)
		terror("Dtstack dtprev 2.2");
	if((long)dtprev(dt,3L) != 0)
		terror("Dtstack dtprev 3.2");

	if((long)dtdelete(dt,NIL(Void_t*)) != 3)
		terror("Dtstack pop 3.3");

	/* search to one of the 3 */
	if((long)dtsearch(dt,3L) != 3)
		terror("Dtstack search 3.2");
	if((long)dtdelete(dt,3L) != 3)
		terror("Dtstack delete 3.2");

	if((long)dtdelete(dt,NIL(Void_t*)) != 2)
		terror("Dtstack pop 2.2");
	if((long)dtdelete(dt,NIL(Void_t*)) != 2)
		terror("Dtstack pop 2.1");
	if((long)dtdelete(dt,NIL(Void_t*)) != 3)
		terror("Dtstack pop 3.1");
	if((long)dtdelete(dt,NIL(Void_t*)) != 1)
		terror("Dtstack pop 1");

	if(dtsize(dt) != 0)
		terror("Dtstack size");

	texit(0);
}
Esempio n. 28
0
int updatePM(PointMap * pm, int x, int y, int v)
{
    mpair *p;
    mpair dummy;
    int old;

    dummy.id.x = x;
    dummy.id.y = y;
    dummy.v = v;
    p = dtinsert(pm, &dummy);
    old = p->v;
    p->v = v;
    return old;
}
Esempio n. 29
0
static void insert (Dt_t* map, char* name, int v)
{
    intm* ip = (intm*)dtmatch(map, name);    

    if (ip) {
	if (ip->v != v)
	    agerr(AGWARN, "Duplicate cluster name \"%s\"\n", name);
	return;
    }
    ip = NEW(intm);
    ip->id = strdup(name);
    ip->v = v;
    dtinsert (map, ip);
}
Esempio n. 30
0
void Grid::add(int i, int j, FDPModel::Node *n) {
    Cell *cellp;
    Cell key;

    key.p.i = i;
    key.p.j = j;
    cellp = reinterpret_cast<Cell*>(dtinsert(this, &key));
    cellp->nodes.push_front(n);
	/*
    if(Verbose >= 3) {
      fprintf(stderr, "grid(%d,%d): %s\n", i, j, n->name);
    }
	*/
}