30 bool current_state = from.
get_bit(0);
37 if (from.
get_bit(i) != current_state) {
39 if (current_state != empty_bit) {
40 Subrange
range(begin, i);
44 current_state = !current_state;
49 nassertv(current_state == empty_bit);
63 Subranges::const_iterator si;
64 for (si = _subranges.
begin(); si != _subranges.
end(); ++si) {
65 result += (*si)._end - (*si)._begin;
82 Subranges::const_iterator si;
83 for (si = _subranges.
begin(); si != _subranges.
end(); ++si) {
84 result += (*si)._end - (*si)._begin;
100 if (_subranges.
empty()) {
104 return _subranges[0]._begin;
117 if (_subranges.
empty()) {
121 return _subranges[0]._begin;
134 if (_subranges.
empty()) {
138 return _subranges[_subranges.
size() - 1]._end - 1;
151 if (_subranges.
empty()) {
155 return _subranges[_subranges.
size() - 1]._end - 1;
167 Subrange
range(low_bit, low_bit + 1);
168 Subranges::const_iterator si = _subranges.lower_bound(
range);
169 if (si == _subranges.
end()) {
174 if (low_bit >= (*si)._begin) {
178 int next = (*si)._begin;
180 if (si != _subranges.
begin()) {
182 if (low_bit < (*si)._end) {
198 if (_inverse && other._inverse) {
203 if (_inverse != other._inverse) {
205 return !(*
this & other).
is_zero();
210 return !(*
this & other).
is_zero();
217 output(std::ostream &out)
const {
220 out <<
"all except: ";
222 Subranges::const_iterator si;
223 for (si = _subranges.
begin(); si != _subranges.
end(); ++si) {
224 if ((*si)._end == (*si)._begin + 1) {
226 out << (*si)._begin <<
", ";
229 out << (*si)._begin <<
"-" << ((*si)._end - 1) <<
", ";
243 if (_inverse != other._inverse) {
244 return _inverse ? 1 : -1;
247 Subranges::const_reverse_iterator ai = _subranges.
rbegin();
248 Subranges::const_reverse_iterator bi = other._subranges.
rbegin();
250 while (ai != _subranges.
rend() && bi != other._subranges.
rend()) {
251 if ((*ai)._end < (*bi)._end) {
254 }
else if ((*bi)._end < (*ai)._end) {
257 }
else if ((*ai)._begin < (*bi)._begin) {
260 }
else if ((*bi)._begin < (*ai)._begin) {
269 if (ai != _subranges.
rend()) {
273 if (bi != other._subranges.
rend()) {
290 if (_inverse && other._inverse) {
293 }
else if (!_inverse && !other._inverse) {
294 do_intersection(other);
296 }
else if (_inverse && !other._inverse) {
298 (*this) = other & (*this);
300 }
else if (!_inverse && other._inverse) {
301 do_intersection_neg(other);
318 if (_inverse && other._inverse) {
319 do_intersection(other);
321 }
else if (!_inverse && !other._inverse) {
324 }
else if (_inverse && !other._inverse) {
325 do_intersection_neg(other);
327 }
else if (!_inverse && other._inverse) {
329 (*this) = other | (*this);
345 (*this) = ((*this) | other) & ~((*
this) & other);
354 do_add_range(
int begin,
int end) {
360 Subrange
range(begin, end);
361 Subranges::iterator si = _subranges.lower_bound(
range);
362 if (si == _subranges.
end()) {
363 if (!_subranges.
empty()) {
364 si = _subranges.
begin() + _subranges.
size() - 1;
365 if ((*si)._end >= begin) {
382 nassertv((*si)._end >= end);
384 if ((*si)._begin > end) {
385 if (si != _subranges.
begin()) {
386 Subranges::iterator si2 = si;
388 if ((*si2)._end >= begin) {
407 while (si != _subranges.
begin()) {
408 Subranges::iterator si2 = si;
410 if ((*si2)._end >= begin) {
412 (*si2)._end = (*si)._end;
413 _subranges.erase(si);
421 if ((*si)._begin > begin) {
423 (*si)._begin = begin;
432 do_remove_range(
int begin,
int end) {
438 Subrange
range(begin, end);
439 Subranges::iterator si = _subranges.lower_bound(
range);
440 if (si == _subranges.
end()) {
441 if (!_subranges.
empty()) {
442 si = _subranges.
begin() + _subranges.
size() - 1;
443 if ((*si)._end > begin) {
445 end = std::max(begin, (*si)._begin);
459 nassertv((*si)._end >= end);
461 if ((*si)._begin > end) {
462 if (si != _subranges.
begin()) {
463 Subranges::iterator si2 = si;
465 if ((*si2)._end > begin) {
468 end = std::max(begin, (*si2)._begin);
483 if (end < (*si)._end) {
485 Subrange left_range((*si)._begin, begin);
491 while (begin <= (*si)._begin || (*si)._begin >= (*si)._end) {
492 if (si == _subranges.
begin()) {
493 _subranges.erase(si);
496 Subranges::iterator si2 = si;
498 _subranges.erase(si);
502 (*si)._end = std::min((*si)._end, begin);
503 nassertv((*si)._end > (*si)._begin);
512 do_has_any(
int begin,
int end)
const {
518 Subrange
range(begin, end);
519 Subranges::const_iterator si = _subranges.lower_bound(
range);
520 if (si != _subranges.
end() && end > (*si)._begin) {
523 if (si != _subranges.
begin()) {
525 if (begin < (*si)._end) {
539 do_has_all(
int begin,
int end)
const {
545 Subrange
range(begin, end);
546 Subranges::const_iterator si = _subranges.lower_bound(
range);
547 if (si != _subranges.
end() && begin >= (*si)._begin) {
560 if (_subranges.
empty()) {
563 if (other._subranges.
empty()) {
568 int my_begin = (*_subranges.
begin())._begin;
569 int other_begin = (*other._subranges.
begin())._begin;
570 do_remove_range(my_begin, other_begin);
572 for (
size_t i = 0; i < other._subranges.
size() - 1; ++i) {
573 do_remove_range(other._subranges[i]._end, other._subranges[i + 1]._begin);
576 int my_end = (*(_subranges.
begin() + _subranges.
size() - 1))._end;
577 int other_end = (*(other._subranges.
begin() + other._subranges.
size() - 1))._end;
578 do_remove_range(other_end, my_end);
586 Subranges::const_iterator si;
587 for (si = other._subranges.
begin(); si != other._subranges.
end(); ++si) {
588 do_add_range((*si)._begin, (*si)._end);
598 Subranges::const_iterator si;
599 for (si = other._subranges.
begin(); si != other._subranges.
end(); ++si) {
600 do_remove_range((*si)._begin, (*si)._end);
608 do_shift(
int offset) {
610 Subranges::iterator si;
611 for (si = _subranges.
begin(); si != _subranges.
end(); ++si) {
612 (*si)._begin += offset;
613 (*si)._end += offset;
625 Subranges::const_iterator si;
626 for (si = _subranges.
begin(); si != _subranges.
end(); ++si) {
639 _subranges.
reserve(num_subranges);
640 for (
size_t i = 0; i < num_subranges; ++i) {
643 _subranges.
push_back(Subrange(begin, end));
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
A dynamic array with an unlimited number of bits.
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...
size_t get_num_bits() const
Returns the current number of possibly different bits in this array.
bool get_bit(int index) const
Returns true if the nth bit is set, false if it is cleared.
A class to retrieve the individual data elements previously stored in a Datagram.
uint32_t get_uint32()
Extracts an unsigned 32-bit integer.
bool get_bool()
Extracts a boolean value.
int32_t get_int32()
Extracts a signed 32-bit integer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_uint32(uint32_t value)
Adds an unsigned 32-bit integer to the datagram.
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
void add_bool(bool value)
Adds a boolean value to the datagram.
This class records a set of integers, where each integer is either present or not present in the set.
int get_highest_on_bit() const
Returns the index of the highest 1 bit in the array.
int get_num_off_bits() const
Returns the number of bits that are set to 0 in the array.
void write_datagram(BamWriter *manager, Datagram &dg) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
void read_datagram(DatagramIterator &scan, BamReader *manager)
Reads the object that was previously written to a Bam file.
int get_lowest_on_bit() const
Returns the index of the lowest 1 bit in the array.
int get_lowest_off_bit() const
Returns the index of the lowest 0 bit in the array.
bool has_bits_in_common(const SparseArray &other) const
Returns true if this SparseArray has any "one" bits in common with the other 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,...
static SparseArray range(int low_bit, int size)
Returns a SparseArray whose size bits, beginning at low_bit, are on.
int get_highest_off_bit() const
Returns the index of the highest 0 bit in the array.
bool is_zero() const
Returns true if the entire bitmask is zero, false otherwise.
int get_num_on_bits() const
Returns the number of bits that are set to 1 in the array.
int get_next_higher_different_bit(int low_bit) const
Returns the index of the next bit in the array, above low_bit, whose value is different that the valu...
TypeHandle is the identifier used to differentiate C++ class types.
void reserve(size_type_0 n)
Informs the vector of a planned change in size; ensures that the capacity of the vector is greater th...
reverse_iterator_0 rend()
Returns the iterator that marks the end of the ordered vector, when viewed in reverse order.
iterator_0 begin()
Returns the iterator that marks the first element in the ordered vector.
void push_back(const value_type_0 &key)
Adds the new element to the end of the vector without regard for proper sorting.
reverse_iterator_0 rbegin()
Returns the iterator that marks the first element in the ordered vector, when viewed in reverse order...
size_type_0 size() const
Returns the number of elements in the ordered vector.
bool empty() const
Returns true if the ordered vector is empty, false otherwise.
iterator_0 end()
Returns the iterator that marks the end of the ordered vector.
iterator_0 insert_unverified(iterator_0 position, const value_type_0 &key)
Inserts the indicated key into the ordered vector at the indicated place.
void clear()
Removes all elements from the ordered vector.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.