/[bison]/bison/lib/bbitset.h
ViewVC logotype

Diff of /bison/lib/bbitset.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by eggert, Mon Aug 12 14:13:56 2002 UTC revision 1.5 by akim, Mon Sep 30 12:50:49 2002 UTC
# Line 26  Foundation, Inc., 59 Temple Place - Suit Line 26  Foundation, Inc., 59 Temple Place - Suit
26  #endif  #endif
27    
28  /* Currently we support three flavours of bitsets:  /* Currently we support three flavours of bitsets:
29     BITSET_ARRAY:  Array of bits (fixed size, faster).     BITSET_ARRAY:  Array of bits (fixed size, fast for dense bitsets).
30     BITSET_LIST:   Linked list of array of bits (variable size, least storage     BITSET_LIST:   Linked list of array of bits (variable size, least storage
31     for large very sparse sets).                    for large very sparse sets).
32     BITSET_TABLE:  Expandable table of pointers to array of bits     BITSET_TABLE:  Expandable table of pointers to array of bits
33     (variable size, less storage for large sparse sets).                    (variable size, less storage for large sparse sets).
34    
35     BITSET_STATS:  Wrapper bitset for internal use only.     BITSET_STATS:  Wrapper bitset for internal use only.
36  */  */
# Line 38  enum bitset_type {BITSET_ARRAY, BITSET_L Line 38  enum bitset_type {BITSET_ARRAY, BITSET_L
38                    BITSET_STATS};                    BITSET_STATS};
39  #define BITSET_TYPE_NAMES {"abitset", "lbitset", "ebitset"}  #define BITSET_TYPE_NAMES {"abitset", "lbitset", "ebitset"}
40    
41    extern const char * const bitset_type_names[];
42    
43  enum bitset_alloc_type {BITSET_MALLOC, BITSET_OBALLOC};  enum bitset_alloc_type {BITSET_MALLOC, BITSET_OBALLOC};
44    
45  /* Non-zero to use inline functions instead of macros.  */  /* Non-zero to use inline functions instead of macros.  */
# Line 68  enum bitset_ops {BITSET_OP_ZERO, BITSET_ Line 70  enum bitset_ops {BITSET_OP_ZERO, BITSET_
70                   BITSET_OP_AND, BITSET_OP_OR, BITSET_OP_XOR, BITSET_OP_ANDN,                   BITSET_OP_AND, BITSET_OP_OR, BITSET_OP_XOR, BITSET_OP_ANDN,
71                   BITSET_OP_OR_AND, BITSET_OP_AND_OR, BITSET_OP_ANDN_OR};                   BITSET_OP_OR_AND, BITSET_OP_AND_OR, BITSET_OP_ANDN_OR};
72    
73    struct bbitset_struct
74    {
75      const struct bitset_vtable * vtable;
76      bitset_windex cindex;         /* Cache word index.  */
77      bitset_windex csize;          /* Cache size in words.  */
78      bitset_word *cdata;           /* Cache data pointer.  */
79      /* Perhaps we could sacrifice another word to indicate
80         that the bitset is known to be zero, that a bit has been set
81         in the cache, and that a bit has been cleared in the cache.
82         This would speed up some of the searches but slightly slow down
83         bit set/reset operations of cached bits.  */
84    };
85    
86    
87    typedef struct bitset_struct *bitset;
88    
89    
90    /* The contents of this structure should be considered private.  */
91    struct bitset_vtable
92    {
93      void (*set) PARAMS ((struct bitset_struct *, bitset_bindex));
94      void (*reset) PARAMS ((struct bitset_struct *, bitset_bindex));
95      int (*toggle) PARAMS ((struct bitset_struct *, bitset_bindex));
96      int (*test) PARAMS ((struct bitset_struct *, bitset_bindex));
97      int (*size) PARAMS ((struct bitset_struct *));
98      int (*count) PARAMS ((struct bitset_struct *));
99    
100      int (*empty_p) PARAMS ((struct bitset_struct *));
101      void (*ones) PARAMS ((struct bitset_struct *));
102      void (*zero) PARAMS ((struct bitset_struct *));
103    
104      void (*copy) PARAMS ((struct bitset_struct *, struct bitset_struct *));
105      int (*disjoint_p) PARAMS ((struct bitset_struct *, struct bitset_struct *));
106      int (*equal_p) PARAMS ((struct bitset_struct *, struct bitset_struct *));
107      void (*not) PARAMS ((struct bitset_struct *, struct bitset_struct *));
108      int (*subset_p) PARAMS ((struct bitset_struct *, struct bitset_struct *));
109    
110      void (*and) PARAMS ((struct bitset_struct *, struct bitset_struct *,
111                           struct bitset_struct *));
112      int (*and_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
113                              struct bitset_struct *));
114      void (*andn) PARAMS ((struct bitset_struct *, struct bitset_struct *,
115                           struct bitset_struct *));
116      int (*andn_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
117                               struct bitset_struct *));
118      void (*or) PARAMS ((struct bitset_struct *, struct bitset_struct *,
119                          struct bitset_struct *));
120      int (*or_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
121                             struct bitset_struct *));
122      void (*xor) PARAMS ((struct bitset_struct *, struct bitset_struct *,
123                          struct bitset_struct *));
124      int (*xor_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
125                              struct bitset_struct *));
126    
127      void (*and_or) PARAMS ((struct bitset_struct *, struct bitset_struct *,
128                              struct bitset_struct *, struct bitset_struct *));
129      int (*and_or_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
130                             struct bitset_struct *, struct bitset_struct *));
131      void (*andn_or) PARAMS ((struct bitset_struct *, struct bitset_struct *,
132                              struct bitset_struct *, struct bitset_struct *));
133      int (*andn_or_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
134                                  struct bitset_struct *, struct bitset_struct *));
135      void (*or_and) PARAMS ((struct bitset_struct *, struct bitset_struct *,
136                              struct bitset_struct *, struct bitset_struct *));
137      int (*or_and_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
138                                 struct bitset_struct *, struct bitset_struct *));
139    
140      int (*list) PARAMS ((struct bitset_struct *, bitset_bindex *,
141                           bitset_bindex, bitset_bindex *));
142      int (*list_reverse) PARAMS ((struct bitset_struct *, bitset_bindex *,
143                                   bitset_bindex, bitset_bindex *));
144      void (*free) PARAMS ((struct bitset_struct *));
145      enum bitset_type type;
146    };
147    
148    #define BITSET_COMPATIBLE_(BSET1, BSET2) ((BSET1)->b.vtable == (BSET2)->b.vtable)
149    
150    #define BITSET_CHECK2_(DST, SRC) \
151    if (!BITSET_COMPATIBLE_ (DST, SRC)) abort ();
152    
153    #define BITSET_CHECK3_(DST, SRC1, SRC2) \
154    if (!BITSET_COMPATIBLE_ (DST, SRC1) \
155        || !BITSET_COMPATIBLE_ (DST, SRC2)) abort ();
156    
157    #define BITSET_CHECK4_(DST, SRC1, SRC2, SRC3) \
158    if (!BITSET_COMPATIBLE_ (DST, SRC1) || !BITSET_COMPATIBLE_ (DST, SRC2) \
159        || !BITSET_COMPATIBLE_ (DST, SRC3)) abort ();
160    
161    
162  /* Return size in bits of bitset SRC.  */  /* Return size in bits of bitset SRC.  */
163  #define BITSET_SIZE_(SRC) (SRC)->b.ops->size (SRC)  #define BITSET_SIZE_(SRC) (SRC)->b.vtable->size (SRC)
164    
165    /* Return number of bits set in bitset SRC.  */
166    #define BITSET_COUNT_(SRC) (SRC)->b.vtable->count (SRC)
167    
168  /* Return type of bitset SRC.  */  /* Return type of bitset SRC.  */
169  #define BITSET_TYPE_(DST) (DST)->b.ops->type  #define BITSET_TYPE_(DST) (DST)->b.vtable->type
170    
171  /* Set bit BITNO in bitset DST.  */  /* Set bit BITNO in bitset DST.  */
172  #define BITSET_SET_(DST, BITNO) (DST)->b.ops->set (DST, BITNO)  #define BITSET_SET_(DST, BITNO) (DST)->b.vtable->set (DST, BITNO)
173    
174  /* Reset bit BITNO in bitset DST.  */  /* Reset bit BITNO in bitset DST.  */
175  #define BITSET_RESET_(DST, BITNO) (DST)->b.ops->reset (DST, BITNO)  #define BITSET_RESET_(DST, BITNO) (DST)->b.vtable->reset (DST, BITNO)
176    
177    /* Toggle bit BITNO in bitset DST.  */
178    #define BITSET_TOGGLE_(DST, BITNO) (DST)->b.vtable->toggle (DST, BITNO)
179    
180  /* Return non-zero if bit BITNO in bitset SRC is set.  */  /* Return non-zero if bit BITNO in bitset SRC is set.  */
181  #define BITSET_TEST_(SRC, BITNO) (SRC)->b.ops->test (SRC, BITNO)  #define BITSET_TEST_(SRC, BITNO) (SRC)->b.vtable->test (SRC, BITNO)
182    
183  /* Free bitset SRC.  */  /* Free bitset SRC.  */
184  #define BITSET_FREE_(SRC)\  #define BITSET_FREE_(SRC)\
185   ((SRC)->b.ops->free ? (SRC)->b.ops->free (SRC) :(void)0)   ((SRC)->b.vtable->free ? (SRC)->b.vtable->free (SRC) :(void)0)
   
 /* Perform operation OP on DST.  */  
 #define BITSET_OP1_(DST, OP) (DST)->b.ops->op1 (DST, OP)  
