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 |
|
|
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 |
} |
} |
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 |
} |
} |
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 |
|
|
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 |
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) |
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) |
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) |