Go to the documentation of this file.
18 SparseArray() : _inverse(false) {
27 result._inverse =
true;
46 result._subranges.
push_back(Subrange(0, on_bits));
96 nassert_raise(
"SparseArray has no maximum bit count");
109 if (_subranges.
empty()) {
112 Subranges::const_iterator si = _subranges.
begin() + _subranges.
size() - 1;
174 return _subranges.
empty();
184 return _subranges.
empty();
196 return !do_has_all(low_bit, low_bit + size);
198 return do_has_any(low_bit, low_bit + size);
208 return !do_has_any(low_bit, low_bit + size);
210 return do_has_all(low_bit, low_bit + size);
220 return do_remove_range(low_bit, low_bit + size);
222 return do_add_range(low_bit, low_bit + size);
232 return do_add_range(low_bit, low_bit + size);
234 return do_remove_range(low_bit, low_bit + size);
256 _inverse = !_inverse;
271 INLINE
bool SparseArray::
279 INLINE
bool SparseArray::
327 operator ~ ()
const {
329 result.invert_in_place();
337 operator << (
int shift)
const {
347 operator >> (
int shift)
const {
395 return _subranges.
size();
405 nassertr(n < _subranges.
size(), 0);
406 return _subranges[n]._begin;
416 nassertr(n < _subranges.
size(), 0);
417 return _subranges[n]._end;
423 INLINE SparseArray::Subrange::
424 Subrange(
int begin,
int end) :
433 INLINE
bool SparseArray::Subrange::
434 operator < (
const SparseArray::Subrange &other)
const {
438 return _end < other._end;
size_type_0 size() const
Returns the number of elements in the ordered vector.
void set_range_to(bool value, int low_bit, int size)
Sets the indicated range of bits to either on or off.
void clear()
Sets all the bits in the SparseArray off.
int get_num_bits() const
Returns the current number of possibly different bits in this array.
void set_bit_to(int index, bool value)
Sets the nth bit either on or off, according to the indicated bool value.
bool empty() const
Returns true if the ordered vector is empty, false otherwise.
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 bool has_max_num_bits()
Returns true if there is a maximum number of bits that may be stored in this structure,...
bool is_zero() const
Returns true if the entire bitmask is zero, false otherwise.
void operator>>=(int shift)
Logical right shift.
bool get_bit(int index) const
Returns true if the nth bit is set, false if it is cleared.
bool is_inverse() const
If this is true, the SparseArray is actually defined as a list of subranges of integers that are *not...
bool is_all_on() const
Returns true if the entire bitmask is one, false otherwise.
int compare_to(const SparseArray &other) const
Returns a number less than zero if this SparseArray sorts before the indicated other SparseArray,...
void push_back(const value_type_0 &key)
Adds the new element to the end of the vector without regard for proper sorting.
This class records a set of integers, where each integer is either present or not present in the set.
void clear_range(int low_bit, int size)
Sets the indicated range of bits off.
size_t get_num_subranges() const
Returns the number of separate subranges stored in the SparseArray.
void set_range(int low_bit, int size)
Sets the indicated range of bits on.
void clear_bit(int index)
Sets the nth bit off.
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...
static SparseArray all_on()
Returns a SparseArray with an infinite array of bits, all on.
static SparseArray lower_on(int on_bits)
Returns a SparseArray whose lower on_bits bits are on.
bool operator<(const SparseArray &other) const
Returns true if the unsigned integer which is represented by this SparseArray is less than that of th...
static SparseArray range(int low_bit, int size)
Returns a SparseArray whose size bits, beginning at low_bit, are on.
bool has_any_of(int low_bit, int size) const
Returns true if any bit in the indicated range is set, false otherwise.
static SparseArray bit(int index)
Returns a SparseArray with only the indicated bit on.
int get_subrange_end(size_t n) const
Returns the last numeric element, plus one, in the nth subrange.
int get_subrange_begin(size_t n) const
Returns the first numeric element in the nth subrange.
void invert_in_place()
Inverts all the bits in the SparseArray.
void operator<<=(int shift)
Logical left shift.
iterator_0 begin()
Returns the iterator that marks the first element in the ordered vector.
static 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...
static SparseArray all_off()
Returns a SparseArray whose bits are all off.
void clear()
Removes all elements from the ordered vector.