14 template<
class WType,
int nbits>
20 template<
class WType,
int nbits>
30 template<
class WType,
int nbits>
34 result._word = (WordType)~0;
41 template<
class WType,
int nbits>
52 template<
class WType,
int nbits>
57 }
else if (on_bits >= num_bits) {
61 result._word = ((WordType)1 << on_bits) - 1;
68 template<
class WType,
int nbits>
79 template<
class WType,
int nbits>
85 }
else if (size >= num_bits) {
86 result._word = (WordType)~0;
88 result._word = ((WordType)1 << size) - 1;
90 result._word <<= low_bit;
97 template<
class WType,
int nbits>
107 template<
class WType,
int nbits>
110 nassertr(index >= 0 && index < num_bits,
false);
111 return (_word & ((WordType)1 << index)) != 0;
117 template<
class WType,
int nbits>
120 nassertv(index >= 0 && index < num_bits);
121 _word |= ((WordType)1 << index);
127 template<
class WType,
int nbits>
130 nassertv(index >= 0 && index < num_bits);
131 _word &= ~((WordType)1 << index);
138 template<
class WType,
int nbits>
151 template<
class WType,
int nbits>
160 template<
class WType,
int nbits>
163 return _word == (WordType)~0;
170 template<
class WType,
int nbits>
173 return (_word >> low_bit) &
181 template<
class WType,
int nbits>
183 store(WordType value,
int low_bit,
int size) {
185 _word = (_word & ~mask) | ((value << low_bit) & mask);
191 template<
class WType,
int nbits>
195 return (_word & mask) != 0;
201 template<
class WType,
int nbits>
205 return (_word & mask) == mask;
211 template<
class WType,
int nbits>
221 template<
class WType,
int nbits>
231 template<
class WType,
int nbits>
235 set_range(low_bit, size);
237 clear_range(low_bit, size);
244 template<
class WType,
int nbits>
253 template<
class WType,
int nbits>
262 template<
class WType,
int nbits>
271 template<
class WType,
int nbits>
281 template<
class WType,
int nbits>
291 template<
class WType,
int nbits>
294 return (~(*
this)).get_lowest_on_bit();
301 template<
class WType,
int nbits>
311 template<
class WType,
int nbits>
314 return (~(*
this)).get_highest_on_bit();
324 template<
class WType,
int nbits>
329 nassertr(low_bit >= 0, low_bit);
330 if (low_bit >= num_bits) {
334 WordType is_on = (_word & ((WordType)1 << low_bit));
348 w &= ~(((WordType)1 << low_bit) - 1);
355 return is_on ? num_bits : low_bit;
370 template<
class WType,
int nbits>
384 template<
class WType,
int nbits>
387 return (_word & other._word) != 0;
393 template<
class WType,
int nbits>
403 template<
class WType,
int nbits>
406 if (num_bits >= 40) {
416 template<
class WType,
int nbits>
419 for (
int i = num_bits - 1; i >= 0; i--) {
420 if (spaces_every != 0 && ((i % spaces_every) == spaces_every - 1)) {
423 out << (get_bit(i) ?
'1' :
'0');
431 template<
class WType,
int nbits>
434 int num_digits = (num_bits + 3) / 4;
436 for (
int i = num_digits - 1; i >= 0; i--) {
437 WordType digit = extract(i * 4, 4);
438 if (spaces_every != 0 && ((i % spaces_every) == spaces_every - 1)) {
442 out << (char)(digit - 10 +
'a');
444 out << (char)(digit +
'0');
453 template<
class WType,
int nbits>
455 write(std::ostream &out,
int indent_level)
const {
456 indent(out, indent_level) << *
this <<
"\n";
462 template<
class WType,
int nbits>
465 return _word == other._word;
471 template<
class WType,
int nbits>
474 return _word != other._word;
484 template<
class WType,
int nbits>
487 return _word < other._word;
495 template<
class WType,
int nbits>
498 if ((*
this) < other) {
500 }
else if (other < (*
this)) {
510 template<
class WType,
int nbits>
521 template<
class WType,
int nbits>
532 template<
class WType,
int nbits>
543 template<
class WType,
int nbits>
552 template<
class WType,
int nbits>
563 template<
class WType,
int nbits>
574 template<
class WType,
int nbits>
577 _word &= other._word;
583 template<
class WType,
int nbits>
586 _word |= other._word;
592 template<
class WType,
int nbits>
595 _word ^= other._word;
601 template<
class WType,
int nbits>
610 template<
class WType,
int nbits>
620 template<
class WType,
int nbits>
629 template<
class WType,
int nbits>
638 template<
class WType,
int nbits>
647 template<
class WType,
int nbits>
656 template<
class WType,
int nbits>
665 template<
class WType,
int nbits>
674 template<
class WType,
int nbits>
684 template<
class WType,
int nbits>
696 template<
class WType,
int nbits>
711 template<
class WType,
int nbits>
726 template<
class WType,
int nbits>
730 nassertr(index >= 0 && index < num_bits, mask);
750 template<
class WType,
int nbits>
754 nassertr(index >= 0 && index < num_bits, mask);
775 template<
class WType,
int nbits>
780 return keep_next_highest_bit(high_bit);
782 return keep_next_highest_bit();
791 template<
class WType,
int nbits>
796 return keep_next_lowest_bit(low_bit);
798 return keep_next_lowest_bit();
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.
uint16_t flood_bits_up(uint16_t x)
Returns a value such that every bit at or above the highest bit in x is 1.
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 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 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 register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
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...
void write(std::ostream &out, int indent_level=0) const
Writes the BitMask out as a binary or a hex number, according to the number of bits.
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,...
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.
constexpr int get_num_bits() const
Returns the number of bits available to set in the bitmask.
static BitMask< WType, nbits > all_off()
Returns a BitMask whose bits are all off.
int get_lowest_on_bit(uint16_t x)
Returns the index of the lowest 1 bit in the word.
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.
void output_hex(std::ostream &out, int spaces_every=4) const
Writes the BitMask out as a hexadecimal number, with spaces every four digits.
int get_highest_on_bit(uint16_t x)
Returns the index of the highest 1 bit in the word.
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.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
WordType extract(int low_bit, int size) const
Returns a word that represents only the indicated range of bits within this BitMask,...
void output(std::ostream &out) const
Writes the BitMask out as a binary or a hex number, according to the number of bits.
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.
uint16_t flood_bits_down(uint16_t x)
Returns a value such that every bit at or below the highest bit in x is 1.
bool has_all_of(int low_bit, int size) const
Returns true if all bits in the indicated range are set, false otherwise.
void output_binary(std::ostream &out, int spaces_every=4) const
Writes the BitMask out as a binary number, with spaces every four bits.
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.
int count_bits_in_word(uint16_t x)
Returns the number of 1 bits in the indicated word.
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.