186    
 /* Perform operation OP on SRC and store in DST.  */  
 #define BITSET_OP2_(DST, SRC, OP) (DST)->b.ops->op2 (DST, SRC, OP)  
187    
188  /* DST = SRC1 OP SRC2.  */  /* Return SRC == 0.  */
189  #define BITSET_OP3_(DST, SRC1, SRC2, OP) \  #define BITSET_EMPTY_P_(SRC) (SRC)->b.vtable->empty_p (SRC)
 (DST)->b.ops->op3 (DST, SRC1, SRC2, OP)  
190    
191  /* DST = (SRC1 OP1 SRC2) OP2 SRC3.  */  /* DST = ~0.  */
192  #define BITSET_OP4_(DST, SRC1, SRC2, SRC3, OP) \  #define BITSET_ONES_(DST) (DST)->b.vtable->ones (DST)
 (DST)->b.ops->op4 (DST, SRC1, SRC2, SRC3, OP)  
193    
194  /* DST = 0.  */  /* DST = 0.  */
195  #define BITSET_ZERO_(DST) BITSET_OP1_ (DST, BITSET_OP_ZERO);  #define BITSET_ZERO_(DST) (DST)->b.vtable->zero (DST)
196    
 /* DST = ~0.  */  
 #define BITSET_ONES_(DST) BITSET_OP1_ (DST, BITSET_OP_ONES);  
