26bed1c39c3bf189e69cf7f23c3b9f9f95a2cc85
[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 #ifdef _NO_GC
29
30 #define GC_malloc malloc
31 #define GC_free free
32 #define GC_realloc realloc
33
34 #else
35
36 #include "./gc/gc.h" 
37
38 #endif
39
40 #ifndef ALLOC
41
42 #define  ALLOC(x,sz) if (!(x = GC_malloc(sz)))                          \
43          {                                                           \
44             fprintf(stderr,"out of virtual memory %s , %d",__FILE__,__LINE__);\
45             exit (1);                                                \
46          }
47
48 #endif
49
50 #ifndef THROWS
51 #define THROWS
52 #define THROW_NONE  0 
53 #define THROW_SRC   1 
54 #define THROW_DEST  2
55 #define THROW_BOTH  3
56 #endif
57
58 /* linear linked list generic */
59 typedef struct set
60 {
61     void    *item ;
62     struct  set *curr ;
63     struct  set *next ;
64 } set ;
65
66 #define DEFSETFUNC(fname)  int fname ( void *item, va_list ap)
67 #define V_ARG(type,var) type var = va_arg(ap,type) 
68
69 /* set related functions */
70 void          *addSet             ( set  ** , void   *         );
71 void          *addSetHead         ( set  ** , void   *         );
72 void          *getSet             ( set  ** );
73 void          deleteSetItem       ( set  ** , void * );
74 void          deleteItemIf        ( set  ** , int (*cond) (void *, va_list), ... );
75 int            isinSet            ( set  * , void * );
76 int            isinSetWith        ( set  *,  void *, int (*cfunc)());
77 int           applyToSet          ( set  *list ,int (*somefunc)(void *,va_list), ...);
78 int           applyToSetFTrue     ( set  *list ,int (*somefunc)(void *,va_list), ...);
79 set         *unionSets           ( set *, set *, int);
80 set         *unionSetsWith       ( set *, set *, int (*cFunc)(),int);
81 set         *intersectSets       ( set *, set *, int);
82 void          *addSetIfnotP       ( set **, void *);
83 set         *setFromSet        ( set * );
84 int           isSetsEqual        ( set *, set *);
85 set         *subtractFromSet     ( set *, set *,int);
86 int          elementsInSet       (set *);
87 set         *intersectSetsWith (set *, set *,int (*cFunc)(),int );
88 int         isSetsEqualWith    ( set *, set *, int (*cFunc)());
89 void        *peekSet           ( set *);
90 void        *setFirstItem      ( set *);
91 void        *setNextItem       ( set *);
92 void         setToNull         (void ** );
93
94
95 #endif