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 | |
18 | static 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 | |
26 | static void freeItem(Dt_t * d, edgelistitem * obj, Dtdisc_t * disc) |
27 | { |
28 | free(obj); |
29 | } |
30 | |
31 | static int |
32 | cmpItem(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 | |
42 | static 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 | |
54 | edgelist *init_edgelist() |
55 | { |
56 | edgelist *list = dtopen(&ELDisc, Dtoset); |
57 | return list; |
58 | } |
59 | |
60 | void free_edgelist(edgelist * list) |
61 | { |
62 | dtclose(list); |
63 | } |
64 | |
65 | void add_edge(edgelist * list, Agedge_t * e) |
66 | { |
67 | edgelistitem temp; |
68 | |
69 | temp.edge = e; |
70 | dtinsert(list, &temp); |
71 | } |
72 | |
73 | void 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 |
82 | void 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 | |
97 | int size_edgelist(edgelist * list) |
98 | { |
99 | return dtsize(list); |
100 | } |
101 | |