This source file includes following definitions.
- bitset_alloc
 
- bitset_reset
 
- bitset_test
 
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 #ifndef _GL_BITSET_H
  21 #define _GL_BITSET_H
  22 
  23 
  24 
  25 
  26 #include <stdio.h>
  27 #if USE_UNLOCKED_IO
  28 # include "unlocked-io.h"
  29 #endif
  30 
  31 #include "bitset/base.h"
  32 #include "obstack.h"
  33 
  34 
  35 enum bitset_attr {BITSET_FIXED = 1,    
  36                   BITSET_VARIABLE = 2, 
  37                   BITSET_DENSE = 4,    
  38                   BITSET_SPARSE = 8,   
  39                   BITSET_FRUGAL = 16,  
  40                   BITSET_GREEDY = 32}; 
  41 
  42 typedef unsigned bitset_attrs;
  43 
  44 
  45 
  46 
  47 
  48 union bitset_union
  49 {
  50   
  51 
  52   struct bbitset_struct b;              
  53 
  54   struct abitset_struct
  55   {
  56     struct bbitset_struct b;
  57     bitset_word words[1];               
  58   } a;
  59 
  60   struct tbitset_struct
  61   {
  62     struct bbitset_struct b;
  63     bitset_windex size;                 
  64     struct tbitset_elt_struct **elts;   
  65   } e;
  66 
  67   struct lbitset_struct
  68   {
  69     struct bbitset_struct b;
  70     struct lbitset_elt_struct *head;    
  71     struct lbitset_elt_struct *tail;    
  72   } l;
  73 
  74   struct bitset_stats_struct
  75   {
  76     struct bbitset_struct b;
  77     bitset bset;
  78   } s;
  79 
  80   struct vbitset_struct
  81   {
  82     struct bbitset_struct b;
  83     bitset_windex size;                 
  84   } v;
  85 };
  86 
  87 
  88 
  89 
  90 typedef struct
  91 {
  92   bitset_bindex list[BITSET_LIST_SIZE];
  93   bitset_bindex next;
  94   bitset_bindex num;
  95   bitset_bindex i;
  96 } bitset_iterator;
  97 
  98 
  99 
 100 void bitset_free (bitset);
 101 
 102 
 103 size_t bitset_bytes (enum bitset_type, bitset_bindex);
 104 
 105 
 106 bitset bitset_init (bitset, bitset_bindex, enum bitset_type);
 107 
 108 
 109 
 110 enum bitset_type bitset_type_choose (bitset_bindex, bitset_attrs);
 111 
 112 
 113 bitset bitset_alloc (bitset_bindex, enum bitset_type)
     
 114   _GL_ATTRIBUTE_DEALLOC (bitset_free, 1);
 115 
 116 
 117 void bitset_obstack_free (bitset);
 118 
 119 
 120 
 121 bitset bitset_obstack_alloc (struct obstack *bobstack,
 122                              bitset_bindex, enum bitset_type)
 123   _GL_ATTRIBUTE_DEALLOC (bitset_obstack_free, 1);
 124 
 125 
 126 bitset bitset_create (bitset_bindex, bitset_attrs)
 127   _GL_ATTRIBUTE_DEALLOC (bitset_free, 1);
 128 
 129 
 130 enum bitset_type bitset_type_get (bitset);
 131 
 132 
 133 const char *bitset_type_name_get (bitset);
 134 
 135 
 136 
 137 static inline void
 138 bitset_set (bitset bset, bitset_bindex bitno)
 139 {
 140   bitset_windex windex = bitno / BITSET_WORD_BITS;
 141   bitset_windex offset = windex - bset->b.cindex;
 142 
 143   if (offset < bset->b.csize)
 144     bset->b.cdata[offset] |= ((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
 145   else
 146     BITSET_SET_ (bset, bitno);
 147 }
 148 
 149 
 150 
 151 static inline void
 152 bitset_reset (bitset bset, bitset_bindex bitno)
     
 153 {
 154   bitset_windex windex = bitno / BITSET_WORD_BITS;
 155   bitset_windex offset = windex - bset->b.cindex;
 156 
 157   if (offset < bset->b.csize)
 158     bset->b.cdata[offset] &= ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
 159   else
 160     BITSET_RESET_ (bset, bitno);
 161 }
 162 
 163 
 164 
 165 static inline bool
 166 bitset_test (bitset bset, bitset_bindex bitno)
     
 167 {
 168   bitset_windex windex = bitno / BITSET_WORD_BITS;
 169   bitset_windex offset = windex - bset->b.cindex;
 170 
 171   if (offset < bset->b.csize)
 172     return (bset->b.cdata[offset] >> (bitno % BITSET_WORD_BITS)) & 1;
 173   else
 174     return BITSET_TEST_ (bset, bitno);
 175 }
 176 
 177 
 178 
 179 #define bitset_toggle(bset, bitno) BITSET_TOGGLE_ (bset, bitno)
 180 
 181 
 182 #define bitset_size(SRC) BITSET_SIZE_ (SRC)
 183 
 184 
 185 
 186 #define bitset_resize(DST, SIZE) BITSET_RESIZE_ (DST, SIZE)
 187 
 188 
 189 #define bitset_count(SRC) BITSET_COUNT_ (SRC)
 190 
 191 
 192 
 193 #define bitset_empty_p(SRC) BITSET_EMPTY_P_ (SRC)
 194 
 195 
 196 #define bitset_ones(DST) BITSET_ONES_ (DST)
 197 
 198 
 199 #define bitset_zero(DST) BITSET_ZERO_ (DST)
 200 
 201 
 202 
 203 
 204 #define bitset_copy(DST, SRC) BITSET_COPY_ (DST, SRC)
 205 
 206 
 207 #define bitset_disjoint_p(DST, SRC) BITSET_DISJOINT_P_ (DST, SRC)
 208 
 209 
 210 #define bitset_equal_p(DST, SRC) BITSET_EQUAL_P_ (DST, SRC)
 211 
 212 
 213 #define bitset_not(DST, SRC) BITSET_NOT_ (DST, SRC)
 214 
 215 
 216 #define bitset_subset_p(DST, SRC) BITSET_SUBSET_P_ (DST, SRC)
 217 
 218 
 219 
 220 
 221 #define bitset_and(DST, SRC1, SRC2) BITSET_AND_ (DST, SRC1, SRC2)
 222 
 223 
 224 #define bitset_and_cmp(DST, SRC1, SRC2) BITSET_AND_CMP_ (DST, SRC1, SRC2)
 225 
 226 
 227 #define bitset_andn(DST, SRC1, SRC2) BITSET_ANDN_ (DST, SRC1, SRC2)
 228 
 229 
 230 #define bitset_andn_cmp(DST, SRC1, SRC2) BITSET_ANDN_CMP_ (DST, SRC1, SRC2)
 231 
 232 
 233 #define bitset_or(DST, SRC1, SRC2) BITSET_OR_ (DST, SRC1, SRC2)
 234 
 235 
 236 #define bitset_or_cmp(DST, SRC1, SRC2) BITSET_OR_CMP_ (DST, SRC1, SRC2)
 237 
 238 
 239 #define bitset_xor(DST, SRC1, SRC2) BITSET_XOR_ (DST, SRC1, SRC2)
 240 
 241 
 242 #define bitset_xor_cmp(DST, SRC1, SRC2) BITSET_XOR_CMP_ (DST, SRC1, SRC2)
 243 
 244 
 245 
 246 
 247 #define bitset_and_or(DST, SRC1, SRC2, SRC3) \
 248  BITSET_AND_OR_ (DST, SRC1, SRC2, SRC3)
 249 
 250 
 251 
 252 #define bitset_and_or_cmp(DST, SRC1, SRC2, SRC3) \
 253  BITSET_AND_OR_CMP_ (DST, SRC1, SRC2, SRC3)
 254 
 255 
 256 #define bitset_andn_or(DST, SRC1, SRC2, SRC3) \
 257  BITSET_ANDN_OR_ (DST, SRC1, SRC2, SRC3)
 258 
 259 
 260 
 261 #define bitset_andn_or_cmp(DST, SRC1, SRC2, SRC3) \
 262  BITSET_ANDN_OR_CMP_ (DST, SRC1, SRC2, SRC3)
 263 
 264 
 265 #define bitset_or_and(DST, SRC1, SRC2, SRC3)\
 266  BITSET_OR_AND_ (DST, SRC1, SRC2, SRC3)
 267 
 268 
 269 
 270 #define bitset_or_and_cmp(DST, SRC1, SRC2, SRC3)\
 271  BITSET_OR_AND_CMP_ (DST, SRC1, SRC2, SRC3)
 272 
 273 
 274 
 275 
 276 #define bitset_list(BSET, LIST, NUM, NEXT) \
 277  BITSET_LIST_ (BSET, LIST, NUM, NEXT)
 278 
 279 
 280 
 281 
 282 #define bitset_list_reverse(BSET, LIST, NUM, NEXT) \
 283  BITSET_LIST_REVERSE_ (BSET, LIST, NUM, NEXT)
 284 
 285 
 286 bool bitset_compatible_p (bitset bset1, bitset bset2);
 287 
 288 
 289 
 290 bitset_bindex bitset_next (bitset src, bitset_bindex bitno);
 291 
 292 
 293 
 294 bitset_bindex bitset_prev (bitset src, bitset_bindex bitno);
 295 
 296 
 297 
 298 bitset_bindex bitset_first (bitset src);
 299 
 300 
 301 
 302 bitset_bindex bitset_last (bitset src);
 303 
 304 
 305 bool bitset_only_set_p (bitset, bitset_bindex);
 306 
 307 
 308 void bitset_dump (FILE *, bitset);
 309 
 310 
 311 
 312 
 313 
 314 
 315 
 316 
 317 
 318 
 319 
 320 #define BITSET_FOR_EACH(ITER, BSET, INDEX, MIN)                               \
 321   for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE;                        \
 322        (ITER.num == BITSET_LIST_SIZE)                                         \
 323        && (ITER.num = bitset_list (BSET, ITER.list,                           \
 324                                    BITSET_LIST_SIZE, &ITER.next));)           \
 325     for (ITER.i = 0;                                                          \
 326          ITER.i < ITER.num && ((INDEX) = ITER.list[ITER.i], 1);               \
 327          ITER.i++)
 328 
 329 
 330 
 331 
 332 
 333 
 334 
 335 
 336 
 337 
 338 
 339 
 340 #define BITSET_FOR_EACH_REVERSE(ITER, BSET, INDEX, MIN)                       \
 341   for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE;                        \
 342        (ITER.num == BITSET_LIST_SIZE)                                         \
 343        && (ITER.num = bitset_list_reverse (BSET, ITER.list,                   \
 344                                            BITSET_LIST_SIZE, &ITER.next));)   \
 345     for (ITER.i = 0;                                                          \
 346          ITER.i < ITER.num && ((INDEX) = ITER.list[ITER.i], 1);               \
 347          ITER.i++)
 348 
 349 
 350 
 351 
 352 #define bitset_diff(DST, SRC1, SRC2) bitset_andn (DST, SRC1, SRC2)
 353 #define bitset_diff_cmp(DST, SRC1, SRC2) bitset_andn_cmp (DST, SRC1, SRC2)
 354 
 355 #define bitset_intersection(DST, SRC1, SRC2) bitset_and (DST, SRC1, SRC2)
 356 #define bitset_intersection_cmp(DST, SRC1, SRC2) bitset_and_cmp (DST, SRC1, SRC2)
 357 
 358 #define bitset_union(DST, SRC1, SRC2) bitset_or (DST, SRC1, SRC2)
 359 #define bitset_union_cmp(DST, SRC1, SRC2) bitset_or_cmp (DST, SRC1, SRC2)
 360 
 361 
 362 #define bitset_symdiff(DST, SRC1, SRC2) bitset_xor (DST, SRC1, SRC2)
 363 #define bitset_symdiff_cmp(DST, SRC1, SRC2) bitset_xor_cmp (DST, SRC1, SRC2)
 364 
 365 
 366 #define bitset_diff_union(DST, SRC1, SRC2, SRC3) \
 367   bitset_andn_or (DST, SRC1, SRC2, SRC3)
 368 #define bitset_diff_union_cmp(DST, SRC1, SRC2, SRC3) \
 369   bitset_andn_or_cmp (DST, SRC1, SRC2, SRC3)
 370 
 371 
 372 
 373 void bitset_release_memory (void);
 374 
 375 
 376 void bitset_stats_enable (void);
 377 
 378 
 379 void bitset_stats_disable (void);
 380 
 381 
 382 void bitset_stats_read (const char *file_name);
 383 
 384 
 385 void bitset_stats_write (const char *file_name);
 386 
 387 
 388 void bitset_stats_dump (FILE *);
 389 
 390 
 391 void debug_bitset (bitset);
 392 
 393 
 394 void debug_bitset_stats (void);
 395 
 396 #endif