Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
edgelist.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include <circogen/edgelist.h>
12#include <assert.h>
13#include <util/alloc.h>
14
15static void *mkItem(void *p, Dtdisc_t *disc) {
16 (void)disc;
17 edgelistitem *obj = p;
18
19 edgelistitem *ap = gv_alloc(sizeof(edgelistitem));
20
21 ap->edge = obj->edge;
22 return ap;
23}
24
25static int cmpItem(void *k1, void *k2) {
26 const Agedge_t **key1 = k1;
27 const Agedge_t **key2 = k2;
28 if (*key1 > *key2) {
29 return 1;
30 }
31 if (*key1 < *key2) {
32 return -1;
33 }
34 return 0;
35}
36
37static Dtdisc_t ELDisc = {
38 offsetof(edgelistitem, edge), /* key */
39 sizeof(Agedge_t *), /* size */
40 offsetof(edgelistitem, link), /* link */
41 mkItem,
42 free,
43 cmpItem,
44};
45
47{
48 edgelist *list = dtopen(&ELDisc, Dtoset);
49 return list;
50}
51
53{
54 dtclose(list);
55}
56
57void add_edge(edgelist * list, Agedge_t * e)
58{
59 edgelistitem temp;
60
61 temp.edge = e;
62 dtinsert(list, &temp);
63}
64
65void remove_edge(edgelist * list, Agedge_t * e)
66{
67 edgelistitem temp;
68
69 temp.edge = e;
70 dtdelete(list, &temp);
71}
72
73#ifdef DEBUG
74void print_edge(edgelist * list)
75{
76 edgelistitem *temp;
77 Agedge_t *ep;
78
79 for (temp = (edgelistitem *) dtflatten(list); temp;
80 temp = (edgelistitem *)dtlink(list, temp)) {
81 ep = temp->edge;
82 fprintf(stderr, "%s--", agnameof(agtail(ep)));
83 fprintf(stderr, "%s \n", agnameof(aghead(ep)));
84 }
85 fputs("\n", stderr);
86}
87#endif
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
Definition alloc.h:47
CDT_API Dtlink_t * dtflatten(Dt_t *)
Definition dtflatten.c:10
#define dtlink(d, e)
Definition cdt.h:175
#define dtinsert(d, o)
Definition cdt.h:185
CDT_API int dtclose(Dt_t *)
Definition dtclose.c:8
CDT_API Dtmethod_t * Dtoset
ordered set (self-adjusting tree)
Definition dttree.c:304
#define dtdelete(d, o)
Definition cdt.h:186
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
Definition dtopen.c:9
void add_edge(edgelist *list, Agedge_t *e)
Definition edgelist.c:57
edgelist * init_edgelist(void)
Definition edgelist.c:46
void free_edgelist(edgelist *list)
Definition edgelist.c:52
static void * mkItem(void *p, Dtdisc_t *disc)
Definition edgelist.c:15
static int cmpItem(void *k1, void *k2)
Definition edgelist.c:25
void remove_edge(edgelist *list, Agedge_t *e)
Definition edgelist.c:65
static Dtdisc_t ELDisc
Definition edgelist.c:37
static Dtdisc_t disc
Definition exparse.y:209
void free(void *)
edge
Definition gmlparse.y:240
#define agtail(e)
Definition cgraph.h:880
#define aghead(e)
Definition cgraph.h:881
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:158
Definition cdt.h:100
Agedge_t * edge
Definition edgelist.h:21