1/* $Id$ $Revision$ */
2/* vim:set shiftwidth=4 ts=8: */
3
4/*************************************************************************
5 * Copyright (c) 2011 AT&T Intellectual Property
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors: See CVS logs. Details at http://www.graphviz.org/
12 *************************************************************************/
13
14
15#include "edgelist.h"
16#include <assert.h>
17
18static edgelistitem *mkItem(Dt_t * d, edgelistitem * obj, Dtdisc_t * disc)
19{
20 edgelistitem *ap = GNEW(edgelistitem);
21
22 ap->edge = obj->edge;
23 return ap;
24}
25
26static void freeItem(Dt_t * d, edgelistitem * obj, Dtdisc_t * disc)
27{
28 free(obj);
29}
30
31static int
32cmpItem(Dt_t * d, Agedge_t ** key1, Agedge_t ** key2, Dtdisc_t * disc)
33{
34 if (*key1 > *key2)
35 return 1;
36 else if (*key1 < *key2)
37 return -1;
38 else
39 return 0;
40}
41
42static Dtdisc_t ELDisc = {
43 offsetof(edgelistitem, edge), /* key */
44 sizeof(Agedge_t *), /* size */
45 offsetof(edgelistitem, link), /* link */
46 (Dtmake_f) mkItem,
47 (Dtfree_f) freeItem,
48 (Dtcompar_f) cmpItem,
49 (Dthash_f) 0,
50 (Dtmemory_f) 0,
51 (Dtevent_f) 0
52};
53
54edgelist *init_edgelist()
55{
56 edgelist *list = dtopen(&ELDisc, Dtoset);
57 return list;
58}
59
60void free_edgelist(edgelist * list)
61{
62 dtclose(list);
63}
64
65void add_edge(edgelist * list, Agedge_t * e)
66{
67 edgelistitem temp;
68
69 temp.edge = e;
70 dtinsert(list, &temp);
71}
72
73void remove_edge(edgelist * list, Agedge_t * e)
74{
75 edgelistitem temp;
76
77 temp.edge = e;
78 dtdelete(list, &temp);
79}
80
81#ifdef DEBUG
82void print_edge(edgelist * list)
83{
84 edgelistitem *temp;
85 Agedge_t *ep;
86
87 for (temp = (edgelistitem *) dtflatten(list); temp;
88 temp = (edgelistitem *) dtlink(list, (Dtlink_t *) temp)) {
89 ep = temp->edge;
90 fprintf(stderr, "%s--", agnameof(agtail(ep)));
91 fprintf(stderr, "%s \n", agnameof(aghead(ep)));
92 }
93 fputs("\n", stderr);
94}
95#endif
96
97int size_edgelist(edgelist * list)
98{
99 return dtsize(list);
100}
101