76 Bit &operator = (
bool val) { _bm->
bit(_bit, val);
return *
this; }
77 operator bool ()
const {
return _bm->
bit(_bit); }
85 static long bit_buffer_bytes(
long bits)
noexcept
93 typedef unsigned long Type;
101 static long chars(
long bits)
noexcept
105 template<
long BITS >
109 typedef unsigned char Type;
122 void bit(
long bit,
bool on)
noexcept;
154 void set_bit(
long bit)
noexcept;
193 {
return this->
bit(
bit); }
203 {
return Bit(
this,
bit); }
216 long scan_zero(
long max_bit,
long start_bit = 0) const noexcept;
218 void *bit_buffer() const noexcept {
return _bits; }
221 static int _bzl(
unsigned long w)
noexcept;
240 { __builtin_memcpy(_bits, o._bits,
sizeof(_bits)); }
253 long scan_zero(
long start_bit = 0) const noexcept;
256 { __builtin_memset(_bits, 0,
sizeof(_bits)); }
264 long idx = word_index(bit);
265 long b = bit_index(bit);
266 _bits[idx] = (_bits[idx] & ~(1UL << b)) | (
static_cast<unsigned long>(on) << b);
273 long idx = word_index(bit);
274 long b = bit_index(bit);
275 _bits[idx] &= ~(1UL << b);
282 long idx = word_index(bit);
283 long b = bit_index(bit);
285 __atomic_and_fetch(&_bits[idx], ~mask, __ATOMIC_RELAXED);
292 long idx = word_index(bit);
293 long b = bit_index(bit);
295 return __atomic_fetch_and(&_bits[idx], ~mask, __ATOMIC_RELAXED) & mask;
302 long idx = word_index(bit);
303 long b = bit_index(bit);
304 _bits[idx] |= (1UL << b);
311 long idx = word_index(bit);
312 long b = bit_index(bit);
314 __atomic_or_fetch(&_bits[idx], mask, __ATOMIC_RELAXED);
321 long idx = word_index(bit);
322 long b = bit_index(bit);
324 return __atomic_fetch_or(&_bits[idx], mask, __ATOMIC_RELAXED) & mask;
331 long idx = word_index(bit);
332 long b = bit_index(bit);
333 return _bits[idx] & (1UL << b);
338Bitmap_base::_bzl(
unsigned long w)
noexcept
340 for (
int i = 0; i < W_bits; ++i, w >>= 1)
352 if (!(
operator [] (start_bit)))
355 long idx = word_index(start_bit);
357 max_bit -= start_bit & ~(W_bits - 1);
359 for (; max_bit > 0; max_bit -= W_bits, ++idx)
364 if (_bits[idx] != ~0UL)
366 long zbit = _bzl(_bits[idx]);
367 return zbit < max_bit ? idx * W_bits + zbit : -1;
374template<
int BITS>
inline
A writeable bit in a bitmap.
Helper abstraction for a byte contained in the bitmap.
Helper abstraction for a word contained in the bitmap.
Basic bitmap abstraction.
static long chars(long bits) noexcept
Get the number of chars that are used for the bitmap.
long scan_zero(long max_bit, long start_bit=0) const noexcept
Scan for the first zero bit.
void atomic_clear_bit(long bit) noexcept
Clear bit bit atomically.
word_type atomic_get_and_clear(long bit) noexcept
Clear bit bit atomically and return old state.
void atomic_set_bit(long bit) noexcept
Set bit bit atomically.
static unsigned bit_index(unsigned bit)
Get the bit index within word_type for the given bit.
unsigned long word_type
Data type for each element of the bit buffer.
static long words(long bits) noexcept
Get the number of Words that are used for the bitmap.
static unsigned word_index(unsigned bit)
Get the word index for the given bit.
@ W_bits
number of bits in word_type
@ C_bits
number of bits in char
void clear_bit(long bit) noexcept
Clear bit bit.
void set_bit(long bit) noexcept
Set bit bit.
word_type atomic_get_and_set(long bit) noexcept
Set bit bit atomically and return old state.
word_type operator[](long bit) const noexcept
Get the bit at index bit.
void bit(long bit, bool on) noexcept
Set the value of bit bit to on.
word_type * _bits
Pointer to the buffer storing the bits.
Bitmap() noexcept
Create a bitmap with BITS bits.
long scan_zero(long start_bit=0) const noexcept
Scan for the first zero bit.