197    
198  /* Return SRC == 0.  */  
199  #define BITSET_EMPTY_P_(SRC) BITSET_OP1_ (SRC, BITSET_OP_EMPTY_P);  /* DST = SRC.  */
200    #define BITSET_COPY_(DST, SRC) (SRC)->b.vtable->copy (DST, SRC)
201    
202    /* Return DST & SRC == 0.  */
203    #define BITSET_DISJOINT_P_(DST, SRC) (SRC)->b.vtable->disjoint_p (DST, SRC)
204    
205  /* Return DST == SRC.  */  /* Return DST == SRC.  */
206  #define BITSET_EQUAL_P_(DST, SRC) BITSET_OP2_ (DST, SRC, BITSET_OP_EQUAL_P)  #define BITSET_EQUAL_P_(DST, SRC) (SRC)->b.vtable->equal_p (DST, SRC)
207    
208    /* DST = ~SRC.  */
209    #define BITSET_NOT_(DST, SRC) (SRC)->b.vtable->not (DST, SRC)
210    
211  /* Return DST == DST | SRC.  */  /* Return DST == DST | SRC.  */
212  #define BITSET_SUBSET_P_(DST, SRC) BITSET_OP2_ (DST, SRC, BITSET_OP_SUBSET_P)  #define BITSET_SUBSET_P_(DST, SRC) (SRC)->b.vtable->subset_p (DST, SRC)
213    
 /* Return DST & SRC == 0.  */  
 #define BITSET_DISJOINT_P_(DST, SRC)\  
  BITSET_OP2_ (DST, SRC, BITSET_OP_DISJOINT_P)  
