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);
41 _subranges.push_back(
range);
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;
97 if (_subranges.empty() || _subranges[0]._begin > 0) {
100 return _subranges[0]._end;
104 if (_subranges.empty()) {
108 return _subranges[0]._begin;
118 if (_subranges.empty() || _subranges[0]._begin > 0) {
121 return _subranges[0]._end;
125 if (_subranges.empty()) {
129 return _subranges[0]._begin;
142 if (_subranges.empty()) {
146 return _subranges[_subranges.size() - 1]._end - 1;
159 if (_subranges.empty()) {
163 return _subranges[_subranges.size() - 1]._end - 1;
175 Subrange
range(low_bit, low_bit + 1);
176 Subranges::const_iterator si = _subranges.lower_bound(
range);
177 if (si == _subranges.end()) {
182 if (low_bit >= (*si)._begin) {
186 int next = (*si)._begin;
188 if (si != _subranges.begin()) {
190 if (low_bit < (*si)._end) {
206 if (_inverse && other._inverse) {
211 if (_inverse != other._inverse) {
213 return !(*
this & other).
is_zero();
218 return !(*
this & other).
is_zero();
225output(std::ostream &out)
const {
228 out <<
"all except: ";
230 Subranges::const_iterator si;
231 for (si = _subranges.begin(); si != _subranges.end(); ++si) {
232 if ((*si)._end == (*si)._begin + 1) {
234 out << (*si)._begin <<
", ";
237 out << (*si)._begin <<
"-" << ((*si)._end - 1) <<
", ";
251 if (_inverse != other._inverse) {
252 return _inverse ? 1 : -1;
255 Subranges::const_reverse_iterator ai = _subranges.rbegin();
256 Subranges::const_reverse_iterator bi = other._subranges.
rbegin();
258 while (ai != _subranges.rend() && bi != other._subranges.
rend()) {
259 if ((*ai)._end < (*bi)._end) {
262 }
else if ((*bi)._end < (*ai)._end) {
265 }
else if ((*ai)._begin < (*bi)._begin) {
268 }
else if ((*bi)._begin < (*ai)._begin) {
277 if (ai != _subranges.rend()) {
281 if (bi != other._subranges.
rend()) {
298 if (_inverse && other._inverse) {
301 }
else if (!_inverse && !other._inverse) {
302 do_intersection(other);
304 }
else if (_inverse && !other._inverse) {
306 (*this) = other & (*this);
308 }
else if (!_inverse && other._inverse) {
309 do_intersection_neg(other);
326 if (_inverse && other._inverse) {
327 do_intersection(other);
329 }
else if (!_inverse && !other._inverse) {
332 }
else if (_inverse && !other._inverse) {
333 do_intersection_neg(other);
335 }
else if (!_inverse && other._inverse) {
337 (*this) = other | (*this);
353 (*this) = ((*this) | other) & ~((*
this) & other);
362do_add_range(
int begin,
int end) {
368 Subrange
range(begin, end);
369 Subranges::iterator si = _subranges.lower_bound(
range);
370 if (si == _subranges.end()) {
371 if (!_subranges.empty()) {
372 si = _subranges.begin() + _subranges.size() - 1;
373 if ((*si)._end >= begin) {
379 _subranges.push_back(
range);
385 _subranges.push_back(
range);
390 nassertv((*si)._end >= end);
392 if ((*si)._begin > end) {
393 if (si != _subranges.begin()) {
394 Subranges::iterator si2 = si;
396 if ((*si2)._end >= begin) {
404 _subranges.insert_unverified(si,
range);
409 _subranges.insert_unverified(si,
range);
415 while (si != _subranges.begin()) {
416 Subranges::iterator si2 = si;
418 if ((*si2)._end >= begin) {
420 (*si2)._end = (*si)._end;
421 _subranges.erase(si);
429 if ((*si)._begin > begin) {
431 (*si)._begin = begin;
440do_remove_range(
int begin,
int end) {
446 Subrange
range(begin, end);
447 Subranges::iterator si = _subranges.lower_bound(
range);
448 if (si == _subranges.end()) {
449 if (!_subranges.empty()) {
450 si = _subranges.begin() + _subranges.size() - 1;
451 if ((*si)._end > begin) {
453 end = std::max(begin, (*si)._begin);
467 nassertv((*si)._end >= end);
469 if ((*si)._begin > end) {
470 if (si != _subranges.begin()) {
471 Subranges::iterator si2 = si;
473 if ((*si2)._end > begin) {
476 end = std::max(begin, (*si2)._begin);
491 if (end < (*si)._end) {
493 Subrange left_range((*si)._begin, begin);
495 si = _subranges.insert_unverified(si, left_range);
499 while (begin <= (*si)._begin || (*si)._begin >= (*si)._end) {
500 if (si == _subranges.begin()) {
501 _subranges.erase(si);
504 Subranges::iterator si2 = si;
506 _subranges.erase(si);
510 (*si)._end = std::min((*si)._end, begin);
511 nassertv((*si)._end > (*si)._begin);
520do_has_any(
int begin,
int end)
const {
526 Subrange
range(begin, end);
527 Subranges::const_iterator si = _subranges.lower_bound(
range);
528 if (si != _subranges.end() && end > (*si)._begin) {
531 if (si != _subranges.begin()) {
533 if (begin < (*si)._end) {
547do_has_all(
int begin,
int end)
const {
553 Subrange
range(begin, end);
554 Subranges::const_iterator si = _subranges.lower_bound(
range);
555 if (si != _subranges.end() && begin >= (*si)._begin) {
568 if (_subranges.empty()) {
571 if (other._subranges.
empty()) {
576 int my_begin = (*_subranges.begin())._begin;
577 int other_begin = (*other._subranges.
begin())._begin;
578 do_remove_range(my_begin, other_begin);
580 for (
size_t i = 0; i < other._subranges.
size() - 1; ++i) {
581 do_remove_range(other._subranges[i]._end, other._subranges[i + 1]._begin);
584 int my_end = (*(_subranges.begin() + _subranges.size() - 1))._end;
585 int other_end = (*(other._subranges.
begin() + other._subranges.
size() - 1))._end;
586 do_remove_range(other_end, my_end);
594 Subranges::const_iterator si;
595 for (si = other._subranges.
begin(); si != other._subranges.
end(); ++si) {
596 do_add_range((*si)._begin, (*si)._end);
606 Subranges::const_iterator si;
607 for (si = other._subranges.
begin(); si != other._subranges.
end(); ++si) {
608 do_remove_range((*si)._begin, (*si)._end);
616do_shift(
int offset) {
618 Subranges::iterator si;
619 for (si = _subranges.begin(); si != _subranges.end(); ++si) {
620 (*si)._begin += offset;
621 (*si)._end += offset;
633 Subranges::const_iterator si;
634 for (si = _subranges.begin(); si != _subranges.end(); ++si) {
647 _subranges.reserve(num_subranges);
648 for (
size_t i = 0; i < num_subranges; ++i) {
651 _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.
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.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.