14 template<
class BMType>
20 template<
class BMType>
24 result._lo = BitMaskType::all_on();
25 result._hi = BitMaskType::all_on();
32 template<
class BMType>
44 template<
class BMType>
49 }
else if (on_bits >= num_bits) {
53 if (on_bits <= half_bits) {
54 result._lo = BitMaskType::lower_on(on_bits);
56 result._lo = BitMaskType::all_on();
57 result._hi = BitMaskType::lower_on(on_bits - half_bits);
65 template<
class BMType>
76 template<
class BMType>
87 template<
class BMType>
97 template<
class BMType>
100 if (index < half_bits) {
101 return _lo.get_bit(index);
103 return _hi.get_bit(index - half_bits);
110 template<
class BMType>
113 if (index < half_bits) {
116 _hi.set_bit(index - half_bits);
123 template<
class BMType>
126 if (index < half_bits) {
127 _lo.clear_bit(index);
129 _hi.clear_bit(index - half_bits);
137 template<
class BMType>
140 if (index < half_bits) {
141 _lo.set_bit_to(index, value);
143 _hi.set_bit_to(index - half_bits, value);
150 template<
class BMType>
153 return (_lo.is_zero() && _hi.is_zero());
159 template<
class BMType>
162 return (_lo.is_all_on() && _hi.is_all_on());
169 template<
class BMType>
172 if (low_bit >= half_bits) {
173 return _hi.extract(low_bit - half_bits, size);
174 }
else if (low_bit + size < half_bits) {
175 return _lo.extract(low_bit, size);
177 int hi_portion = low_bit + size - half_bits;
178 int lo_portion = size - hi_portion;
179 return (_hi.extract(0, hi_portion) << lo_portion) |
180 _lo.extract(low_bit, lo_portion);
188 template<
class BMType>
190 store(WordType value,
int low_bit,
int size) {
191 if (low_bit >= half_bits) {
192 _hi.store(value, low_bit - half_bits, size);
193 }
else if (low_bit + size < half_bits) {
194 _lo.store(value, low_bit, size);
196 int hi_portion = low_bit + size - half_bits;
197 int lo_portion = size - hi_portion;
199 _hi.store(value >> lo_portion, 0, hi_portion);
200 _lo.store(value, low_bit, lo_portion);
207 template<
class BMType>
210 if (low_bit >= half_bits) {
211 return _hi.has_any_of(low_bit - half_bits, size);
212 }
else if (low_bit + size < half_bits) {
213 return _lo.has_any_of(low_bit, size);
215 int hi_portion = low_bit + size - half_bits;
216 int lo_portion = size - hi_portion;
217 return _hi.has_any_of(0, hi_portion)
218 || _lo.has_any_of(low_bit, lo_portion);
225 template<
class BMType>
228 if (low_bit >= half_bits) {
229 return _hi.has_all_of(low_bit - half_bits, size);
230 }
else if (low_bit + size < half_bits) {
231 return _lo.has_all_of(low_bit, size);
233 int hi_portion = low_bit + size - half_bits;
234 int lo_portion = size - hi_portion;
235 return _hi.has_all_of(0, hi_portion)
236 && _lo.has_all_of(low_bit, lo_portion);
243 template<
class BMType>
246 if (low_bit >= half_bits) {
247 _hi.set_range(low_bit - half_bits, size);
248 }
else if (low_bit + size < half_bits) {
249 _lo.set_range(low_bit, size);
251 int hi_portion = low_bit + size - half_bits;
252 int lo_portion = size - hi_portion;
254 _hi.set_range(0, hi_portion);
255 _lo.set_range(low_bit, lo_portion);
262 template<
class BMType>
265 if (low_bit >= half_bits) {
266 _hi.clear_range(low_bit - half_bits, size);
267 }
else if (low_bit + size < half_bits) {
268 _lo.clear_range(low_bit, size);
270 int hi_portion = low_bit + size - half_bits;
271 int lo_portion = size - hi_portion;
273 _hi.clear_range(0, hi_portion);
274 _lo.clear_range(low_bit, lo_portion);
281 template<
class BMType>
285 set_range(low_bit, size);
287 clear_range(low_bit, size);
294 template<
class BMType>
297 return _lo.get_num_on_bits() + _hi.get_num_on_bits();
303 template<
class BMType>
306 return _lo.get_num_off_bits() + _hi.get_num_off_bits();
313 template<
class BMType>
316 int result = _lo.get_lowest_on_bit();
318 result = _hi.get_lowest_on_bit();
330 template<
class BMType>
333 int result = _lo.get_lowest_off_bit();
335 result = _hi.get_lowest_off_bit();
347 template<
class BMType>
350 int result = _hi.get_highest_on_bit();
352 result = _lo.get_highest_on_bit();
363 template<
class BMType>
366 int result = _hi.get_highest_off_bit();
368 result = _lo.get_highest_off_bit();
382 template<
class BMType>
385 if (low_bit > half_bits) {
386 return _hi.get_next_higher_different_bit(low_bit - half_bits) + half_bits;
388 int result = _lo.get_next_higher_different_bit(low_bit);
389 if (result != low_bit) {
392 if (_lo.get_bit(low_bit)) {
393 result = _hi.get_lowest_off_bit();
395 result = _hi.get_lowest_on_bit();
400 return result + half_bits;
407 template<
class BMType>
410 _lo.invert_in_place();
411 _hi.invert_in_place();
422 template<
class BMType>
425 return _lo.has_bits_in_common(other._lo) ||
426 _hi.has_bits_in_common(other._hi);
432 template<
class BMType>
443 template<
class BMType>
453 template<
class BMType>
456 _hi.output_binary(out);
458 _lo.output_binary(out);
465 template<
class BMType>
477 template<
class BMType>
479 write(std::ostream &out,
int indent_level)
const {
480 indent(out, indent_level) << *
this <<
"\n";
486 template<
class BMType>
489 return _lo == other._lo && _hi == other._hi;
495 template<
class BMType>
498 return _lo != other._lo && _hi != other._hi;
508 template<
class BMType>
511 int cmp = _hi.compare_to(other._hi);
515 return _lo < other._lo;
524 template<
class BMType>
527 int cmp = _hi.compare_to(other._hi);
531 return _lo.compare_to(other._lo);
537 template<
class BMType>
548 template<
class BMType>
559 template<
class BMType>
570 template<
class BMType>
574 result.invert_in_place();
581 template<
class BMType>
592 template<
class BMType>
603 template<
class BMType>
613 template<
class BMType>
623 template<
class BMType>
633 template<
class BMType>
636 _hi = (_hi << shift) | ((_lo >> (half_bits - shift)) & BitMaskType::lower_on(shift));
643 template<
class BMType>
646 _lo = (_lo >> shift) | ((_hi & BitMaskType::lower_on(shift)) << (half_bits - shift));
653 template<
class BMType>
656 _hi.generate_hash(hashgen);
657 _lo.generate_hash(hashgen);
663 template<
class BMType>
666 std::ostringstream str;
667 str <<
"DoubleBitMask" << num_bits;
bool is_all_on() const
Returns true if the entire doubleBitMask is one, false otherwise.
void output_binary(std::ostream &out, int spaces_every=4) const
Writes the DoubleBitMask out as a binary number, with spaces every four bits.
This is a specific kind of HashGenerator that simply adds up all of the ints.
void clear_range(int low_bit, int size)
Sets the indicated range of bits off.
static DoubleBitMask< BMType > range(int low_bit, int size)
Returns a DoubleBitMask whose size bits, beginning at low_bit, are on.
constexpr int get_num_bits() const
Returns the number of bits available to set in the doubleBitMask.
bool operator<(const DoubleBitMask< BMType > &other) const
The ordering operator is of limited usefulness with a DoubleBitMask, however, it has a definition whi...
int get_lowest_on_bit() const
Returns the index of the lowest 1 bit in the mask.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
void set_range_to(bool value, int low_bit, int size)
Sets the indicated range of bits to either on or off.
void generate_hash(ChecksumHashGenerator &hashgen) const
Adds the doubleBitMask to the indicated hash generator.
int get_highest_on_bit() const
Returns the index of the highest 1 bit in the mask.
This is a special BitMask type that is implemented as a pair of lesser BitMask types,...
void write(std::ostream &out, int indent_level=0) const
Writes the DoubleBitMask out as a binary or a hex number, according to the number of bits.
void store(WordType value, int low_bit, int size)
Stores the indicated word into the indicated range of bits with this DoubleBitMask.
bool has_any_of(int low_bit, int size) const
Returns true if any bit in the indicated range is set, false otherwise.
void clear_bit(int index)
Sets the nth bit off.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
int get_next_higher_different_bit(int low_bit) const
Returns the index of the next bit in the mask, above low_bit, whose value is different that the value...
static DoubleBitMask< BMType > lower_on(int on_bits)
Returns a DoubleBitMask whose lower on_bits bits are on.
bool get_bit(int index) const
Returns true if the nth bit is set, false if it is cleared.
int get_lowest_off_bit() const
Returns the index of the lowest 0 bit in the mask.
void output(std::ostream &out) const
Writes the DoubleBitMask out as a binary or a hex number, according to the number of bits.
void set_range(int low_bit, int size)
Sets the indicated range of bits on.
WordType extract(int low_bit, int size) const
Returns a word that represents only the indicated range of bits within this DoubleBitMask,...
void clear()
Sets all the bits in the DoubleBitMask off.
void set_bit_to(int index, bool value)
Sets the nth bit either on or off, according to the indicated bool value.
int get_num_off_bits() const
Returns the number of bits that are set to 0 in the mask.
void set_bit(int index)
Sets the nth bit on.
static DoubleBitMask< BMType > all_on()
Returns a DoubleBitMask whose bits are all on.
bool is_zero() const
Returns true if the entire doubleBitMask is zero, false otherwise.
void output_hex(std::ostream &out, int spaces_every=4) const
Writes the DoubleBitMask out as a hexadecimal number, with spaces every four digits.
static DoubleBitMask< BMType > bit(int index)
Returns a DoubleBitMask with only the indicated bit on.
int get_num_on_bits() const
Returns the number of bits that are set to 1 in the mask.
TypeHandle is the identifier used to differentiate C++ class types.
int compare_to(const DoubleBitMask< BMType > &other) const
Returns a number less than zero if this DoubleBitMask sorts before the indicated other DoubleBitMask,...
void invert_in_place()
Inverts all the bits in the DoubleBitMask.
int get_highest_off_bit() const
Returns the index of the highest 0 bit in the mask.
bool has_bits_in_common(const DoubleBitMask< BMType > &other) const
Returns true if this DoubleBitMask has any "one" bits in common with the other one,...
static DoubleBitMask< BMType > all_off()
Returns a DoubleBitMask whose bits are all off.
bool has_all_of(int low_bit, int size) const
Returns true if all bits in the indicated range are set, false otherwise.