214    
215  /* DST = SRC.  */  /* DST = SRC1 & SRC2.  */
216  #define BITSET_COPY_(DST, SRC) BITSET_OP2_ (DST, SRC, BITSET_OP_COPY)  #define BITSET_AND_(DST, SRC1, SRC2) (SRC1)->b.vtable->and (DST, SRC1, SRC2)
217    #define BITSET_AND_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->and_cmp (DST, SRC1, SRC2)
218    
219  /* DST = ~SRC.  */  /* DST = SRC1 & ~SRC2.  */
220  #define BITSET_NOT_(DST, SRC) BITSET_OP2_ (DST, SRC, BITSET_OP_NOT)  #define BITSET_ANDN_(DST, SRC1, SRC2) (SRC1)->b.vtable->andn (DST, SRC1, SRC2)
221    #define BITSET_ANDN_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->andn_cmp (DST, SRC1, SRC2)
222    
223  /* DST = SRC1 | SRC2.  */  /* DST = SRC1 | SRC2.  */
224  #define BITSET_OR_(DST, SRC1, SRC2) BITSET_OP3_ (DST, SRC1, SRC2,\  #define BITSET_OR_(DST, SRC1, SRC2) (SRC1)->b.vtable->or (DST, SRC1, SRC2)
225    BITSET_OP_OR)  #define BITSET_OR_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->or_cmp (DST, SRC1, SRC2)
226    
227  /* DST = SRC1 ^ SRC2.  */  /* DST = SRC1 ^ SRC2.  */
228  #define BITSET_XOR_(DST, SRC1, SRC2) BITSET_OP3_ (DST, SRC1, SRC2,\  #define BITSET_XOR_(DST, SRC1, SRC2) (SRC1)->b.vtable->xor (DST, SRC1, SRC2)
229    BITSET_OP_XOR)  #define BITSET_XOR_CMP_(DST, SRC1, SRC2) (SRC1)->b.vtable->xor_cmp (DST, SRC1, SRC2)
230    
 /* DST = SRC1 & SRC2.  */  
 #define BITSET_AND_(DST, SRC1, SRC2) BITSET_OP3_ (DST, SRC1, SRC2, \  
   BITSET_OP_AND)  
231    
 /* DST = SRC1 & ~SRC2.  */  
 #define BITSET_ANDN_(DST, SRC1, SRC2) BITSET_OP3_ (DST, SRC1, SRC2, \  
   BITSET_OP_ANDN)  
232    
233  /* DST = (SRC1 & SRC2) | SRC3.  Return non-zero if  /* DST = (SRC1 & SRC2) | SRC3.  Return non-zero if
234     DST != (SRC1 & SRC2) | SRC3.  */     DST != (SRC1 & SRC2) | SRC3.  */
235  #define BITSET_AND_OR_(DST, SRC1, SRC2, SRC3)\  #define BITSET_AND_OR_(DST, SRC1, SRC2, SRC3) \
236    BITSET_OP4_ (DST, SRC1, SRC2, SRC3, BITSET_OP_AND_OR)   (SRC1)->b.vtable->and_or (DST, SRC1, SRC2, SRC3)
237    #define BITSET_AND_OR_CMP_(DST, SRC1, SRC2, SRC3) \
238     (SRC1)->b.vtable->and_or_cmp (DST, SRC1, SRC2, SRC3)
239    
240    /* DST = (SRC1 & ~SRC2) | SRC3.  Return non-zero if
241       DST != (SRC1 & ~SRC2) | SRC3.  */
242    #define BITSET_ANDN_OR_(DST, SRC1, SRC2, SRC3) \
243     (SRC1)->b.vtable->andn_or (DST, SRC1, SRC2, SRC3)
244    #define BITSET_ANDN_OR_CMP_(DST, SRC1, SRC2, SRC3) \
245     (SRC1)->b.vtable->andn_or_cmp (DST, SRC1, SRC2, SRC3)
246    
247  /* DST = (SRC1 | SRC2) & SRC3.  Return non-zero if  /* DST = (SRC1 | SRC2) & SRC3.  Return non-zero if
248     DST != (SRC1 | SRC2) & SRC3.  */     DST != (SRC1 | SRC2) & SRC3.  */
249  #define BITSET_OR_AND_(DST, SRC1, SRC2, SRC3)\  #define BITSET_OR_AND_(DST, SRC1, SRC2, SRC3) \
250    BITSET_OP4_ (DST, SRC1, SRC2, SRC3, BITSET_OP_OR_AND)   (SRC1)->b.vtable->or_and (DST, SRC1, SRC2, SRC3)
251    #define BITSET_OR_AND_CMP_(DST, SRC1, SRC2, SRC3) \
252     (SRC1)->b.vtable->or_and_cmp (DST, SRC1, SRC2, SRC3)
253    
 /* DST = (SRC1 & ~SRC2) | SRC3.  Return non-zero if  
    DST != (SRC1 & ~SRC2) | SRC3.  */  
 #define BITSET_ANDN_OR_(DST, SRC1, SRC2, SRC3)\  
   BITSET_OP4_ (DST, SRC1, SRC2, SRC3, BITSET_OP_ANDN_OR)  
