Graphviz  2.41.20171026.1811
intset.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 #include "config.h"
15 
16 #include <stddef.h>
17 #include <intset.h>
18 #include <memory.h>
19 
20 static void*
21 mkIntItem(Dt_t* d,intitem* obj,Dtdisc_t* disc)
22 {
23  intitem* np = NEW(intitem);
24  np->id = obj->id;
25  return (void*)np;
26 }
27 
28 static void
29 freeIntItem(Dt_t* d,intitem* obj,Dtdisc_t* disc)
30 {
31  free (obj);
32 }
33 
34 static int
35 cmpid(Dt_t* d, int* key1, int* key2, Dtdisc_t* disc)
36 {
37  if (*key1 > *key2) return 1;
38  else if (*key1 < *key2) return -1;
39  else return 0;
40 }
41 
42 static Dtdisc_t intSetDisc = {
43  offsetof(intitem,id),
44  sizeof(int),
45  offsetof(intitem,link),
46  (Dtmake_f)mkIntItem,
47  (Dtfree_f)freeIntItem,
48  (Dtcompar_f)cmpid,
49  0,
50  0,
51  0
52 };
53 
54 Dt_t*
55 openIntSet (void)
56 {
57  return dtopen(&intSetDisc,Dtoset);
58 }
59 
60 void
61 addIntSet (Dt_t* is, int v)
62 {
63  intitem obj;
64 
65  obj.id = v;
66  dtinsert(is, &obj);
67 }
68 
69 int
70 inIntSet (Dt_t* is, int v)
71 {
72  return (dtmatch (is, &v) != 0);
73 }
74 
int(* Dtcompar_f)(Dt_t *, void *, void *, Dtdisc_t *)
Definition: cdt.h:40
void *(* Dtmake_f)(Dt_t *, void *, Dtdisc_t *)
Definition: cdt.h:38
CDT_API Dtmethod_t * Dtoset
Definition: cdt.h:166
Definition: cdt.h:80
int id
Definition: intset.h:20
Definition: intset.h:19
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
Definition: dtopen.c:9
int
Definition: grammar.c:1264
#define dtmatch(d, o)
Definition: cdt.h:261
int inIntSet(Dt_t *is, int v)
Definition: intset.c:70
#define dtinsert(d, o)
Definition: cdt.h:262
void(* Dtfree_f)(Dt_t *, void *, Dtdisc_t *)
Definition: cdt.h:39
Definition: cdt.h:99
Dt_t * openIntSet(void)
Definition: intset.c:55
void addIntSet(Dt_t *is, int v)
Definition: intset.c:61
#define NEW(t)
Definition: memory.h:35