ea503e5738fc795e50df908d012cf233402a9f97
[fw/sdcc] / src / SDCCset.h
1 /*-----------------------------------------------------------------
2     SDCCset.h - contains support routines for sets .
3
4     Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998)
5
6     This program is free software; you can redistribute it and/or modify it
7     under the terms of the GNU General Public License as published by the
8     Free Software Foundation; either version 2, or (at your option) any
9     later version.
10     
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15     
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19     
20     In other words, you are welcome to use, share and improve this program.
21     You are forbidden to forbid anyone else to use, share and improve
22     what you give them.   Help stamp out software-hoarding!  
23 -------------------------------------------------------------------------*/
24
25 #ifndef SDCCSET_H
26 #define SDCCSET_H
27 #include <stdarg.h>
28
29 #if defined(_MSC_VER)
30 #include "sdcc_vc.h"
31 #else
32 #include "sdccconf.h"
33 #endif // _MSC_VER
34
35
36 #ifndef THROWS
37 #define THROWS
38 #define THROW_NONE  0
39 #define THROW_SRC   1
40 #define THROW_DEST  2
41 #define THROW_BOTH  3
42 #endif
43
44 /* linear linked list generic */
45 typedef struct set
46   {
47     void *item;
48     struct set *curr;
49     struct set *next;
50   }
51 set;
52
53 #define DEFSETFUNC(fname)  int fname ( void *item, va_list ap)
54 #define V_ARG(type,var) type var = va_arg(ap,type)
55
56 /* set related functions */
57 set *newSet (void);
58 void *addSet (set **, void *);
59 void *addSetHead (set **, void *);
60 void *getSet (set **);
61 void deleteSetItem (set **, void *);
62 void deleteItemIf (set **, int (*cond) (void *, va_list),...);
63 int isinSet (set *, void *);
64 typedef int (* insetwithFunc) (void *, void *);
65 int isinSetWith (set *, void *, insetwithFunc cfunc);
66 int applyToSet (set * list, int (*somefunc) (void *, va_list),...);
67 int applyToSetFTrue (set * list, int (*somefunc) (void *, va_list),...);
68 set *unionSets (set *, set *, int);
69 set *unionSetsWith (set *, set *, int (*cFunc) (), int);
70 set *intersectSets (set *, set *, int);
71 void *addSetIfnotP (set **, void *);
72 set *setFromSet (set *);
73 int isSetsEqual (set *, set *);
74 set *subtractFromSet (set *, set *, int);
75 int elementsInSet (set *);
76 set *intersectSetsWith (set *, set *, int (*cFunc) (void *, void *), int);
77 int isSetsEqualWith (set *, set *, int (*cFunc) (void *, void *));
78 void *peekSet (set *);
79 void *setFirstItem (set *);
80 void *setNextItem (set *);
81 void setToNull (void **);
82 set *reverseSet (set *);
83 void deleteSet(set **s);
84
85 #endif