254    
255  /* Find list of up to NUM bits set in BSET starting from and including  /* Find list of up to NUM bits set in BSET starting from and including
256     *NEXT.  Return with actual number of bits found and with *NEXT     *NEXT.  Return with actual number of bits found and with *NEXT
257     indicating where search stopped.  */     indicating where search stopped.  */
258  #define BITSET_LIST_(BSET, LIST, NUM, NEXT) \  #define BITSET_LIST_(BSET, LIST, NUM, NEXT) \
259  (BSET)->b.ops->list (BSET, LIST, NUM, NEXT)   (BSET)->b.vtable->list (BSET, LIST, NUM, NEXT)
260    
261  /* Find reverse list of up to NUM bits set in BSET starting from and  /* Find reverse list of up to NUM bits set in BSET starting from and
262     including NEXT.  Return with actual number of bits found and with     including NEXT.  Return with actual number of bits found and with
263     *NEXT indicating where search stopped.  */     *NEXT indicating where search stopped.  */
264  #define BITSET_REVERSE_LIST_(BSET, LIST, NUM, NEXT) \  #define BITSET_LIST_REVERSE_(BSET, LIST, NUM, NEXT) \
265  (BSET)->b.ops->reverse_list (BSET, LIST, NUM, NEXT)   (BSET)->b.vtable->list_reverse (BSET, LIST, NUM, NEXT)
266    
267    
268  struct bbitset_struct  /* Private functions for bitset implementations.  */
269  {  
270    struct bitset_ops_struct *ops;  extern int bitset_toggle_ PARAMS ((bitset, bitset_bindex));
   bitset_windex cindex;         /* Cache word index.  */  
   bitset_windex csize;          /* Cache size in words.  */  
   bitset_word *cdata;           /* Cache data pointer.  */  
   /* Perhaps we could sacrifice another word to indicate  
      that the bitset is known to be zero, that a bit has been set  
      in the cache, and that a bit has been cleared in the cache.  
      This would speed up some of the searches but slightly slow down  
      bit set/reset operations of cached bits.  */  
 };  
271    
272    extern int bitset_count_ PARAMS ((bitset));
273    
274  typedef struct bitset_struct *bitset;  extern int bitset_copy_ PARAMS ((bitset, bitset));
   
   
 /* The contents of this structure should be considered private.  */  
 struct bitset_ops_struct  
 {  
   void (*set) PARAMS ((struct bitset_struct *, bitset_bindex));  
   void (*reset) PARAMS ((struct bitset_struct *, bitset_bindex));  
   int (*test) PARAMS ((struct bitset_struct *, bitset_bindex));  
   int (*size) PARAMS ((struct bitset_struct *));  
   int (*op1) PARAMS ((struct bitset_struct *, enum bitset_ops));  
   int (*op2) PARAMS ((struct bitset_struct *, struct bitset_struct *,  
                       enum bitset_ops));  
   int (*op3) PARAMS ((struct bitset_struct *, struct bitset_struct *,  
                       struct bitset_struct *, enum bitset_ops));  
   int (*op4) PARAMS ((struct bitset_struct *, struct bitset_struct *,  
                       struct bitset_struct *, struct bitset_struct *,  
                       enum bitset_ops));  
   int (*list) PARAMS ((struct bitset_struct *, bitset_bindex *,  
                        bitset_bindex, bitset_bindex *));  
   int (*reverse_list) PARAMS ((struct bitset_struct *, bitset_bindex *,  
                                bitset_bindex, bitset_bindex *));  
   void (*free) PARAMS ((struct bitset_struct *));  
   enum bitset_type type;  
 };  
275    
276  #define BITSET_COMPATIBLE_(BSET1, BSET2) ((BSET1)->b.ops == (BSET2)->b.ops)  extern int bitset_and_or_cmp_ PARAMS ((bitset, bitset, bitset, bitset));
   
 #define BITSET_CHECK2_(DST, SRC) \  
 if (!BITSET_COMPATIBLE_ (DST, SRC)) abort ();  
   
 #define BITSET_CHECK3_(DST, SRC1, SRC2) \  
 if (!BITSET_COMPATIBLE_ (DST, SRC1) \  
     || !BITSET_COMPATIBLE_ (DST, SRC2)) abort ();  
   
 #define BITSET_CHECK4_(DST, SRC1, SRC2, SRC3) \  
 if (!BITSET_COMPATIBLE_ (DST, SRC1) || !BITSET_COMPATIBLE_ (DST, SRC2) \  
     || !BITSET_COMPATIBLE_ (DST, SRC3)) abort ();  
277    
278    extern int bitset_andn_or_cmp_ PARAMS ((bitset, bitset, bitset, bitset));
279    
280  extern int bitset_op4 PARAMS ((bitset, bitset, bitset, bitset,  extern int bitset_or_and_cmp_ PARAMS ((bitset, bitset, bitset, bitset));
                                enum bitset_ops op));  
281    
282  #endif /* _BBITSET_H  */  #endif /* _BBITSET_H  */

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26