Panda3D
bitMask.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file bitMask.I
10  * @author drose
11  * @date 2000-06-08
12  */
13 
14 template<class WType, int nbits>
16 
17 /**
18  *
19  */
20 template<class WType, int nbits>
22 BitMask(WordType init_value) :
23  _word(init_value)
24 {
25 }
26 
27 /**
28  * Returns a BitMask whose bits are all on.
29  */
30 template<class WType, int nbits>
32 all_on() {
33  BitMask result;
34  result._word = (WordType)~0;
35  return result;
36 }
37 
38 /**
39  * Returns a BitMask whose bits are all off.
40  */
41 template<class WType, int nbits>
44  BitMask result;
45  result._word = 0;
46  return result;
47 }
48 
49 /**
50  * Returns a BitMask whose lower on_bits bits are on.
51  */
52 template<class WType, int nbits>
54 lower_on(int on_bits) {
55  if (on_bits <= 0) {
56  return all_off();
57  } else if (on_bits >= num_bits) {
58  return all_on();
59  }
60  BitMask result;
61  result._word = ((WordType)1 << on_bits) - 1;
62  return result;
63 }
64 
65 /**
66  * Returns a BitMask with only the indicated bit on.
67  */
68 template<class WType, int nbits>
70 bit(int index) {
71  BitMask result;
72  result.set_bit(index);
73  return result;
74 }
75 
76 /**
77  * Returns a BitMask whose size bits, beginning at low_bit, are on.
78  */
79 template<class WType, int nbits>
81 range(int low_bit, int size) {
82  BitMask result;
83  if (size <= 0) {
84  result._word = 0;
85  } else if (size >= num_bits) {
86  result._word = (WordType)~0;
87  } else {
88  result._word = ((WordType)1 << size) - 1;
89  }
90  result._word <<= low_bit;
91  return result;
92 }
93 
94 /**
95  * Returns the number of bits available to set in the bitmask.
96  */
97 template<class WType, int nbits>
98 constexpr int BitMask<WType, nbits>::
99 get_num_bits() const {
100  return num_bits;
101 }
102 
103 /**
104  * Returns true if the nth bit is set, false if it is cleared. index must be
105  * in the range [0, num_bits).
106  */
107 template<class WType, int nbits>
108 INLINE bool BitMask<WType, nbits>::
109 get_bit(int index) const {
110  nassertr(index >= 0 && index < num_bits, false);
111  return (_word & ((WordType)1 << index)) != 0;
112 }
113 
114 /**
115  * Sets the nth bit on. index must be in the range [0, num_bits).
116  */
117 template<class WType, int nbits>
118 INLINE void BitMask<WType, nbits>::
119 set_bit(int index) {
120  nassertv(index >= 0 && index < num_bits);
121  _word |= ((WordType)1 << index);
122 }
123 
124 /**
125  * Sets the nth bit off. index must be in the range [0, num_bits).
126  */
127 template<class WType, int nbits>
128 INLINE void BitMask<WType, nbits>::
129 clear_bit(int index) {
130  nassertv(index >= 0 && index < num_bits);
131  _word &= ~((WordType)1 << index);
132 }
133 
134 /**
135  * Sets the nth bit either on or off, according to the indicated bool value.
136  * index must be in the range [0, num_bits).
137  */
138 template<class WType, int nbits>
139 INLINE void BitMask<WType, nbits>::
140 set_bit_to(int index, bool value) {
141  if (value) {
142  set_bit(index);
143  } else {
144  clear_bit(index);
145  }
146 }
147 
148 /**
149  * Returns true if the entire bitmask is zero, false otherwise.
150  */
151 template<class WType, int nbits>
152 INLINE bool BitMask<WType, nbits>::
153 is_zero() const {
154  return (_word == 0);
155 }
156 
157 /**
158  * Returns true if the entire bitmask is one, false otherwise.
159  */
160 template<class WType, int nbits>
161 INLINE bool BitMask<WType, nbits>::
162 is_all_on() const {
163  return _word == (WordType)~0;
164 }
165 
166 /**
167  * Returns a word that represents only the indicated range of bits within this
168  * BitMask, shifted to the least-significant position.
169  */
170 template<class WType, int nbits>
171 INLINE typename BitMask<WType, nbits>::WordType BitMask<WType, nbits>::
172 extract(int low_bit, int size) const {
173  return (_word >> low_bit) &
175 }
176 
177 /**
178  * Stores the indicated word into the indicated range of bits with this
179  * BitMask.
180  */
181 template<class WType, int nbits>
182 INLINE void BitMask<WType, nbits>::
183 store(WordType value, int low_bit, int size) {
184  WordType mask = BitMask<WType, nbits>::range(low_bit, size)._word;
185  _word = (_word & ~mask) | ((value << low_bit) & mask);
186 }
187 
188 /**
189  * Returns true if any bit in the indicated range is set, false otherwise.
190  */
191 template<class WType, int nbits>
192 INLINE bool BitMask<WType, nbits>::
193 has_any_of(int low_bit, int size) const {
194  WordType mask = BitMask<WType, nbits>::range(low_bit, size)._word;
195  return (_word & mask) != 0;
196 }
197 
198 /**
199  * Returns true if all bits in the indicated range are set, false otherwise.
200  */
201 template<class WType, int nbits>
202 INLINE bool BitMask<WType, nbits>::
203 has_all_of(int low_bit, int size) const {
204  WordType mask = BitMask<WType, nbits>::range(low_bit, size)._word;
205  return (_word & mask) == mask;
206 }
207 
208 /**
209  * Sets the indicated range of bits on.
210  */
211 template<class WType, int nbits>
212 INLINE void BitMask<WType, nbits>::
213 set_range(int low_bit, int size) {
214  WordType mask = BitMask<WType, nbits>::range(low_bit, size)._word;
215  _word |= mask;
216 }
217 
218 /**
219  * Sets the indicated range of bits off.
220  */
221 template<class WType, int nbits>
222 INLINE void BitMask<WType, nbits>::
223 clear_range(int low_bit, int size) {
224  WordType mask = BitMask<WType, nbits>::range(low_bit, size)._word;
225  _word &= ~mask;
226 }
227 
228 /**
229  * Sets the indicated range of bits to either on or off.
230  */
231 template<class WType, int nbits>
232 INLINE void BitMask<WType, nbits>::
233 set_range_to(bool value, int low_bit, int size) {
234  if (value) {
235  set_range(low_bit, size);
236  } else {
237  clear_range(low_bit, size);
238  }
239 }
240 
241 /**
242  * Returns the entire BitMask as a single word.
243  */
244 template<class WType, int nbits>
245 INLINE typename BitMask<WType, nbits>::WordType BitMask<WType, nbits>::
246 get_word() const {
247  return _word;
248 }
249 
250 /**
251  * Sets the entire BitMask to the value indicated by the given word.
252  */
253 template<class WType, int nbits>
254 INLINE void BitMask<WType, nbits>::
255 set_word(WordType value) {
256  _word = value;
257 }
258 
259 /**
260  * Returns the number of bits that are set to 1 in the mask.
261  */
262 template<class WType, int nbits>
263 INLINE int BitMask<WType, nbits>::
265  return count_bits_in_word((WType)_word);
266 }
267 
268 /**
269  * Returns the number of bits that are set to 0 in the mask.
270  */
271 template<class WType, int nbits>
272 INLINE int BitMask<WType, nbits>::
274  return count_bits_in_word((WType)(~_word));
275 }
276 
277 /**
278  * Returns the index of the lowest 1 bit in the mask. Returns -1 if there are
279  * no 1 bits.
280  */
281 template<class WType, int nbits>
282 INLINE int BitMask<WType, nbits>::
285 }
286 
287 /**
288  * Returns the index of the lowest 0 bit in the mask. Returns -1 if there are
289  * no 0 bits.
290  */
291 template<class WType, int nbits>
292 INLINE int BitMask<WType, nbits>::
294  return (~(*this)).get_lowest_on_bit();
295 }
296 
297 /**
298  * Returns the index of the highest 1 bit in the mask. Returns -1 if there
299  * are no 1 bits.
300  */
301 template<class WType, int nbits>
302 INLINE int BitMask<WType, nbits>::
305 }
306 
307 /**
308  * Returns the index of the highest 0 bit in the mask. Returns -1 if there
309  * are no 0 bits.
310  */
311 template<class WType, int nbits>
312 INLINE int BitMask<WType, nbits>::
314  return (~(*this)).get_highest_on_bit();
315 }
316 
317 /**
318  * Returns the index of the next bit in the mask, above low_bit, whose value
319  * is different that the value of low_bit. Returns low_bit again if all bits
320  * higher than low_bit have the same value.
321  *
322  * This can be used to quickly iterate through all of the bits in the mask.
323  */
324 template<class WType, int nbits>
325 INLINE int BitMask<WType, nbits>::
326 get_next_higher_different_bit(int low_bit) const {
327  // We are allowed to call this method with low_bit == num_bits, which is the
328  // highest value this method will return.
329  nassertr(low_bit >= 0, low_bit);
330  if (low_bit >= num_bits) {
331  return low_bit;
332  }
333 
334  WordType is_on = (_word & ((WordType)1 << low_bit));
335  WordType w;
336  if (is_on) {
337  // low_bit is 1. Get the next higher 0 bit. To do this, invert the word
338  // and the get the next higher 1 bit.
339  w = ~_word;
340  } else {
341  // low_bit is 0. Get the next higher 1 bit.
342  w = _word;
343  }
344 
345  // Mask out all of the bits below low_bit. Since we already know that
346  // low_bit is 0, we can use (1 << low_bit) instead of (1 << (low_bit + 1)),
347  // which becomes undefined when (low_bit + 1) == 32.
348  w &= ~(((WordType)1 << low_bit) - 1);
349 
350  if (w == 0) {
351  // All higher bits in the word have the same value. Since every bit after
352  // the topmost bit is 0, we either return the topmost bit + 1 to indicate
353  // the next 0 bit, or low_bit to indicate we have reached the end of the
354  // number of bits.
355  return is_on ? num_bits : low_bit;
356 
357  } else {
358  // Now determine the lowest 1 bit in the remaining word. This operation
359  // will clear out all bits except for the lowest 1 bit.
360  w = (w & (~w + 1));
361 
362  // And the answer is the number of bits in (w - 1).
363  return count_bits_in_word((WType)(w - 1));
364  }
365 }
366 
367 /**
368  * Inverts all the bits in the BitMask. This is equivalent to mask = ~mask.
369  */
370 template<class WType, int nbits>
371 INLINE void BitMask<WType, nbits>::
373  _word = ~_word;
374 }
375 
376 /**
377  * Returns true if this BitMask has any "one" bits in common with the other
378  * one, false otherwise.
379  *
380  * This is equivalent to (mask & other) != 0, but may be faster. (Actually,
381  * it should only be faster in the BitArray case, but this method is provided
382  * for the benefit of generic programming algorithms).
383  */
384 template<class WType, int nbits>
385 INLINE bool BitMask<WType, nbits>::
387  return (_word & other._word) != 0;
388 }
389 
390 /**
391  * Sets all the bits in the BitMask off.
392  */
393 template<class WType, int nbits>
394 INLINE void BitMask<WType, nbits>::
395 clear() {
396  _word = 0;
397 }
398 
399 /**
400  * Writes the BitMask out as a binary or a hex number, according to the number
401  * of bits.
402  */
403 template<class WType, int nbits>
405 output(std::ostream &out) const {
406  if (num_bits >= 40) {
407  output_hex(out);
408  } else {
409  output_binary(out);
410  }
411 }
412 
413 /**
414  * Writes the BitMask out as a binary number, with spaces every four bits.
415  */
416 template<class WType, int nbits>
418 output_binary(std::ostream &out, int spaces_every) const {
419  for (int i = num_bits - 1; i >= 0; i--) {
420  if (spaces_every != 0 && ((i % spaces_every) == spaces_every - 1)) {
421  out << ' ';
422  }
423  out << (get_bit(i) ? '1' : '0');
424  }
425 }
426 
427 /**
428  * Writes the BitMask out as a hexadecimal number, with spaces every four
429  * digits.
430  */
431 template<class WType, int nbits>
433 output_hex(std::ostream &out, int spaces_every) const {
434  int num_digits = (num_bits + 3) / 4;
435 
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)) {
439  out << ' ';
440  }
441  if (digit > 9) {
442  out << (char)(digit - 10 + 'a');
443  } else {
444  out << (char)(digit + '0');
445  }
446  }
447 }
448 
449 /**
450  * Writes the BitMask out as a binary or a hex number, according to the number
451  * of bits.
452  */
453 template<class WType, int nbits>
455 write(std::ostream &out, int indent_level) const {
456  indent(out, indent_level) << *this << "\n";
457 }
458 
459 /**
460  *
461  */
462 template<class WType, int nbits>
463 INLINE bool BitMask<WType, nbits>::
464 operator == (const BitMask<WType, nbits> &other) const {
465  return _word == other._word;
466 }
467 
468 /**
469  *
470  */
471 template<class WType, int nbits>
472 INLINE bool BitMask<WType, nbits>::
473 operator != (const BitMask<WType, nbits> &other) const {
474  return _word != other._word;
475 }
476 
477 /**
478  * The ordering operator is of limited usefulness with a BitMask, however, it
479  * has a definition which places all unique BitMasks into a unique ordering.
480  * It may be useful when defining ordered STL containers of BitMasks, for
481  * instance; and it's required in order to export any STL container (ordered
482  * or unordered) of BitMask under Windows.
483  */
484 template<class WType, int nbits>
485 INLINE bool BitMask<WType, nbits>::
486 operator < (const BitMask<WType, nbits> &other) const {
487  return _word < other._word;
488 }
489 
490 /**
491  * Returns a number less than zero if this BitMask sorts before the indicated
492  * other BitMask, greater than zero if it sorts after, or 0 if they are
493  * equivalent. This is based on the same ordering defined by operator <.
494  */
495 template<class WType, int nbits>
496 INLINE int BitMask<WType, nbits>::
497 compare_to(const BitMask<WType, nbits> &other) const {
498  if ((*this) < other) {
499  return -1;
500  } else if (other < (*this)) {
501  return 1;
502  } else {
503  return 0;
504  }
505 }
506 
507 /**
508  *
509  */
510 template<class WType, int nbits>
512 operator & (const BitMask<WType, nbits> &other) const {
513  BitMask<WType, nbits> result(*this);
514  result &= other;
515  return result;
516 }
517 
518 /**
519  *
520  */
521 template<class WType, int nbits>
523 operator | (const BitMask<WType, nbits> &other) const {
524  BitMask<WType, nbits> result(*this);
525  result |= other;
526  return result;
527 }
528 
529 /**
530  *
531  */
532 template<class WType, int nbits>
534 operator ^ (const BitMask<WType, nbits> &other) const {
535  BitMask<WType, nbits> result(*this);
536  result ^= other;
537  return result;
538 }
539 
540 /**
541  *
542  */
543 template<class WType, int nbits>
545 operator ~ () const {
546  return BitMask<WType, nbits>(~_word);
547 }
548 
549 /**
550  *
551  */
552 template<class WType, int nbits>
554 operator << (int shift) const {
555  BitMask<WType, nbits> result(*this);
556  result <<= shift;
557  return result;
558 }
559 
560 /**
561  *
562  */
563 template<class WType, int nbits>
565 operator >> (int shift) const {
566  BitMask<WType, nbits> result(*this);
567  result >>= shift;
568  return result;
569 }
570 
571 /**
572  *
573  */
574 template<class WType, int nbits>
575 INLINE void BitMask<WType, nbits>::
576 operator &= (const BitMask<WType, nbits> &other) {
577  _word &= other._word;
578 }
579 
580 /**
581  *
582  */
583 template<class WType, int nbits>
584 INLINE void BitMask<WType, nbits>::
585 operator |= (const BitMask<WType, nbits> &other) {
586  _word |= other._word;
587 }
588 
589 /**
590  *
591  */
592 template<class WType, int nbits>
593 INLINE void BitMask<WType, nbits>::
594 operator ^= (const BitMask<WType, nbits> &other) {
595  _word ^= other._word;
596 }
597 
598 /**
599  *
600  */
601 template<class WType, int nbits>
602 INLINE void BitMask<WType, nbits>::
603 operator <<= (int shift) {
604  _word <<= shift;
605 }
606 
607 /**
608  *
609  */
610 template<class WType, int nbits>
611 INLINE void BitMask<WType, nbits>::
612 operator >>= (int shift) {
613  _word >>= shift;
614 }
615 
616 /**
617  * Returns a mostly unique integer key per unique bitmask, suitable for using
618  * in a hash table.
619  */
620 template<class WType, int nbits>
621 INLINE int BitMask<WType, nbits>::
622 get_key() const {
623  return (int)_word;
624 }
625 
626 /**
627  * Returns true if the bitmask is not zero.
628  */
629 template<class WType, int nbits>
630 INLINE bool BitMask<WType, nbits>::
631 __nonzero__() const {
632  return _word != 0;
633 }
634 
635 /**
636  * Adds the bitmask to the indicated hash generator.
637  */
638 template<class WType, int nbits>
639 INLINE void BitMask<WType, nbits>::
641  hashgen.add_int(_word);
642 }
643 
644 /**
645  *
646  */
647 template<class WType, int nbits>
649 init_type(const std::string &name) {
650  register_type(_type_handle, name);
651 }
652 
653 /**
654  * Floods this bitmask's bits upwards.
655  */
656 template<class WType, int nbits>
657 INLINE void BitMask<WType, nbits>::
659  _word = ::flood_bits_up(_word);
660 }
661 
662 /**
663  * Floods this bitmask's bits downwards.
664  */
665 template<class WType, int nbits>
666 INLINE void BitMask<WType, nbits>::
668  _word = ::flood_bits_down(_word);
669 }
670 
671 /**
672  * Returns a BitMask with the bits flooded upwards.
673  */
674 template<class WType, int nbits>
676 flood_bits_up() const {
677  BitMask<WType, nbits> result(::flood_bits_up(_word));
678  return result;
679 }
680 
681 /**
682  * Returns a BitMask with the bits flooded down.
683  */
684 template<class WType, int nbits>
687  BitMask<WType, nbits> result(::flood_bits_down(_word));
688  return result;
689 }
690 
691 
692 /**
693  * Returns a BitMask with only the next highest bit above the indicated bit
694  * on, or all_off.
695  */
696 template<class WType, int nbits>
699  int low_bit = get_lowest_on_bit();
700  if (low_bit >= 0) {
701  return BitMask<WType, nbits>::bit(low_bit);
702  } else {
704  }
705 }
706 
707 /**
708  * Returns a BitMask with only the next lower bit below the indicated bit on,
709  * or all_off.
710  */
711 template<class WType, int nbits>
714  int high_bit = get_highest_on_bit();
715  if (high_bit >= 0) {
716  return BitMask<WType, nbits>::bit(high_bit);
717  } else {
719  }
720 }
721 
722 /**
723  * Returns a BitMask with only the next highest bit above the indicated bit
724  * on, or all.
725  */
726 template<class WType, int nbits>
728 keep_next_highest_bit(int index) const {
729  BitMask<WType, nbits> mask,temp;
730  nassertr(index >= 0 && index < num_bits, mask);
731 
732  mask.set_bit(index);
733  mask.flood_down_in_place();
734  mask.invert_in_place();
735  mask &= *this;
736  temp = mask;
737 
738  mask <<= 1;
739  mask.flood_up_in_place();
740  mask.invert_in_place();
741  mask &= temp;
742 
743  return mask;
744 }
745 
746 /**
747  * Returns a BitMask with only the next lower bit below the indicated bit on,
748  * or all_off.
749  */
750 template<class WType, int nbits>
752 keep_next_lowest_bit(int index) const {
753  BitMask<WType, nbits> mask, temp;
754  nassertr(index >= 0 && index < num_bits, mask);
755 
756  mask.set_bit(index);
757  mask.flood_up_in_place();
758  mask.invert_in_place();
759  mask &= *this;
760  temp = mask;
761 
762  mask >>= 1;
763  mask.flood_down_in_place();
764  mask.invert_in_place();
765  mask &= temp;
766 
767  return mask;
768 }
769 
770 /**
771  * Returns a BitMask with only the next highest "on" bit above all "on" bits
772  * in the passed in bitmask, or all_off. If there are no "on" bits in the
773  * passed in bitmask, it will return keep_next_highest_bit().
774  */
775 template<class WType, int nbits>
778  int high_bit = other.get_highest_on_bit();
779  if (high_bit >= 0) {
780  return keep_next_highest_bit(high_bit);
781  } else {
782  return keep_next_highest_bit();
783  }
784 }
785 
786 /**
787  * Returns a BitMask with only the next lowest "on" bit below all "on" bits in
788  * the passed in bitmask, or all_off. If there are no "on" bits in the passed
789  * in bitmask, it will return keep_next_lowest_bit().
790  */
791 template<class WType, int nbits>
794  int low_bit = other.get_lowest_on_bit();
795  if (low_bit >= 0) {
796  return keep_next_lowest_bit(low_bit);
797  } else {
798  return keep_next_lowest_bit();
799  }
800 }
void clear_bit(int index)
Sets the nth bit off.
Definition: bitMask.I:129
static BitMask< WType, nbits > bit(int index)
Returns a BitMask with only the indicated bit on.
Definition: bitMask.I:70
void flood_down_in_place()
Floods this bitmask's bits downwards.
Definition: bitMask.I:667
int get_highest_off_bit() const
Returns the index of the highest 0 bit in the mask.
Definition: bitMask.I:313
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.
Definition: pbitops.I:89
bool has_any_of(int low_bit, int size) const
Returns true if any bit in the indicated range is set, false otherwise.
Definition: bitMask.I:193
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.
Definition: bitMask.I:686
void invert_in_place()
Inverts all the bits in the BitMask.
Definition: bitMask.I:372
static BitMask< WType, nbits > all_on()
Returns a BitMask whose bits are all on.
Definition: bitMask.I:32
void set_range(int low_bit, int size)
Sets the indicated range of bits on.
Definition: bitMask.I:213
void clear()
Sets all the bits in the BitMask off.
Definition: bitMask.I:395
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
void store(WordType value, int low_bit, int size)
Stores the indicated word into the indicated range of bits with this BitMask.
Definition: bitMask.I:183
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...
Definition: bitMask.I:326
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.
Definition: bitMask.I:455
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...
Definition: bitMask.I:486
int get_lowest_off_bit() const
Returns the index of the lowest 0 bit in the mask.
Definition: bitMask.I:293
bool __nonzero__() const
Returns true if the bitmask is not zero.
Definition: bitMask.I:631
int compare_to(const BitMask< WType, nbits > &other) const
Returns a number less than zero if this BitMask sorts before the indicated other BitMask,...
Definition: bitMask.I:497
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.
Definition: bitMask.I:698
constexpr int get_num_bits() const
Returns the number of bits available to set in the bitmask.
Definition: bitMask.I:99
static BitMask< WType, nbits > all_off()
Returns a BitMask whose bits are all off.
Definition: bitMask.I:43
int get_lowest_on_bit(uint16_t x)
Returns the index of the lowest 1 bit in the word.
Definition: pbitops.I:129
int get_num_off_bits() const
Returns the number of bits that are set to 0 in the mask.
Definition: bitMask.I:273
void set_word(WordType value)
Sets the entire BitMask to the value indicated by the given word.
Definition: bitMask.I:255
static BitMask< WType, nbits > range(int low_bit, int size)
Returns a BitMask whose size bits, beginning at low_bit, are on.
Definition: bitMask.I:81
void flood_up_in_place()
Floods this bitmask's bits upwards.
Definition: bitMask.I:658
void clear_range(int low_bit, int size)
Sets the indicated range of bits off.
Definition: bitMask.I:223
bool is_all_on() const
Returns true if the entire bitmask is one, false otherwise.
Definition: bitMask.I:162
void output_hex(std::ostream &out, int spaces_every=4) const
Writes the BitMask out as a hexadecimal number, with spaces every four digits.
Definition: bitMask.I:433
int get_highest_on_bit(uint16_t x)
Returns the index of the highest 1 bit in the word.
Definition: pbitops.I:192
WordType get_word() const
Returns the entire BitMask as a single word.
Definition: bitMask.I:246
bool get_bit(int index) const
Returns true if the nth bit is set, false if it is cleared.
Definition: bitMask.I:109
static BitMask< WType, nbits > lower_on(int on_bits)
Returns a BitMask whose lower on_bits bits are on.
Definition: bitMask.I:54
void generate_hash(ChecksumHashGenerator &hashgen) const
Adds the bitmask to the indicated hash generator.
Definition: bitMask.I:640
int get_lowest_on_bit() const
Returns the index of the lowest 1 bit in the mask.
Definition: bitMask.I:283
void set_bit_to(int index, bool value)
Sets the nth bit either on or off, according to the indicated bool value.
Definition: bitMask.I:140
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
WordType extract(int low_bit, int size) const
Returns a word that represents only the indicated range of bits within this BitMask,...
Definition: bitMask.I:172
void output(std::ostream &out) const
Writes the BitMask out as a binary or a hex number, according to the number of bits.
Definition: bitMask.I:405
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.
Definition: bitMask.I:386
BitMask< WType, nbits > flood_bits_up() const
Returns a BitMask with the bits flooded upwards.
Definition: bitMask.I:676
void set_range_to(bool value, int low_bit, int size)
Sets the indicated range of bits to either on or off.
Definition: bitMask.I:233
int get_highest_on_bit() const
Returns the index of the highest 1 bit in the mask.
Definition: bitMask.I:303
void add_int(long num)
Adds another integer to the hash so far.
void set_bit(int index)
Sets the nth bit on.
Definition: bitMask.I:119
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.
Definition: pbitops.I:50
bool has_all_of(int low_bit, int size) const
Returns true if all bits in the indicated range are set, false otherwise.
Definition: bitMask.I:203
void output_binary(std::ostream &out, int spaces_every=4) const
Writes the BitMask out as a binary number, with spaces every four bits.
Definition: bitMask.I:418
int get_key() const
Returns a mostly unique integer key per unique bitmask, suitable for using in a hash table.
Definition: bitMask.I:622
int get_num_on_bits() const
Returns the number of bits that are set to 1 in the mask.
Definition: bitMask.I:264
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
A general bitmask class.
Definition: bitMask.h:32
int count_bits_in_word(uint16_t x)
Returns the number of 1 bits in the indicated word.
Definition: pbitops.I:18
bool is_zero() const
Returns true if the entire bitmask is zero, false otherwise.
Definition: bitMask.I:153
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.
Definition: bitMask.I:713