73 Bit &operator = (
bool val) { _bm->
bit(_bit, val);
return *
this; }
74 operator bool ()
const {
return _bm->
bit(_bit); }
82 static long bit_buffer_bytes(
long bits)
noexcept
90 typedef unsigned long Type;
98 static long chars(
long bits)
throw ()
102 template<
long BITS >
106 typedef unsigned char Type;
118 void bit(
long bit,
bool on)
noexcept;
129 void set_bit(
long bit)
noexcept;
144 {
return this->
bit(
bit); }
152 {
return Bit(
this,
bit); }
165 long scan_zero(
long max_bit,
long start_bit = 0) const noexcept;
167 void *bit_buffer() const noexcept {
return _bits; }
170 static int _bzl(
unsigned long w)
noexcept;
189 { __builtin_memcpy(_bits, o._bits,
sizeof(_bits)); }
202 long scan_zero(
long start_bit = 0) const noexcept;
205 { __builtin_memset(_bits, 0,
sizeof(_bits)); }
213 long idx = word_index(bit);
214 long b = bit_index(bit);
215 _bits[idx] = (_bits[idx] & ~(1UL << b)) | ((
unsigned long)on << b);
222 long idx = word_index(bit);
223 long b = bit_index(bit);
224 _bits[idx] &= ~(1UL << b);
231 long idx = word_index(bit);
232 long b = bit_index(bit);
233 _bits[idx] |= (1UL << b);
240 long idx = word_index(bit);
241 long b = bit_index(bit);
242 return _bits[idx] & (1UL << b);
247Bitmap_base::_bzl(
unsigned long w)
noexcept
249 for (
int i = 0; i < W_bits; ++i, w >>= 1)
261 if (!(
operator [] (start_bit)))
264 long idx = word_index(start_bit);
266 max_bit -= start_bit & ~(W_bits - 1);
268 for (; max_bit > 0; max_bit -= W_bits, ++idx)
273 if (_bits[idx] != ~0UL)
275 long zbit = _bzl(_bits[idx]);
276 return zbit < max_bit ? idx * W_bits + zbit : -1;
283template<
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.
long scan_zero(long max_bit, long start_bit=0) const noexcept
Scan for the first zero bit.
@ W_bits
number of bits in word_type
@ C_bits
number of bits in char
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.
void clear_bit(long bit) noexcept
Clear bit bit.
void set_bit(long bit) noexcept
Set bit bit.
word_type operator[](long bit) const noexcept
Get the bit at index bit.
static long chars(long bits)
Get the number of chars that are used for the bitmap.
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.