/[bison]/bison/lib/ebitset.c
ViewVC logotype

Diff of /bison/lib/ebitset.c

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

revision 1.6 by akim, Mon Sep 30 12:50:49 2002 UTC revision 1.7 by eggert, Wed Oct 2 07:57:24 2002 UTC
# Line 40  Line 40 
40     be zero.     be zero.
41    
42     The bitset cache can be disabled either by setting cindex to     The bitset cache can be disabled either by setting cindex to
43     some large number or by setting csize to 0.  Here     BITSET_WINDEX_MAX or by setting csize to 0.  Here
44     we use the former approach since cindex needs to be updated whenever     we use the former approach since cindex needs to be updated whenever
45     cdata is changed.       cdata is changed.  
46  */  */
# Line 71  typedef ebitset_elt *ebitset_elts; Line 71  typedef ebitset_elt *ebitset_elts;
71  /* Head of ebitset linked list.  */  /* Head of ebitset linked list.  */
72  typedef struct ebitset_struct  typedef struct ebitset_struct
73  {  {
74    unsigned int size;            /* Number of elements.  */    bitset_windex size;           /* Number of elements.  */
75    ebitset_elts *elts;           /* Expanding array of pointers to elements.  */    ebitset_elts *elts;           /* Expanding array of pointers to elements.  */
76  }  }
77  *ebitset;  *ebitset;
# Line 108  static struct obstack ebitset_obstack; Line 108  static struct obstack ebitset_obstack;
108  static int ebitset_obstack_init = 0;  static int ebitset_obstack_init = 0;
109  static ebitset_elt *ebitset_free_list;  /* Free list of bitset elements.  */  static ebitset_elt *ebitset_free_list;  /* Free list of bitset elements.  */
110    
111  static void ebitset_elts_grow PARAMS ((bitset, unsigned int));  static void ebitset_elts_grow PARAMS ((bitset, bitset_windex));
112  static ebitset_elt *ebitset_elt_alloc PARAMS ((void));  static ebitset_elt *ebitset_elt_alloc PARAMS ((void));
113  static ebitset_elt *ebitset_elt_calloc PARAMS ((void));  static ebitset_elt *ebitset_elt_calloc PARAMS ((void));
114  static void ebitset_elt_add PARAMS ((bitset, ebitset_elt *, unsigned int));  static void ebitset_elt_add PARAMS ((bitset, ebitset_elt *, bitset_windex));
115  static void ebitset_elt_remove PARAMS ((bitset, unsigned int));  static void ebitset_elt_remove PARAMS ((bitset, bitset_windex));
116  static void ebitset_elt_free PARAMS ((ebitset_elt *));  static void ebitset_elt_free PARAMS ((ebitset_elt *));
117  static ebitset_elt *ebitset_elt_find PARAMS ((bitset, bitset_windex,  static ebitset_elt *ebitset_elt_find PARAMS ((bitset, bitset_windex,
118                                                enum ebitset_find_mode));                                                enum ebitset_find_mode));
119  static ebitset_elt *ebitset_elt_last PARAMS ((bitset));  static ebitset_elt *ebitset_elt_last PARAMS ((bitset));
120  static int ebitset_elt_zero_p PARAMS ((ebitset_elt *));  static int ebitset_elt_zero_p PARAMS ((ebitset_elt *));
121    
122  static int ebitset_weed PARAMS ((bitset));  static bitset_windex ebitset_weed PARAMS ((bitset));
123  static void ebitset_zero PARAMS ((bitset));  static void ebitset_zero PARAMS ((bitset));
124  static void ebitset_copy_ PARAMS ((bitset, bitset));  static void ebitset_copy_ PARAMS ((bitset, bitset));
125  static int ebitset_copy_cmp PARAMS ((bitset, bitset));  static int ebitset_copy_cmp PARAMS ((bitset, bitset));
126  static void ebitset_set PARAMS ((bitset, bitset_bindex));  static void ebitset_set PARAMS ((bitset, bitset_bindex));
127  static void ebitset_reset PARAMS ((bitset, bitset_bindex));  static void ebitset_reset PARAMS ((bitset, bitset_bindex));
128  static int ebitset_test PARAMS ((bitset, bitset_bindex));  static int ebitset_test PARAMS ((bitset, bitset_bindex));
129  static int ebitset_size PARAMS ((bitset));  static bitset_bindex ebitset_size PARAMS ((bitset));
130  static int ebitset_disjoint_p PARAMS ((bitset, bitset));  static int ebitset_disjoint_p PARAMS ((bitset, bitset));
131  static int ebitset_equal_p PARAMS ((bitset, bitset));  static int ebitset_equal_p PARAMS ((bitset, bitset));
132  static void ebitset_not PARAMS ((bitset, bitset));  static void ebitset_not PARAMS ((bitset, bitset));
# Line 136  static int ebitset_and_cmp PARAMS ((bits Line 136  static int ebitset_and_cmp PARAMS ((bits
136  static int ebitset_andn_cmp PARAMS ((bitset, bitset, bitset));  static int ebitset_andn_cmp PARAMS ((bitset, bitset, bitset));
137  static int ebitset_or_cmp PARAMS ((bitset, bitset, bitset));  static int ebitset_or_cmp PARAMS ((bitset, bitset, bitset));
138  static int ebitset_xor_cmp PARAMS ((bitset, bitset, bitset));  static int ebitset_xor_cmp PARAMS ((bitset, bitset, bitset));
139  static int ebitset_list PARAMS ((bitset, bitset_bindex *, bitset_bindex,  static bitset_bindex ebitset_list PARAMS ((bitset, bitset_bindex *,
140                                   bitset_bindex *));                                             bitset_bindex, bitset_bindex *));
141  static int ebitset_list_reverse  static bitset_bindex ebitset_list_reverse
142  PARAMS ((bitset, bitset_bindex *, bitset_bindex, bitset_bindex *));  PARAMS ((bitset, bitset_bindex *, bitset_bindex, bitset_bindex *));
143  static void ebitset_free PARAMS ((bitset));  static void ebitset_free PARAMS ((bitset));
144    
# Line 149  static void ebitset_free PARAMS ((bitset Line 149  static void ebitset_free PARAMS ((bitset
149  #define EBITSET_WORDS(ELT) ((ELT)->u.words)  #define EBITSET_WORDS(ELT) ((ELT)->u.words)
150    
151  /* Disable bitset cache and mark BSET as being zero.  */  /* Disable bitset cache and mark BSET as being zero.  */
152  #define EBITSET_ZERO_SET(BSET) ((BSET)->b.cindex = BITSET_INDEX_MAX, \  #define EBITSET_ZERO_SET(BSET) ((BSET)->b.cindex = BITSET_WINDEX_MAX, \
153          (BSET)->b.cdata = 0)          (BSET)->b.cdata = 0)
154    
155  #define EBITSET_CACHE_DISABLE(BSET)  ((BSET)->b.cindex = BITSET_INDEX_MAX)  #define EBITSET_CACHE_DISABLE(BSET)  ((BSET)->b.cindex = BITSET_WINDEX_MAX)
156    
157  /* Disable bitset cache and mark BSET as being possibly non-zero.  */  /* Disable bitset cache and mark BSET as being possibly non-zero.  */
158  #define EBITSET_NONZERO_SET(BSET) \  #define EBITSET_NONZERO_SET(BSET) \
# Line 173  static void ebitset_free PARAMS ((bitset Line 173  static void ebitset_free PARAMS ((bitset
173  static void  static void
174  ebitset_elts_grow (bset, size)  ebitset_elts_grow (bset, size)
175       bitset bset;       bitset bset;
176       unsigned int size;       bitset_windex size;
177  {  {
178    unsigned int oldsize;    bitset_windex oldsize;
179    unsigned int newsize;    bitset_windex newsize;
180    
181    oldsize = EBITSET_SIZE (bset);    oldsize = EBITSET_SIZE (bset);
182    newsize = oldsize + size;    newsize = oldsize + size;
183    
184      if (BITSET_SIZE_MAX / sizeof (ebitset_elt *) < newsize)
185        xalloc_die ();
186    
187    EBITSET_ELTS (bset) = xrealloc (EBITSET_ELTS (bset),    EBITSET_ELTS (bset) = xrealloc (EBITSET_ELTS (bset),
188                                    newsize * sizeof (ebitset_elt *));                                    newsize * sizeof (ebitset_elt *));
189    EBITSET_SIZE (bset) = newsize;    EBITSET_SIZE (bset) = newsize;
# Line 269  ebitset_elt_free (elt) Line 272  ebitset_elt_free (elt)
272  static inline void  static inline void
273  ebitset_elt_remove (bset, eindex)  ebitset_elt_remove (bset, eindex)
274       bitset bset;       bitset bset;
275       unsigned int eindex;       bitset_windex eindex;
276  {  {
277    ebitset_elts *elts;    ebitset_elts *elts;
278    ebitset_elt *elt;    ebitset_elt *elt;
# Line 288  static inline void Line 291  static inline void
291  ebitset_elt_add (bset, elt, eindex)  ebitset_elt_add (bset, elt, eindex)
292       bitset bset;       bitset bset;
293       ebitset_elt *elt;       ebitset_elt *elt;
294       unsigned int eindex;       bitset_windex eindex;
295  {  {
296    ebitset_elts *elts;    ebitset_elts *elts;
297    
# Line 321  ebitset_elt_find (bset, windex, mode) Line 324  ebitset_elt_find (bset, windex, mode)
324  {  {
325    ebitset_elt *elt;    ebitset_elt *elt;
326    bitset_windex size;    bitset_windex size;
327    unsigned int eindex;    bitset_windex eindex;
328    ebitset_elts *elts;    ebitset_elts *elts;
329    
330    eindex = windex / EBITSET_ELT_WORDS;    eindex = windex / EBITSET_ELT_WORDS;
# Line 351  ebitset_elt_find (bset, windex, mode) Line 354  ebitset_elt_find (bset, windex, mode)
354      case EBITSET_CREATE:      case EBITSET_CREATE:
355        if (eindex >= size)        if (eindex >= size)
356          {          {
357            unsigned int extra;            bitset_windex extra;
358    
359            extra = eindex - size + 1;            extra = eindex - size + 1;
360    
# Line 395  ebitset_elt_last (bset) Line 398  ebitset_elt_last (bset)
398    
399    
400  /* Weed out the zero elements from the elts.  */  /* Weed out the zero elements from the elts.  */
401  static inline int  static inline bitset_windex
402  ebitset_weed (bset)  ebitset_weed (bset)
403       bitset bset;       bitset bset;
404  {  {
405    ebitset_elts *elts;    ebitset_elts *elts;
406    bitset_windex j;    bitset_windex j;
407    int count;    bitset_windex count;
408    
409    if (EBITSET_ZERO_P (bset))    if (EBITSET_ZERO_P (bset))
410      return 0;      return 0;
# Line 567  ebitset_copy_cmp (dst, src) Line 570  ebitset_copy_cmp (dst, src)
570    
571    
572  /* Return size in bits of bitset SRC.  */  /* Return size in bits of bitset SRC.  */
573  static int  static bitset_bindex
574  ebitset_size (src)  ebitset_size (src)
575       bitset src;       bitset src;
576  {  {
# Line 639  ebitset_free (bset) Line 642  ebitset_free (bset)
642  /* 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
643   *NEXT and store in array LIST.  Return with actual number of bits   *NEXT and store in array LIST.  Return with actual number of bits
644   found and with *NEXT indicating where search stopped.  */   found and with *NEXT indicating where search stopped.  */
645  static int  static bitset_bindex
646  ebitset_list_reverse (bset, list, num, next)  ebitset_list_reverse (bset, list, num, next)
647       bitset bset;       bitset bset;
648       bitset_bindex *list;       bitset_bindex *list;
# Line 652  ebitset_list_reverse (bset, list, num, n Line 655  ebitset_list_reverse (bset, list, num, n
655    unsigned int bcount;    unsigned int bcount;
656    bitset_bindex boffset;    bitset_bindex boffset;
657    bitset_windex windex;    bitset_windex windex;
658    unsigned int eindex;    bitset_windex eindex;
659    bitset_windex woffset;    bitset_windex woffset;
660    bitset_bindex count;    bitset_bindex count;
661    bitset_windex size;    bitset_windex size;
# Line 731  ebitset_list_reverse (bset, list, num, n Line 734  ebitset_list_reverse (bset, list, num, n
734  /* 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
735   *NEXT and store in array LIST.  Return with actual number of bits   *NEXT and store in array LIST.  Return with actual number of bits
736   found and with *NEXT indicating where search stopped.  */   found and with *NEXT indicating where search stopped.  */
737  static int  static bitset_bindex
738  ebitset_list (bset, list, num, next)  ebitset_list (bset, list, num, next)
739       bitset bset;       bitset bset;
740       bitset_bindex *list;       bitset_bindex *list;
# Line 740  ebitset_list (bset, list, num, next) Line 743  ebitset_list (bset, list, num, next)
743  {  {
744    bitset_bindex bitno;    bitset_bindex bitno;
745    bitset_windex windex;    bitset_windex windex;
746    unsigned int eindex;    bitset_windex eindex;
747    bitset_bindex count;    bitset_bindex count;
748    bitset_windex size;    bitset_windex size;
749    ebitset_elt *elt;    ebitset_elt *elt;
# Line 1296  struct bitset_vtable ebitset_vtable = { Line 1299  struct bitset_vtable ebitset_vtable = {
1299    
1300    
1301  /* Return size of initial structure.  */  /* Return size of initial structure.  */
1302  int  size_t
1303  ebitset_bytes (n_bits)  ebitset_bytes (n_bits)
1304       bitset_bindex n_bits ATTRIBUTE_UNUSED;       bitset_bindex n_bits ATTRIBUTE_UNUSED;
1305  {  {
# Line 1311  ebitset_init (bset, n_bits) Line 1314  ebitset_init (bset, n_bits)
1314       bitset bset;       bitset bset;
1315       bitset_bindex n_bits;       bitset_bindex n_bits;
1316  {  {
1317    unsigned int size;    bitset_windex size;
1318    
1319    bset->b.vtable = &ebitset_vtable;    bset->b.vtable = &ebitset_vtable;
1320    

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

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