-/* Loop over all elements of BSET, starting with MIN, executing CODE. */
-#define BITSET_EXECUTE(BSET, MIN, N, CODE) \
-do { \
- bitset_bindex _list[BITSET_LIST_SIZE]; \
- bitset_bindex _next = (MIN); \
- int _num; \
- \
- while ((_num = bitset_list ((BSET), _list, BITSET_LIST_SIZE, &_next)))\
- { \
- int _i; \
- \
- for (_i = 0; _i < _num; _i++) \
- { \
- (N) = _list[_i]; \
- CODE; \
- } \
- if (_num < BITSET_LIST_SIZE) \
- break; \
- } \
-} while (0)
+/* Loop over all elements of BSET, starting with MIN, setting BIT
+ to the index of each set bit. For example, the following will print
+ the bits set in a bitset:
+
+ bitset_bindex i;
+ bitset_iterator iter;
+
+ bitset_zero (dst);
+ BITSET_FOR_EACH (iter, src, i, 0)
+ {
+ printf ("%ld ", i);
+ };
+*/
+#define BITSET_FOR_EACH(ITER, BSET, BIT, MIN) \
+ 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));) \
+ for (ITER.i = 0; (BIT) = ITER.list[ITER.i], ITER.i < ITER.num; ITER.i++)