15 template<
class BMType>
23 template<
class BMType>
33 template<
class BMType>
46 template<
class BMType>
59 template<
class BMType>
63 result._lo = BitMaskType::all_on();
64 result._hi = BitMaskType::all_on();
73 template<
class BMType>
87 template<
class BMType>
92 }
else if (on_bits >= num_bits) {
96 if (on_bits <= half_bits) {
97 result._lo = BitMaskType::lower_on(on_bits);
99 result._lo = BitMaskType::all_on();
100 result._hi = BitMaskType::lower_on(on_bits - half_bits);
110 template<
class BMType>
124 template<
class BMType>
137 template<
class BMType>
154 template<
class BMType>
173 template<
class BMType>
185 template<
class BMType>
198 template<
class BMType>
201 if (index < half_bits) {
202 return _lo.get_bit(index);
204 return _hi.get_bit(index - half_bits);
214 template<
class BMType>
217 if (index < half_bits) {
220 _hi.set_bit(index - half_bits);
230 template<
class BMType>
233 if (index < half_bits) {
234 _lo.clear_bit(index);
236 _hi.clear_bit(index - half_bits);
247 template<
class BMType>
250 if (index < half_bits) {
251 _lo.set_bit_to(index, value);
253 _hi.set_bit_to(index - half_bits, value);
263 template<
class BMType>
266 return (_lo.is_zero() && _hi.is_zero());
275 template<
class BMType>
278 return (_lo.is_all_on() && _hi.is_all_on());
288 template<
class BMType>
291 if (low_bit >= half_bits) {
292 return _hi.extract(low_bit - half_bits, size);
293 }
else if (low_bit + size < half_bits) {
294 return _lo.extract(low_bit, size);
296 int hi_portion = low_bit + size - half_bits;
297 int lo_portion = size - hi_portion;
298 return (_hi.extract(0, hi_portion) << lo_portion) |
299 _lo.extract(low_bit, lo_portion);
309 template<
class BMType>
311 store(WordType value,
int low_bit,
int size) {
312 if (low_bit >= half_bits) {
313 _hi.store(value, low_bit - half_bits, size);
314 }
else if (low_bit + size < half_bits) {
315 _lo.store(value, low_bit, size);
317 int hi_portion = low_bit + size - half_bits;
318 int lo_portion = size - hi_portion;
320 _hi.store(value >> lo_portion, 0, hi_portion);
321 _lo.store(value, low_bit, lo_portion);
331 template<
class BMType>
334 if (low_bit >= half_bits) {
335 return _hi.has_any_of(low_bit - half_bits, size);
336 }
else if (low_bit + size < half_bits) {
337 return _lo.has_any_of(low_bit, size);
339 int hi_portion = low_bit + size - half_bits;
340 int lo_portion = size - hi_portion;
341 return (_hi.has_any_of(0, hi_portion) << lo_portion) ||
342 _lo.has_any_of(low_bit, lo_portion);
352 template<
class BMType>
355 if (low_bit >= half_bits) {
356 return _hi.has_all_of(low_bit - half_bits, size);
357 }
else if (low_bit + size < half_bits) {
358 return _lo.has_all_of(low_bit, size);
360 int hi_portion = low_bit + size - half_bits;
361 int lo_portion = size - hi_portion;
362 return (_hi.has_all_of(0, hi_portion) << lo_portion) &&
363 _lo.has_all_of(low_bit, lo_portion);
372 template<
class BMType>
375 if (low_bit >= half_bits) {
376 _hi.set_range(low_bit - half_bits, size);
377 }
else if (low_bit + size < half_bits) {
378 _lo.set_range(low_bit, size);
380 int hi_portion = low_bit + size - half_bits;
381 int lo_portion = size - hi_portion;
383 _hi.set_range(0, hi_portion);
384 _lo.set_range(low_bit, lo_portion);
393 template<
class BMType>
396 if (low_bit >= half_bits) {
397 _hi.clear_range(low_bit - half_bits, size);
398 }
else if (low_bit + size < half_bits) {
399 _lo.clear_range(low_bit, size);
401 int hi_portion = low_bit + size - half_bits;
402 int lo_portion = size - hi_portion;
404 _hi.clear_range(0, hi_portion);
405 _lo.clear_range(low_bit, lo_portion);
414 template<
class BMType>
418 set_range(low_bit, size);
420 clear_range(low_bit, size);
430 template<
class BMType>
433 return _lo.get_num_on_bits() + _hi.get_num_on_bits();
442 template<
class BMType>
445 return _lo.get_num_off_bits() + _hi.get_num_off_bits();
454 template<
class BMType>
457 int result = _lo.get_lowest_on_bit();
459 result = _hi.get_lowest_on_bit();
473 template<
class BMType>
476 int result = _lo.get_lowest_off_bit();
478 result = _hi.get_lowest_off_bit();
492 template<
class BMType>
495 int result = _hi.get_highest_on_bit();
497 result = _lo.get_highest_on_bit();
510 template<
class BMType>
513 int result = _hi.get_highest_off_bit();
515 result = _lo.get_highest_off_bit();
533 template<
class BMType>
536 if (low_bit > half_bits) {
537 return _hi.get_next_higher_different_bit(low_bit - half_bits) + half_bits;
539 int result = _lo.get_next_higher_different_bit(low_bit);
540 if (result != low_bit) {
543 if (_lo.get_bit(low_bit)) {
544 result = _hi.get_lowest_off_bit();
546 result = _hi.get_lowest_on_bit();
551 return result + half_bits;
560 template<
class BMType>
563 _lo.invert_in_place();
564 _hi.invert_in_place();
578 template<
class BMType>
581 return _lo.has_bits_in_common(other._lo) ||
582 _hi.has_bits_in_common(other._hi);
590 template<
class BMType>
603 template<
class BMType>
615 template<
class BMType>
618 _hi.output_binary(out);
620 _lo.output_binary(out);
629 template<
class BMType>
643 template<
class BMType>
645 write(ostream &out,
int indent_level)
const {
646 indent(out, indent_level) << *
this <<
"\n";
654 template<
class BMType>
657 return _lo == other._lo && _hi == other._hi;
665 template<
class BMType>
668 return _lo != other._lo && _hi != other._hi;
682 template<
class BMType>
685 int cmp = _hi.compare_to(other._hi);
689 return _lo < other._lo;
700 template<
class BMType>
703 int cmp = _hi.compare_to(other._hi);
707 return _lo.compare_to(other._lo);
715 template<
class BMType>
728 template<
class BMType>
741 template<
class BMType>
754 template<
class BMType>
758 result.invert_in_place();
767 template<
class BMType>
780 template<
class BMType>
793 template<
class BMType>
805 template<
class BMType>
817 template<
class BMType>
829 template<
class BMType>
832 _hi = (_hi << shift) | ((_lo >> half_bits - shift) & BitMaskType::lower_on(shift));
841 template<
class BMType>
844 _lo = (_lo >> shift) | ((_hi & BitMaskType::lower_on(shift)) << half_bits - shift);
853 template<
class BMType>
856 _hi.generate_hash(hashgen);
857 _lo.generate_hash(hashgen);
865 template<
class BMType>
869 str <<
"DoubleBitMask" << num_bits;
870 register_type(_type_handle, str.str());
This is a specific kind of HashGenerator that simply adds up all of the ints.
int get_num_off_bits() const
Returns the number of bits that are set to 0 in the mask.
void output_binary(ostream &out, int spaces_every=4) const
Writes the DoubleBitMask out as a binary number, with spaces every four bits.
void clear_range(int low_bit, int size)
Sets the indicated range of bits off.
int get_highest_off_bit() const
Returns the index of the highest 0 bit in the mask.
static DoubleBitMask< BMType > range(int low_bit, int size)
Returns a DoubleBitMask whose size bits, beginning at low_bit, are on.
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, false otherwise.
bool is_all_on() const
Returns true if the entire doubleBitMask is one, false otherwise.
void set_range_to(bool value, int low_bit, int size)
Sets the indicated range of bits to either on or off.
bool has_any_of(int low_bit, int size) const
Returns true if any bit in the indicated range is set, false otherwise.
bool has_all_of(int low_bit, int size) const
Returns true if all bits in the indicated range are set, false otherwise.
This is a special BitMask type that is implemented as a pair of lesser BitMask types, to present a double-wide bit mask.
void output(ostream &out) 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.
int get_highest_on_bit() const
Returns the index of the highest 1 bit in the mask.
int get_num_on_bits() const
Returns the number of bits that are set to 1 in the mask.
void clear_bit(int index)
Sets the nth bit off.
static DoubleBitMask< BMType > lower_on(int on_bits)
Returns a DoubleBitMask whose lower on_bits bits are on.
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 CONSTEXPR int get_max_num_bits()
If get_max_num_bits() returned true, this method may be called to return the maximum number of bits t...
WordType extract(int low_bit, int size) const
Returns a word that represents only the indicated range of bits within this DoubleBitMask, shifted to the least-significant position.
int get_lowest_off_bit() const
Returns the index of the lowest 0 bit in the mask.
void set_range(int low_bit, int size)
Sets the indicated range of bits on.
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.
static CONSTEXPR int get_num_bits()
Returns the number of bits available to set in the doubleBitMask.
int compare_to(const DoubleBitMask< BMType > &other) const
Returns a number less than zero if this DoubleBitMask sorts before the indicated other DoubleBitMask...
int get_lowest_on_bit() const
Returns the index of the lowest 1 bit 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.
static DoubleBitMask< BMType > bit(int index)
Returns a DoubleBitMask with only the indicated bit on.
void generate_hash(ChecksumHashGenerator &hashgen) const
Adds the doubleBitMask to the indicated hash generator.
bool is_zero() const
Returns true if the entire doubleBitMask is zero, false otherwise.
bool get_bit(int index) const
Returns true if the nth bit is set, false if it is cleared.
TypeHandle is the identifier used to differentiate C++ class types.
bool operator<(const DoubleBitMask< BMType > &other) const
The ordering operator is of limited usefulness with a DoubleBitMask, however, it has a definition whi...
static CONSTEXPR bool has_max_num_bits()
Returns true if there is a maximum number of bits that may be stored in this structure, false otherwise.
void invert_in_place()
Inverts all the bits in the DoubleBitMask.
static DoubleBitMask< BMType > all_off()
Returns a DoubleBitMask whose bits are all off.
void output_hex(ostream &out, int spaces_every=4) const
Writes the DoubleBitMask out as a hexadecimal number, with spaces every four digits.
void write(ostream &out, int indent_level=0) const
Writes the DoubleBitMask out as a binary or a hex number, according to the number of bits...