typedef unsigned long bitset_word;
#define BITSET_WORD_BITS ((unsigned) (CHAR_BIT * sizeof (bitset_word)))
-/* Iterate over each set bit of WORD.
- Each iteration sets POS to the 0-based index of the next set bit in WORD.
- Repeatedly resets bits in WORD in place until it's null. */
-#define BITSET_FOR_EACH_BIT(Pos, Word) \
- for (int Pos = bitset_ffs (Word); \
- 0 <= Pos; \
- Word ^= 1UL << Pos, Pos = bitset_ffs (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. If this type is changed to be
The bit and word index types must be unsigned. */
typedef size_t bitset_bindex;
-/* First first set bit in WORD.
- Indexes start at 0, return -1 if WORD is null. */
-static inline
-int bitset_ffs (bitset_word word)
-{
- return ffsl ((long) word) - 1;
-}
-
/* Word index. */
typedef size_t bitset_windex;
#define BITSET_LIST_REVERSE_(BSET, LIST, NUM, NEXT) \
(BSET)->b.vtable->list_reverse (BSET, LIST, NUM, NEXT)
+/* Iterate left to right over each set bit of WORD.
+ Each iteration sets POS to the 0-based index of the next set bit in WORD.
+ Repeatedly resets bits in WORD in place until it's null. */
+#define BITSET_FOR_EACH_BIT(Pos, Word) \
+ for (int Pos = bitset_ffs_ (Word); \
+ 0 <= Pos; \
+ Word ^= 1UL << Pos, Pos = bitset_ffs_ (Word))
/* Private functions for bitset implementations. */
bool bitset_or_and_cmp_ (bitset, bitset, bitset, bitset);
+/* First set bit in WORD.
+ Indexes start at 0, return -1 if WORD is null. */
+static inline
+int bitset_ffs_ (bitset_word word)
+{
+ return ffsl ((long) word) - 1;
+}
+
#endif /* _BBITSET_H */