15 template<
class WType,
int nbits>
23 template<
class WType,
int nbits>
35 template<
class WType,
int nbits>
47 template<
class WType,
int nbits>
59 template<
class WType,
int nbits>
71 template<
class WType,
int nbits>
75 result._word = (WordType)~0;
84 template<
class WType,
int nbits>
97 template<
class WType,
int nbits>
102 }
else if (on_bits >= num_bits) {
106 result._word = ((WordType)1 << on_bits) - 1;
115 template<
class WType,
int nbits>
129 template<
class WType,
int nbits>
135 }
else if (size >= num_bits) {
136 result._word = (WordType)~0;
138 result._word = ((WordType)1 << size) - 1;
140 result._word <<= low_bit;
149 template<
class WType,
int nbits>
166 template<
class WType,
int nbits>
185 template<
class WType,
int nbits>
197 template<
class WType,
int nbits>
210 template<
class WType,
int nbits>
213 nassertr(index >= 0 && index < num_bits,
false);
214 return (_word & ((WordType)1 << index)) != 0;
223 template<
class WType,
int nbits>
226 nassertv(index >= 0 && index < num_bits);
227 _word |= ((WordType)1 << index);
236 template<
class WType,
int nbits>
239 nassertv(index >= 0 && index < num_bits);
240 _word &= ~((WordType)1 << index);
250 template<
class WType,
int nbits>
266 template<
class WType,
int nbits>
278 template<
class WType,
int nbits>
281 return (~_word == 0);
291 template<
class WType,
int nbits>
294 return (_word >> low_bit) &
304 template<
class WType,
int nbits>
306 store(WordType value,
int low_bit,
int size) {
308 _word = (_word & ~mask) | ((value << low_bit) & mask);
317 template<
class WType,
int nbits>
321 return (_word & mask) != 0;
330 template<
class WType,
int nbits>
334 return (_word & mask) == mask;
342 template<
class WType,
int nbits>
354 template<
class WType,
int nbits>
366 template<
class WType,
int nbits>
381 template<
class WType,
int nbits>
393 template<
class WType,
int nbits>
405 template<
class WType,
int nbits>
408 return count_bits_in_word((WType)_word);
417 template<
class WType,
int nbits>
420 return count_bits_in_word((WType)(~_word));
429 template<
class WType,
int nbits>
432 return ::get_lowest_on_bit(_word);
441 template<
class WType,
int nbits>
444 return (~(*
this)).get_lowest_on_bit();
453 template<
class WType,
int nbits>
456 return ::get_highest_on_bit(_word);
465 template<
class WType,
int nbits>
468 return (~(*
this)).get_highest_on_bit();
482 template<
class WType,
int nbits>
487 nassertr(low_bit >= 0, low_bit);
488 if (low_bit >= num_bits) {
492 WordType is_on = (_word & ((WordType)1 << low_bit));
506 w &= ~(((WordType)1 << low_bit) - 1);
513 return is_on ? num_bits : low_bit;
521 return count_bits_in_word((WType)(w - 1));
531 template<
class WType,
int nbits>
548 template<
class WType,
int nbits>
551 return (_word & other._word) != 0;
559 template<
class WType,
int nbits>
571 template<
class WType,
int nbits>
574 if (num_bits >= 40) {
587 template<
class WType,
int nbits>
590 for (
int i = num_bits - 1; i >= 0; i--) {
591 if (spaces_every != 0 && ((i % spaces_every) == spaces_every - 1)) {
594 out << (
get_bit(i) ?
'1' :
'0');
604 template<
class WType,
int nbits>
607 int num_digits = (num_bits + 3) / 4;
609 for (
int i = num_digits - 1; i >= 0; i--) {
610 WordType digit =
extract(i * 4, 4);
611 if (spaces_every != 0 && ((i % spaces_every) == spaces_every - 1)) {
615 out << (char)(digit - 10 +
'a');
617 out << (char)(digit +
'0');
628 template<
class WType,
int nbits>
630 write(ostream &out,
int indent_level)
const {
631 indent(out, indent_level) << *
this <<
"\n";
639 template<
class WType,
int nbits>
642 return _word == other._word;
650 template<
class WType,
int nbits>
653 return _word != other._word;
667 template<
class WType,
int nbits>
670 return _word < other._word;
681 template<
class WType,
int nbits>
684 if ((*
this) < other) {
686 }
else if (other < (*
this)) {
698 template<
class WType,
int nbits>
711 template<
class WType,
int nbits>
724 template<
class WType,
int nbits>
737 template<
class WType,
int nbits>
748 template<
class WType,
int nbits>
761 template<
class WType,
int nbits>
774 template<
class WType,
int nbits>
777 _word &= other._word;
785 template<
class WType,
int nbits>
788 _word |= other._word;
796 template<
class WType,
int nbits>
799 _word ^= other._word;
807 template<
class WType,
int nbits>
818 template<
class WType,
int nbits>
830 template<
class WType,
int nbits>
841 template<
class WType,
int nbits>
852 template<
class WType,
int nbits>
863 template<
class WType,
int nbits>
867 str <<
"BitMask" << num_bits;
868 register_type(_type_handle, str.str());
876 template<
class WType,
int nbits>
887 template<
class WType,
int nbits>
898 template<
class WType,
int nbits>
910 template<
class WType,
int nbits>
924 template<
class WType,
int nbits>
941 template<
class WType,
int nbits>
958 template<
class WType,
int nbits>
962 nassertr(index >= 0 && index < num_bits, mask);
984 template<
class WType,
int nbits>
988 nassertr(index >= 0 && index < num_bits, mask);
1012 template<
class WType,
int nbits>
1016 if (high_bit >= 0) {
1031 template<
class WType,
int nbits>
void clear_bit(int index)
Sets the nth bit off.
static BitMask< WType, nbits > bit(int index)
Returns a BitMask with only the indicated bit on.
void flood_down_in_place()
Floods this bitmask's bits downwards.
int get_highest_off_bit() const
Returns the index of the highest 0 bit in the mask.
bool has_any_of(int low_bit, int size) const
Returns true if any bit in the indicated range is set, false otherwise.
This is a specific kind of HashGenerator that simply adds up all of the ints.
BitMask< WType, nbits > flood_bits_down() const
Returns a BitMask with the bits flooded down.
void output_binary(ostream &out, int spaces_every=4) const
Writes the BitMask out as a binary number, with spaces every four bits.
void invert_in_place()
Inverts all the bits in the BitMask.
static BitMask< WType, nbits > all_on()
Returns a BitMask whose bits are all on.
void output(ostream &out) const
Writes the BitMask out as a binary or a hex number, according to the number of bits.
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...
void set_range(int low_bit, int size)
Sets the indicated range of bits on.
void clear()
Sets all the bits in the BitMask off.
void store(WordType value, int low_bit, int size)
Stores the indicated word into the indicated range of bits with this BitMask.
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...
bool operator<(const BitMask< WType, nbits > &other) const
The ordering operator is of limited usefulness with a BitMask, however, it has a definition which pla...
int get_lowest_off_bit() const
Returns the index of the lowest 0 bit in the mask.
bool __nonzero__() const
Returns true if the bitmask is not zero.
int compare_to(const BitMask< WType, nbits > &other) const
Returns a number less than zero if this BitMask sorts before the indicated other BitMask, greater than zero if it sorts after, or 0 if they are equivalent.
BitMask< WType, nbits > keep_next_highest_bit() const
Returns a BitMask with only the next highest bit above the indicated bit on, or all_off.
static BitMask< WType, nbits > all_off()
Returns a BitMask whose bits are all off.
void output_hex(ostream &out, int spaces_every=4) const
Writes the BitMask out as a hexadecimal number, with spaces every four digits.
void write(ostream &out, int indent_level=0) const
Writes the BitMask out as a binary or a hex number, according to the number of bits.
int get_num_off_bits() const
Returns the number of bits that are set to 0 in the mask.
void set_word(WordType value)
Sets the entire BitMask to the value indicated by the given word.
static BitMask< WType, nbits > range(int low_bit, int size)
Returns a BitMask whose size bits, beginning at low_bit, are on.
void flood_up_in_place()
Floods this bitmask's bits upwards.
void clear_range(int low_bit, int size)
Sets the indicated range of bits off.
bool is_all_on() const
Returns true if the entire bitmask is one, false otherwise.
WordType get_word() const
Returns the entire BitMask as a single word.
bool get_bit(int index) const
Returns true if the nth bit is set, false if it is cleared.
static BitMask< WType, nbits > lower_on(int on_bits)
Returns a BitMask whose lower on_bits bits are on.
void generate_hash(ChecksumHashGenerator &hashgen) const
Adds the bitmask to the indicated hash generator.
int get_lowest_on_bit() const
Returns the index of the lowest 1 bit in the mask.
void set_bit_to(int index, bool value)
Sets the nth bit either on or off, according to the indicated bool value.
WordType extract(int low_bit, int size) const
Returns a word that represents only the indicated range of bits within this BitMask, shifted to the least-significant position.
bool has_bits_in_common(const BitMask< WType, nbits > &other) const
Returns true if this BitMask has any "one" bits in common with the other one, false otherwise...
BitMask< WType, nbits > flood_bits_up() const
Returns a BitMask with the bits flooded upwards.
void set_range_to(bool value, int low_bit, int size)
Sets the indicated range of bits to either on or off.
int get_highest_on_bit() const
Returns the index of the highest 1 bit in the mask.
void add_int(long num)
Adds another integer to the hash so far.
void set_bit(int index)
Sets the nth bit on.
bool has_all_of(int low_bit, int size) const
Returns true if all bits in the indicated range are set, false otherwise.
static CONSTEXPR int get_num_bits()
Returns the number of bits available to set in the bitmask.
int get_key() const
Returns a mostly unique integer key per unique bitmask, suitable for using in a hash table...
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.
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.
bool is_zero() const
Returns true if the entire bitmask is zero, false otherwise.
BitMask< WType, nbits > keep_next_lowest_bit() const
Returns a BitMask with only the next lower bit below the indicated bit on, or all_off.