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

Diff of /bison/lib/bitset.c

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

revision 1.9 by eggert, Sat May 24 19:16:02 2003 UTC revision 1.10 by eggert, Tue Jun 17 07:21:03 2003 UTC
# Line 21  Line 21 
21  #endif  #endif
22    
23  #include <stdlib.h>  #include <stdlib.h>
24    #include <string.h>
25  #include "bitset.h"  #include "bitset.h"
26  #include "abitset.h"  #include "abitset.h"
27  #include "lbitset.h"  #include "lbitset.h"
28  #include "ebitset.h"  #include "ebitset.h"
29    #include "vbitset.h"
30  #include "bitset_stats.h"  #include "bitset_stats.h"
31  #include "obstack.h"  #include "obstack.h"
32    
# Line 55  bitset_bytes (enum bitset_type type, bit Line 57  bitset_bytes (enum bitset_type type, bit
57        bytes = ebitset_bytes (n_bits);        bytes = ebitset_bytes (n_bits);
58        break;        break;
59    
60        case BITSET_VARRAY:
61          bytes = vbitset_bytes (n_bits);
62          break;
63    
64      default:      default:
65        abort ();        abort ();
66      }      }
# Line 81  bitset_init (bitset bset, bitset_bindex Line 87  bitset_init (bitset bset, bitset_bindex
87      case BITSET_TABLE:      case BITSET_TABLE:
88        return ebitset_init (bset, n_bits);        return ebitset_init (bset, n_bits);
89    
90        case BITSET_VARRAY:
91          return vbitset_init (bset, n_bits);
92    
93      default:      default:
94        abort ();        abort ();
95      }      }
# Line 93  bitset_init (bitset bset, bitset_bindex Line 102  bitset_init (bitset bset, bitset_bindex
102  enum bitset_type  enum bitset_type
103  bitset_type_choose (bitset_bindex n_bits ATTRIBUTE_UNUSED, unsigned int attr)  bitset_type_choose (bitset_bindex n_bits ATTRIBUTE_UNUSED, unsigned int attr)
104  {  {
   enum bitset_type type;  
   
105    /* Check attributes.  */    /* Check attributes.  */
106    if (attr & BITSET_FIXED && attr & BITSET_VARIABLE)    if (attr & BITSET_FIXED && attr & BITSET_VARIABLE)
107      abort ();      abort ();
108    if (attr & BITSET_SPARSE && attr & BITSET_DENSE)    if (attr & BITSET_SPARSE && attr & BITSET_DENSE)
109      abort ();      abort ();
110    
111    /* Choose the type of bitset. Note that sometimes we will be asked    /* Choose the type of bitset.  Note that sometimes we will be asked
112    for a zero length fixed size bitset.  */    for a zero length fixed size bitset.  */
113    
114    type = BITSET_ARRAY;    
115    /* Currently, the simple bitsets do not support a variable size.  */    /* If no attributes selected, choose a good compromise.  */
116    if (attr & BITSET_VARIABLE || attr & BITSET_SPARSE)    if (!attr)
117      {      return BITSET_VARRAY;
118        type = BITSET_LIST;  
119        if (attr & BITSET_DENSE || attr & BITSET_GREEDY)    if (attr & BITSET_SPARSE)
120          type = BITSET_TABLE;      return BITSET_LIST;
121      }  
122      if (attr & BITSET_FIXED)
123        return BITSET_ARRAY;
124    
125    return type;    if (attr & BITSET_GREEDY)
126        return BITSET_TABLE;
127    
128      return BITSET_VARRAY;
129  }  }
130    
131    
# Line 223  bitset_next (bitset src, bitset_bindex b Line 235  bitset_next (bitset src, bitset_bindex b
235  }  }
236    
237    
238    /* Return true if both bitsets are of the same type and size.  */
239    extern bool
240    bitset_compatible_p (bitset bset1, bitset bset2)
241    {
242        return BITSET_COMPATIBLE_ (bset1, bset2);
243    }
244    
245    
246  /* Find previous bit set in SRC starting from and including BITNO.  /* Find previous bit set in SRC starting from and including BITNO.
247     Return BITSET_BINDEX_MAX if SRC empty.  */     Return BITSET_BINDEX_MAX if SRC empty.  */
248  bitset_bindex  bitset_bindex
# Line 304  bitset_dump (FILE *file, bitset bset) Line 324  bitset_dump (FILE *file, bitset bset)
324  }  }
325    
326    
   
327  /* Release memory associated with bitsets.  */  /* Release memory associated with bitsets.  */
328  void  void
329  bitset_release_memory (void)  bitset_release_memory (void)
# Line 314  bitset_release_memory (void) Line 333  bitset_release_memory (void)
333  }  }
334    
335    
   
336  /* Toggle bit BITNO in bitset BSET and the new value of the bit.  */  /* Toggle bit BITNO in bitset BSET and the new value of the bit.  */
337  bool  bool
338  bitset_toggle_ (bitset bset, bitset_bindex bitno)  bitset_toggle_ (bitset bset, bitset_bindex bitno)
# Line 334  bitset_toggle_ (bitset bset, bitset_bind Line 352  bitset_toggle_ (bitset bset, bitset_bind
352  }  }
353    
354    
355    /* Return number of bits in bitset SRC.  */
356    bitset_bindex
357    bitset_size_ (bitset src)
358    {
359        return BITSET_NBITS_ (src);
360    }
361    
362    
363  /* Return number of bits set in bitset SRC.  */  /* Return number of bits set in bitset SRC.  */
364  bitset_bindex  bitset_bindex
365  bitset_count_ (bitset src)  bitset_count_ (bitset src)

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

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