Graphviz  2.41.20171026.1811
edgelist.c
Go to the documentation of this file.
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 {
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 
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 
98 {
99  return dtsize(list);
100 }
int(* Dtcompar_f)(Dt_t *, void *, void *, Dtdisc_t *)
Definition: cdt.h:40
unsigned int(* Dthash_f)(Dt_t *, void *, Dtdisc_t *)
Definition: cdt.h:41
CDT_API int dtclose(Dt_t *)
void *(* Dtmake_f)(Dt_t *, void *, Dtdisc_t *)
Definition: cdt.h:38
CDT_API Dtlink_t * dtflatten(Dt_t *)
Definition: dtflatten.c:9
CDT_API Dtmethod_t * Dtoset
Definition: cdt.h:166
#define dtdelete(d, o)
Definition: cdt.h:264
Definition: cdt.h:80
Agedge_t * edge
Definition: edgelist.h:25
void add_edge(edgelist *list, Agedge_t *e)
Definition: edgelist.c:65
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
Definition: dtopen.c:9
int size_edgelist(edgelist *list)
Definition: edgelist.c:97
CGRAPH_API Agnode_t * agtail(Agedge_t *e)
Definition: edge.c:525
void remove_edge(edgelist *list, Agedge_t *e)
Definition: edgelist.c:73
CGRAPH_API Agnode_t * aghead(Agedge_t *e)
Definition: edge.c:533
void free_edgelist(edgelist *list)
Definition: edgelist.c:60
CGRAPH_API char * agnameof(void *)
Definition: id.c:143
void *(* Dtmemory_f)(Dt_t *, void *, size_t, Dtdisc_t *)
Definition: cdt.h:36
CDT_API int dtsize(Dt_t *)
Definition: dtsize.c:12
#define dtinsert(d, o)
Definition: cdt.h:262
#define GNEW(t)
Definition: memory.h:37
int(* Dtevent_f)(Dt_t *, int, void *, Dtdisc_t *)
Definition: cdt.h:42
void(* Dtfree_f)(Dt_t *, void *, Dtdisc_t *)
Definition: cdt.h:39
Definition: cdt.h:99
#define dtlink(d, e)
Definition: cdt.h:250
edgelist * init_edgelist()
Definition: edgelist.c:54
Agedge_t * edge(Agraph_t *g, Agnode_t *t, Agnode_t *h)
Definition: gv.cpp:110