/* Currently we support three flavours of bitsets:
BITSET_ARRAY: Array of bits (fixed size, fast for dense bitsets).
BITSET_LIST: Linked list of array of bits (variable size, least storage
- for large very sparse sets).
- BITSET_TABLE: Expandable table of pointers to array of bits
- (variable size, less storage for large sparse sets).
+ for large very sparse sets).
+ BITSET_TABLE: Expandable table of pointers to array of bits
+ (variable size, less storage for large sparse sets).
BITSET_STATS: Wrapper bitset for internal use only.
*/
enum bitset_alloc_type {BITSET_MALLOC, BITSET_OBALLOC};
-/* Non-zero to use inline functions instead of macros. */
-#define BITSET_INLINE 0
-
/* Data type used to store a word of bits. */
typedef unsigned long bitset_word;
#define BITSET_WORD_BITS ((unsigned) (CHAR_BIT * sizeof (bitset_word)))
/* Bit index. In theory we might need a type wider than size_t, but
in practice we lose at most a factor of CHAR_BIT by going with
- size_t, and that is good enough. */
+ size_t, and that is good enough. If this type is changed to be
+ wider than size_t, the code needs to be modified to check for
+ overflow when converting bit counts to byte or word counts.
+ The bit and word index types must be unsigned. */
typedef size_t bitset_bindex;
/* Word index. */
typedef size_t bitset_windex;
-#define BITSET_INDEX_MAX ((bitset_word) 1 << (BITSET_WORD_BITS - 1))
+/* Maximum values for commonly-used unsigned types. BITSET_SIZE_MAX
+ always equals SIZE_MAX, but some older systems lack SIZE_MAX. */
+#define BITSET_BINDEX_MAX ((bitset_bindex) -1)
+
+/* Limit max word index to the maximum value of a signed integer
+ to simplify cache disabling. */
+#define BITSET_WINDEX_MAX (((bitset_windex) -1) >> 1)
+#define BITSET_SIZE_MAX ((size_t) -1)
#define BITSET_MSB ((bitset_word) 1 << (BITSET_WORD_BITS - 1))
#define BITSET_LIST_SIZE 1024
-enum bitset_ops {BITSET_OP_ZERO, BITSET_OP_ONES,
- BITSET_OP_COPY, BITSET_OP_NOT,
+enum bitset_ops {BITSET_OP_ZERO, BITSET_OP_ONES,
+ BITSET_OP_COPY, BITSET_OP_NOT,
BITSET_OP_EMPTY_P, BITSET_OP_EQUAL_P,
BITSET_OP_SUBSET_P, BITSET_OP_DISJOINT_P,
- BITSET_OP_AND, BITSET_OP_OR, BITSET_OP_XOR, BITSET_OP_ANDN,
+ BITSET_OP_AND, BITSET_OP_OR, BITSET_OP_XOR, BITSET_OP_ANDN,
BITSET_OP_OR_AND, BITSET_OP_AND_OR, BITSET_OP_ANDN_OR};
struct bbitset_struct
};
-typedef struct bitset_struct *bitset;
+typedef union bitset_union *bitset;
/* The contents of this structure should be considered private. */
struct bitset_vtable
{
- void (*set) PARAMS ((struct bitset_struct *, bitset_bindex));
- void (*reset) PARAMS ((struct bitset_struct *, bitset_bindex));
- int (*toggle) PARAMS ((struct bitset_struct *, bitset_bindex));
- int (*test) PARAMS ((struct bitset_struct *, bitset_bindex));
- int (*size) PARAMS ((struct bitset_struct *));
- int (*count) PARAMS ((struct bitset_struct *));
-
- int (*empty_p) PARAMS ((struct bitset_struct *));
- void (*ones) PARAMS ((struct bitset_struct *));
- void (*zero) PARAMS ((struct bitset_struct *));
-
- void (*copy) PARAMS ((struct bitset_struct *, struct bitset_struct *));
- int (*disjoint_p) PARAMS ((struct bitset_struct *, struct bitset_struct *));
- int (*equal_p) PARAMS ((struct bitset_struct *, struct bitset_struct *));
- void (*not) PARAMS ((struct bitset_struct *, struct bitset_struct *));
- int (*subset_p) PARAMS ((struct bitset_struct *, struct bitset_struct *));
-
- void (*and) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
- int (*and_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
- void (*andn) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
- int (*andn_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
- void (*or) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
- int (*or_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
- void (*xor) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
- int (*xor_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *));
-
- void (*and_or) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *, struct bitset_struct *));
- int (*and_or_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *, struct bitset_struct *));
- void (*andn_or) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *, struct bitset_struct *));
- int (*andn_or_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *, struct bitset_struct *));
- void (*or_and) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *, struct bitset_struct *));
- int (*or_and_cmp) PARAMS ((struct bitset_struct *, struct bitset_struct *,
- struct bitset_struct *, struct bitset_struct *));
-
- int (*list) PARAMS ((struct bitset_struct *, bitset_bindex *,
- bitset_bindex, bitset_bindex *));
- int (*list_reverse) PARAMS ((struct bitset_struct *, bitset_bindex *,
- bitset_bindex, bitset_bindex *));
- void (*free) PARAMS ((struct bitset_struct *));
+ void (*set) PARAMS ((bitset, bitset_bindex));
+ void (*reset) PARAMS ((bitset, bitset_bindex));
+ int (*toggle) PARAMS ((bitset, bitset_bindex));
+ int (*test) PARAMS ((bitset, bitset_bindex));
+ bitset_bindex (*size) PARAMS ((bitset));
+ bitset_bindex (*count) PARAMS ((bitset));
+
+ int (*empty_p) PARAMS ((bitset));
+ void (*ones) PARAMS ((bitset));
+ void (*zero) PARAMS ((bitset));
+
+ void (*copy) PARAMS ((bitset, bitset));
+ int (*disjoint_p) PARAMS ((bitset, bitset));
+ int (*equal_p) PARAMS ((bitset, bitset));
+ void (*not) PARAMS ((bitset, bitset));
+ int (*subset_p) PARAMS ((bitset, bitset));
+
+ void (*and) PARAMS ((bitset, bitset, bitset));
+ int (*and_cmp) PARAMS ((bitset, bitset, bitset));
+ void (*andn) PARAMS ((bitset, bitset, bitset));
+ int (*andn_cmp) PARAMS ((bitset, bitset, bitset));
+ void (*or) PARAMS ((bitset, bitset, bitset));
+ int (*or_cmp) PARAMS ((bitset, bitset, bitset));
+ void (*xor) PARAMS ((bitset, bitset, bitset));
+ int (*xor_cmp) PARAMS ((bitset, bitset, bitset));
+
+ void (*and_or) PARAMS ((bitset, bitset, bitset, bitset));
+ int (*and_or_cmp) PARAMS ((bitset, bitset, bitset, bitset));
+ void (*andn_or) PARAMS ((bitset, bitset, bitset, bitset));
+ int (*andn_or_cmp) PARAMS ((bitset, bitset, bitset, bitset));
+ void (*or_and) PARAMS ((bitset, bitset, bitset, bitset));
+ int (*or_and_cmp) PARAMS ((bitset, bitset, bitset, bitset));
+
+ bitset_bindex (*list) PARAMS ((bitset, bitset_bindex *,
+ bitset_bindex, bitset_bindex *));
+ bitset_bindex (*list_reverse) PARAMS ((bitset,
+ bitset_bindex *, bitset_bindex,
+ bitset_bindex *));
+ void (*free) PARAMS ((bitset));
enum bitset_type type;
};
/* Return size in bits of bitset SRC. */
-#define BITSET_SIZE_(SRC) (SRC)->b.vtable->size (SRC)
+#define BITSET_SIZE_(SRC) (SRC)->b.vtable->size (SRC)
/* Return number of bits set in bitset SRC. */
-#define BITSET_COUNT_(SRC) (SRC)->b.vtable->count (SRC)
+#define BITSET_COUNT_(SRC) (SRC)->b.vtable->count (SRC)
/* Return type of bitset SRC. */
-#define BITSET_TYPE_(DST) (DST)->b.vtable->type
+#define BITSET_TYPE_(DST) (DST)->b.vtable->type
/* Set bit BITNO in bitset DST. */
-#define BITSET_SET_(DST, BITNO) (DST)->b.vtable->set (DST, BITNO)
+#define BITSET_SET_(DST, BITNO) (DST)->b.vtable->set (DST, BITNO)
/* Reset bit BITNO in bitset DST. */
-#define BITSET_RESET_(DST, BITNO) (DST)->b.vtable->reset (DST, BITNO)
+#define BITSET_RESET_(DST, BITNO) (DST)->b.vtable->reset (DST, BITNO)
/* Toggle bit BITNO in bitset DST. */
-#define BITSET_TOGGLE_(DST, BITNO) (DST)->b.vtable->toggle (DST, BITNO)
+#define BITSET_TOGGLE_(DST, BITNO) (DST)->b.vtable->toggle (DST, BITNO)
/* Return non-zero if bit BITNO in bitset SRC is set. */
-#define BITSET_TEST_(SRC, BITNO) (SRC)->b.vtable->test (SRC, BITNO)
+#define BITSET_TEST_(SRC, BITNO) (SRC)->b.vtable->test (SRC, BITNO)
/* Free bitset SRC. */
#define BITSET_FREE_(SRC)\
(SRC1)->b.vtable->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) \
- (BSET)->b.vtable->list (BSET, LIST, NUM, NEXT)
+ (BSET)->b.vtable->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) \
- (BSET)->b.vtable->list_reverse (BSET, LIST, NUM, NEXT)
+ (BSET)->b.vtable->list_reverse (BSET, LIST, NUM, NEXT)
/* Private functions for bitset implementations. */
-
+
extern int bitset_toggle_ PARAMS ((bitset, bitset_bindex));
-extern int bitset_count_ PARAMS ((bitset));
+extern bitset_bindex bitset_count_ PARAMS ((bitset));
extern int bitset_copy_ PARAMS ((bitset, bitset));
+extern void bitset_and_or_ PARAMS ((bitset, bitset, bitset, bitset));
+
extern int bitset_and_or_cmp_ PARAMS ((bitset, bitset, bitset, bitset));
+extern void bitset_andn_or_ PARAMS ((bitset, bitset, bitset, bitset));
+
extern int bitset_andn_or_cmp_ PARAMS ((bitset, bitset, bitset, bitset));
+extern void bitset_or_and_ PARAMS ((bitset, bitset, bitset, bitset));
+
extern int bitset_or_and_cmp_ PARAMS ((bitset, bitset, bitset, bitset));
#endif /* _BBITSET_H */