This fixes rbitset_foreach().
*/
static inline size_t bitset_next_clear(const bitset_t *bs, size_t pos)
{
- if (pos >= bs->size)
- return (size_t)-1;
return rbitset_next_max(bs->data, pos, bs->size, false);
}
*/
static inline size_t bitset_next_set(const bitset_t *bs, size_t pos)
{
- if (pos >= bs->size)
- return (size_t)-1;
return rbitset_next_max(bs->data, pos, bs->size, true);
}
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);