32 BitArray(WordType init_value) {
33 if (init_value != 0) {
34 _array.push_back(MaskType(init_value));
47 _highest_bits(copy._highest_bits)
59 _highest_bits = copy._highest_bits;
72 result._highest_bits = 1;
178 return num_bits_per_word;
208 nassertr(index >= 0,
false);
209 int w = index / num_bits_per_word;
210 int b = index % num_bits_per_word;
226 nassertv(index >= 0);
227 int w = index / num_bits_per_word;
228 int b = index % num_bits_per_word;
234 _array[w].set_bit(b);
246 nassertv(index >= 0);
247 int w = index / num_bits_per_word;
248 int b = index % num_bits_per_word;
254 _array[w].clear_bit(b);
282 return (_highest_bits != 0);
295 nassertr(size >= 0 && size <= num_bits_per_word, 0);
296 int w = low_bit / num_bits_per_word;
297 int b = low_bit % num_bits_per_word;
299 if (b + size < num_bits_per_word) {
301 return get_word(w).extract(b, size);
305 int num_lower_bits = num_bits_per_word - b;
306 int num_higher_bits = size - num_lower_bits;
308 return get_word(w).extract(b, num_lower_bits) |
309 (
get_word(w + 1).extract(0, num_higher_bits) << num_lower_bits);
320 store(WordType value,
int low_bit,
int size) {
322 int w = low_bit / num_bits_per_word;
323 int b = low_bit % num_bits_per_word;
325 if (b + size < num_bits_per_word) {
328 _array[w].store(value, b, size);
332 int num_lower_bits = num_bits_per_word - b;
333 int num_higher_bits = size - num_lower_bits;
335 ensure_has_word(w + 1);
336 _array[w].store(value, b, num_lower_bits);
337 _array[w + 1].store(value >> num_lower_bits, 0, num_higher_bits);
364 return _array.size();
376 nassertr(n >= 0, MaskType::all_off());
381 return MaskType::all_on();
383 return MaskType::all_off();
418 INLINE
bool BitArray::
419 operator == (
const BitArray &other)
const {
428 INLINE
bool BitArray::
429 operator != (
const BitArray &other)
const {
451 operator & (
const BitArray &other)
const {
463 operator | (
const BitArray &other)
const {
475 operator ^ (
const BitArray &other)
const {
487 operator ~ ()
const {
499 operator << (
int shift)
const {
511 operator >> (
int shift)
const {
525 INLINE
void BitArray::
527 if (_array.get_ref_count() > 1) {
528 PTA(MaskType) new_array;
529 new_array.v() = _array.v();
void invert_in_place()
Inverts all the bits in the BitArray.
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_bits() const
Returns the current number of possibly different bits in this array.
bool get_highest_bits() const
Returns true if the infinite set of bits beyond get_num_bits() are all on, or false of they are all o...
bool get_bit(int index) const
Returns true if the nth bit is set, false if it is cleared.
static BitArray all_on()
Returns a BitArray with an infinite array of bits, all on.
static CONSTEXPR int get_num_bits_per_word()
Returns the number of bits stored per word internally.
static BitArray range(int low_bit, int size)
Returns a BitArray whose size bits, beginning at low_bit, are on.
void set_range_to(bool value, int low_bit, int size)
Sets the indicated range of bits to either on or off.
void store(WordType value, int low_bit, int size)
Stores the indicated word into the indicated range of bits with this BitArray.
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 clear_bit(int index)
Sets the nth bit off.
A dynamic array with an unlimited number of bits.
bool operator<(const BitArray &other) const
Returns true if the unsigned integer which is represented by this BitArray is less than that of the o...
void set_range(int low_bit, int size)
Sets the indicated range of bits on.
void clear_range(int low_bit, int size)
Sets the indicated range of bits off.
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.
static BitArray lower_on(int on_bits)
Returns a BitArray whose lower on_bits bits are on.
void set_bit(int index)
Sets the nth bit on.
MaskType get_word(int n) const
Returns the nth word in the array.
int get_num_words() const
Returns the number of possibly-unique words stored in the array.
void clear()
Sets all the bits in the BitArray off.
static BitArray all_off()
Returns a BitArray whose bits are all off.
static BitArray bit(int index)
Returns a BitArray with only the indicated bit on.
void set_word(int n, WordType value)
Replaces the nth word in the array.
WordType extract(int low_bit, int size) const
Returns a word that represents only the indicated range of bits within this BitArray, shifted to the least-significant position.
int compare_to(const BitArray &other) const
Returns a number less than zero if this BitArray sorts before the indicated other BitArray...