* @brief raw bitsets (low-level bitset operations)
* @date 15.10.2004
* @author Matthias Braun
- * @version $Id$
*
* Raw bitsets are constructed from unsigned int arrays. Additional
* information like the size of the bitset or the used memory are not
/**
* Allocate an empty raw bitset on the stack.
*
- * @param res will contain the newly allocated bitset
* @param size number of bits in the bitset
*/
-#define rbitset_alloca(res, size) \
-do { \
- size_t size_bytes = BITSET_SIZE_BYTES(size); \
- res = (unsigned*)alloca(size_bytes); \
- memset(res, 0, size_bytes); \
-} while(0)
+#define rbitset_alloca(size) \
+ ((unsigned*)memset(alloca(BITSET_SIZE_BYTES(size)), 0, BITSET_SIZE_BYTES(size)))
/**
* Allocate an empty raw bitset on an obstack.
static inline size_t rbitset_next_max(const unsigned *bitset, size_t pos,
size_t last, bool set)
{
+ assert(pos <= last);
+ if (pos == last)
+ return (size_t)-1;
+
size_t p;
size_t elem_pos = pos / BITS_PER_ELEM;
size_t bit_pos = pos % BITS_PER_ELEM;
*/
unsigned in_elem_mask = (1u << bit_pos) - 1;
- assert(pos < last);
-
elem ^= mask;
p = ntz(elem & ~in_elem_mask);
dst[n-1] = (src[n-1] & last_mask) | (dst[n-1] & ~last_mask);
}
+/**
+ * Convenience macro for raw bitset iteration.
+ * @param bitset The bitset.
+ * @param size Size of the bitset.
+ * @param elm A size_t variable.
+ */
+#define rbitset_foreach(bitset, size, elm) \
+ for (size_t elm = 0; (elm = rbitset_next_max((bitset), elm, size, 1)) != (size_t)-1; ++elm)
+
#endif