Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifndef _BITSET_H
-#define _BITSET_H
+#define _BITSET_H
/* This file is the public interface to the bitset abstract data type.
Only use the functions and macros defined in this file. */
typedef unsigned int bitset_attrs;
-/* The contents of the structure should be considered to be private.
- While I would like to make this structure opaque, it needs to be
- visible for the inline bit set/test functions. */
-struct bitset_struct
+/* The contents of the union should be considered to be private.
+ While I would like to make this union opaque, it needs to be
+ visible for the inline bit set/test functions, and for delegation
+ to the proper implementation. */
+union bitset_union
{
+ /* This must be the first member of every other structure that is a
+ member of this union. */
struct bbitset_struct b;
+
+ struct abitset_struct
+ {
+ struct bbitset_struct b;
+ bitset_bindex n_bits; /* Number of bits. */
+ bitset_word words[1]; /* The array of bits. */
+ } a;
+
+ struct ebitset_struct
+ {
+ struct bbitset_struct b;
+ bitset_windex size; /* Number of elements. */
+ struct ebitset_elt_struct **elts; /* Expanding array of ptrs to elts. */
+ } e;
+
+ struct lbitset_struct
+ {
+ struct bbitset_struct b;
+ struct lbitset_elt_struct *head; /* First element in linked list. */
+ struct lbitset_elt_struct *tail; /* Last element in linked list. */
+ } l;
+
+ struct bitset_stats_struct
+ {
+ struct bbitset_struct b;
+ bitset bset;
+ } s;
};
extern const char *bitset_type_name_get PARAMS ((bitset));
#if BITSET_INLINE
-static inline void bitset_set PARAMS ((bitset, bitset_bindex));
-static inline void bitset_reset PARAMS ((bitset, bitset_bindex));
-static inline int bitset_test PARAMS ((bitset, bitset_bindex));
/* Set bit BITNO in bitset BSET. */
-static inline void bitset_set (bset, bitno)
- bitset bset;
- bitset_bindex bitno;
+static inline void
+bitset_set (bitset bset, bitset_bindex bitno)
{
bitset_windex index = bitno / BITSET_WORD_BITS;
bitset_windex offset = index - bset->b.cindex;
-
+
if (offset < bset->b.csize)
bset->b.cdata[offset] |= ((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
else
/* Reset bit BITNO in bitset BSET. */
-static inline void bitset_reset (bset, bitno)
- bitset bset;
- bitset_bindex bitno;
+static inline void
+bitset_reset (bitset bset, bitset_bindex bitno)
{
bitset_windex index = bitno / BITSET_WORD_BITS;
bitset_windex offset = index - bset->b.cindex;
-
+
if (offset < bset->b.csize)
bset->b.cdata[offset] &= ~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
else
/* Test bit BITNO in bitset BSET. */
-static inline int bitset_test (bset, bitno)
- bitset bset;
- bitset_bindex bitno;
+static inline int
+bitset_test (bitset bset, bitset_bindex bitno)
{
bitset_windex index = bitno / BITSET_WORD_BITS;
bitset_windex offset = index - bset->b.cindex;
-
+
if (offset < bset->b.csize)
return (bset->b.cdata[offset] >> (bitno % BITSET_WORD_BITS)) & 1;
else
bitset_bindex _bitno = (bitno); \
bitset_windex _index = _bitno / BITSET_WORD_BITS; \
bitset_windex _offset = _index - (bset)->b.cindex; \
- \
+ \
if (_offset < (bset)->b.csize) \
(bset)->b.cdata[_offset] |= \
((bitset_word) 1 << (_bitno % BITSET_WORD_BITS)); \
bitset_bindex _bitno = (bitno); \
bitset_windex _index = _bitno / BITSET_WORD_BITS; \
bitset_windex _offset = _index - (bset)->b.cindex; \
- \
+ \
if (_offset < (bset)->b.csize) \
- (bset)->b.cdata[_offset] &= ~(1 << (_bitno % BITSET_WORD_BITS)); \
+ (bset)->b.cdata[_offset] &= \
+ ~((bitset_word) 1 << (_bitno % BITSET_WORD_BITS)); \
else \
BITSET_RESET_ ((bset), _bitno); \
} while (0)
#define bitset_or_and_cmp(DST, SRC1, SRC2, SRC3)\
BITSET_OR_AND_CMP_ (DST, SRC1, SRC2, SRC3)
-/* 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
*NEXT. Return with actual number of bits found and with *NEXT
indicating where search stopped. */
#define bitset_list(BSET, LIST, NUM, NEXT) \
- BITSET_LIST_ (BSET, LIST, NUM, NEXT)
+ BITSET_LIST_ (BSET, LIST, NUM, NEXT)
/* Find reverse list of up to NUM bits set in BSET starting from and
including NEXT. Return with actual number of bits found and with
*NEXT indicating where search stopped. */
#define bitset_list_reverse(BSET, LIST, NUM, NEXT) \
- BITSET_LIST_REVERSE_ (BSET, LIST, NUM, NEXT)
+ BITSET_LIST_REVERSE_ (BSET, LIST, NUM, NEXT)
+
+/* Find next set bit. */
+extern bitset_bindex bitset_next PARAMS ((bitset, bitset_bindex));
+
+/* Find previous set bit. */
+extern bitset_bindex bitset_prev PARAMS ((bitset, bitset_bindex));
/* Find first set bit. */
extern bitset_bindex bitset_first PARAMS ((bitset));
/* Find last set bit. */
extern bitset_bindex bitset_last PARAMS ((bitset));
+/* Return nonzero if this is the only set bit. */
+extern int bitset_only_set_p PARAMS ((bitset, bitset_bindex));
+
/* Dump bitset. */
extern void bitset_dump PARAMS ((FILE *, bitset));
for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \
(ITER.num == BITSET_LIST_SIZE) \
&& (ITER.num = bitset_list (BSET, ITER.list, \
- BITSET_LIST_SIZE, &ITER.next));) \
+ BITSET_LIST_SIZE, &ITER.next));) \
for (ITER.i = 0; (BIT) = ITER.list[ITER.i], ITER.i < ITER.num; ITER.i++)
/* Loop over all elements of BSET, in reverse order starting with
- MIN, setting BIT to the index of each set bit. For example, the
+ MIN, setting BIT to the index of each set bit. For example, the
following will print the bits set in a bitset in reverse order:
bitset_bindex i;
for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \
(ITER.num == BITSET_LIST_SIZE) \
&& (ITER.num = bitset_list_reverse (BSET, ITER.list, \
- BITSET_LIST_SIZE, &ITER.next));) \
+ BITSET_LIST_SIZE, &ITER.next));) \
for (ITER.i = 0; (BIT) = ITER.list[ITER.i], ITER.i < ITER.num; ITER.i++)
/* Define set operations in terms of logical operations. */
-#define bitset_diff(DST, SRC1, SRC2) bitset_andn (DST, SRC1, SRC2)
-#define bitset_diff_cmp(DST, SRC1, SRC2) bitset_andn_cmp (DST, SRC1, SRC2)
+#define bitset_diff(DST, SRC1, SRC2) bitset_andn (DST, SRC1, SRC2)
+#define bitset_diff_cmp(DST, SRC1, SRC2) bitset_andn_cmp (DST, SRC1, SRC2)
-#define bitset_intersection(DST, SRC1, SRC2) bitset_and (DST, SRC1, SRC2)
-#define bitset_intersection_cmp(DST, SRC1, SRC2) bitset_and_cmp (DST, SRC1, SRC2)
+#define bitset_intersection(DST, SRC1, SRC2) bitset_and (DST, SRC1, SRC2)
+#define bitset_intersection_cmp(DST, SRC1, SRC2) bitset_and_cmp (DST, SRC1, SRC2)
-#define bitset_union(DST, SRC1, SRC2) bitset_or (DST, SRC1, SRC2)
-#define bitset_union_cmp(DST, SRC1, SRC2) bitset_or_cmp (DST, SRC1, SRC2)
+#define bitset_union(DST, SRC1, SRC2) bitset_or (DST, SRC1, SRC2)
+#define bitset_union_cmp(DST, SRC1, SRC2) bitset_or_cmp (DST, SRC1, SRC2)
/* Symmetrical difference. */
-#define bitset_symdiff(DST, SRC1, SRC2) bitset_xor (DST, SRC1, SRC2)
-#define bitset_symdiff_cmp(DST, SRC1, SRC2) bitset_xor_cmp (DST, SRC1, SRC2)
+#define bitset_symdiff(DST, SRC1, SRC2) bitset_xor (DST, SRC1, SRC2)
+#define bitset_symdiff_cmp(DST, SRC1, SRC2) bitset_xor_cmp (DST, SRC1, SRC2)
/* Union of difference. */
#define bitset_diff_union(DST, SRC1, SRC2, SRC3) \
- bitset_andn_or (DST, SRC1, SRC2, SRC3)
+ bitset_andn_or (DST, SRC1, SRC2, SRC3)
#define bitset_diff_union_cmp(DST, SRC1, SRC2, SRC3) \
- bitset_andn_or_cmp (DST, SRC1, SRC2, SRC3)
+ bitset_andn_or_cmp (DST, SRC1, SRC2, SRC3)