65 Bit &operator = (
bool val) { _bm->
bit(_bit, val);
return *
this; }
66 operator bool ()
const {
return _bm->
bit(_bit); }
74 static long bit_buffer_bytes(
long bits)
noexcept
82 typedef unsigned long Type;
90 static long chars(
long bits)
noexcept
90 static long chars(
long bits)
noexcept {
…}
98 typedef unsigned char Type;
111 void bit(
long bit,
bool on)
noexcept;
143 void set_bit(
long bit)
noexcept;
182 {
return this->
bit(
bit); }
192 {
return Bit(
this,
bit); }
205 long scan_zero(
long max_bit,
long start_bit = 0) const noexcept;
207 void *bit_buffer() const noexcept {
return _bits; }
210 static int _bzl(
unsigned long w)
noexcept;
229 { __builtin_memcpy(_bits, o._bits,
sizeof(_bits)); }
242 long scan_zero(
long start_bit = 0) const noexcept;
245 { __builtin_memset(_bits, 0,
sizeof(_bits)); }
253 long idx = word_index(bit);
254 long b = bit_index(bit);
255 _bits[idx] = (_bits[idx] & ~(1UL << b)) | (
static_cast<unsigned long>(on) << b);
262 long idx = word_index(bit);
263 long b = bit_index(bit);
264 _bits[idx] &= ~(1UL << b);
271 long idx = word_index(bit);
272 long b = bit_index(bit);
274 __atomic_and_fetch(&_bits[idx], ~mask, __ATOMIC_RELAXED);
281 long idx = word_index(bit);
282 long b = bit_index(bit);
284 return __atomic_fetch_and(&_bits[idx], ~mask, __ATOMIC_RELAXED) & mask;
291 long idx = word_index(bit);
292 long b = bit_index(bit);
293 _bits[idx] |= (1UL << b);
300 long idx = word_index(bit);
301 long b = bit_index(bit);
303 __atomic_or_fetch(&_bits[idx], mask, __ATOMIC_RELAXED);
310 long idx = word_index(bit);
311 long b = bit_index(bit);
313 return __atomic_fetch_or(&_bits[idx], mask, __ATOMIC_RELAXED) & mask;
320 long idx = word_index(bit);
321 long b = bit_index(bit);
322 return _bits[idx] & (1UL << b);
327Bitmap_base::_bzl(
unsigned long w)
noexcept
329 for (
int i = 0; i < W_bits; ++i, w >>= 1)
341 if (!(
operator [] (start_bit)))
344 long idx = word_index(start_bit);
346 max_bit -= start_bit & ~(W_bits - 1);
348 for (; max_bit > 0; max_bit -= W_bits, ++idx)
353 if (_bits[idx] != ~0UL)
355 long zbit = _bzl(_bits[idx]);
356 return zbit < max_bit ? idx * W_bits + zbit : -1;
363template<
int BITS>
inline
A writable 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.
@ W_bits
number of bits in word_type
@ C_bits
number of bits in char
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.
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.