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)
throw()
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)
throw();
144 {
return this->
bit(
bit); }
152 {
return Bit(
this,
bit); }
165 long scan_zero(
long max_bit,
long start_bit = 0)
const throw();
167 void *bit_buffer() const throw() {
return _bits; }
170 static int _bzl(
unsigned long w)
throw();
189 { __builtin_memcpy(_bits, o._bits,
sizeof(_bits)); }
202 long scan_zero(
long start_bit = 0)
const throw();
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);
247 Bitmap_base::_bzl(
unsigned long w)
throw()
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;
283 template<
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.
void clear_bit(long bit)
Clear bit bit.
word_type operator[](long bit) const
Get the bit at index bit.
long scan_zero(long max_bit, long start_bit=0) const
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.
void set_bit(long bit)
Set bit bit.
unsigned long word_type
Data type for each element of the bit buffer.
static unsigned word_index(unsigned bit)
Get the word index for the given bit.
void bit(long bit, bool on)
Set the value of bit bit to on.
static long words(long bits)
Get the number of Words that are used for the bitmap.
static long chars(long bits)
Get the number of chars that are used for the bitmap.
word_type * _bits
Pointer to the buffer storing the bits.
long scan_zero(long start_bit=0) const
Scan for the first zero bit.
Bitmap()
Create a bitmap with BITS bits.