23 #ifndef LSST_SPHGEOM_RANGESET_H_ 24 #define LSST_SPHGEOM_RANGESET_H_ 31 #include <initializer_list> 35 #include <type_traits> 172 uint64_t
const *
p =
nullptr;
206 insert(static_cast<uint64_t>(std::get<0>(range)),
207 static_cast<uint64_t>(std::get<1>(range)));
227 typename InputIterator,
236 for (; a !=
b; ++
a) {
250 std::input_iterator_tag,
257 std::input_iterator_tag,
270 return _offset == rs._offset && _ranges == rs._ranges;
274 return _offset != rs._offset || _ranges != rs._ranges;
296 insert(std::get<0>(range), std::get<1>(range));
317 erase(std::get<0>(range), std::get<1>(range));
320 void erase(uint64_t first, uint64_t last);
427 bool intersects(uint64_t first, uint64_t last)
const;
437 bool contains(uint64_t first, uint64_t last)
const;
447 bool isWithin(uint64_t first, uint64_t last)
const;
501 void clear() { _ranges = {0, 0}; _offset =
true; }
504 void fill() { _ranges = {0, 0}; _offset =
false; }
507 bool empty()
const {
return _begin() == _end(); }
511 bool full()
const {
return _beginc() == _endc(); }
536 size_t max_size()
const {
return _ranges.max_size() / 2; }
539 size_t size()
const {
return (_ranges.size() - _offset) / 2; }
549 swap(_ranges, s._ranges);
550 swap(_offset, s._offset);
568 uint64_t
const * _begin()
const {
return _ranges.
data() + _offset; }
571 uint64_t
const * _end()
const {
572 size_t s = _ranges.
size();
573 return _ranges.
data() + (s - ((s & 1) ^ _offset));
578 uint64_t
const * _beginc()
const {
return _ranges.
data() + !_offset; }
582 uint64_t
const * _endc()
const {
583 size_t s = _ranges.
size();
584 return _ranges.
data() + (s - ((s & 1) ^ !_offset));
587 void _insert(uint64_t first, uint64_t last);
591 uint64_t
const *, uint64_t
const *);
594 uint64_t
const *, uint64_t
const *,
595 uint64_t
const *, uint64_t
const *);
597 void _intersect(uint64_t
const *, uint64_t
const *,
598 uint64_t
const *, uint64_t
const *);
600 static bool _intersectsOne(uint64_t
const *,
601 uint64_t
const *, uint64_t
const *);
603 static bool _intersects(uint64_t
const *, uint64_t
const *,
604 uint64_t
const *, uint64_t
const *);
616 #endif // LSST_SPHGEOM_RANGESET_H_ RangeSet operator-(RangeSet const &s) const
The - operator returns the difference between this set and s.
bool operator!=(Iterator const &i) const
RangeSet symmetricDifference(RangeSet const &s) const
symmetricDifference returns the symmetric difference of this set and s.
bool operator!=(RangeSet const &rs) const
bool operator>(Iterator const &i) const
bool operator>=(Iterator const &i) const
void clear()
clear removes all integers from this set.
void insert(std::tuple< U, U > const &range)
bool operator<(Iterator const &i) const
bool operator==(Iterator const &i) const
bool operator==(RangeSet const &rs) const
bool contains(uint64_t u) const
RangeSet & operator^=(RangeSet const &s)
The ^= operator assigns the symmetric difference between this set and s to this set.
RangeSet difference(RangeSet const &s) const
difference returns the difference between this set and s.
bool empty() const
empty checks whether there are any integers in this set.
ptrdiff_t operator-(Iterator const &i) const
RangeSet & operator &=(RangeSet const &s)
The &= operator assigns the intersection of this set and s to this set.
bool isDisjointFrom(RangeSet const &s) const
RangeSet complemented() const
complemented returns a complemented copy of this set.
RangeSet & operator=(RangeSet const &)=default
bool operator<=(Iterator const &i) const
RangeSet()=default
The default constructor creates an empty set.
std::ostream & operator<<(std::ostream &, Angle const &)
friend Iterator operator+(ptrdiff_t n, Iterator const &i)
std::tuple< uint64_t, uint64_t > operator*()
bool isDisjointFrom(uint64_t first, uint64_t last) const
bool isDisjointFrom(uint64_t u) const
Iterator & operator-=(ptrdiff_t n)
Iterator operator-(ptrdiff_t n) const
Iterator beginc() const
beginc returns a constant iterator to the first range in the complement of this set.
RangeSet & simplify(uint32_t n)
simplify simplifies this range set by "coarsening" its ranges.
RangeSet simplified(uint32_t n) const
simplified returns a simplified copy of this set.
void erase(std::tuple< U, U > const &range)
std::tuple< uint64_t, uint64_t > operator[](ptrdiff_t n) const
RangeSet(std::tuple< U, U > const &range)
RangeSet & complement()
complement replaces this set S with U ∖ S, where U is the universe of range sets, [0, 2^64).
bool isWithin(RangeSet const &s) const
RangeSet & scale(uint64_t i)
scale multiplies the endpoints of each range in this set by the given integer.
RangeSet & operator-=(RangeSet const &s)
The -= operator assigns the difference between this set and s to this set.
Iterator operator+(ptrdiff_t n) const
A base class for image defects.
RangeSet(uint64_t first, uint64_t last)
size_t max_size() const
max_size returns the maximum number of ranges a set can hold.
RangeSet scaled(uint64_t i) const
scaled returns a scaled copy of this set.
RangeSet operator &(RangeSet const &s) const
The & operator returns the intersection of this set and s.
RangeSet operator|(RangeSet const &s) const
The | operator returns the union of this set and s.
Iterator & operator+=(ptrdiff_t n)
RangeSet operator^(RangeSet const &s) const
The ^ operator returns the symmetric difference between this set and s.
ptrdiff_t difference_type
bool intersects(uint64_t u) const
Iterator(uint64_t const *ptr)
bool isValid() const
isValid checks that this RangeSet is in a valid state.
Iterator endc() const
endc returns a constant iterator to to the range after the last one in the complement of this set...
RangeSet operator~() const
The ~ operator returns the complement of this set.
RangeSet & operator|=(RangeSet const &s)
The |= operator assigns the union of this set and s to this set.
A RangeSet is a set of unsigned 64 bit integers.
void fill()
fill adds all the unsigned 64 bit integers to this set.
A constant iterator over the ranges (represented as 2-tuples) in a RangeSet.
friend void swap(Iterator &a, Iterator &b)
bool isWithin(uint64_t u) const
bool full() const
full checks whether all integers in the universe of range sets, [0, 2^64), are in this set...
std::input_iterator_tag iterator_category
ptrdiff_t difference_type
RangeSet(InputIterator a, InputIterator b)
This generic constructor creates a set containing the integers or ranges obtained by dereferencing th...
size_t size() const
size returns the number of ranges in this set.
RangeSet(Container const &c)
This generic constructor creates a set containing the integers or integer ranges in the given contain...
uint64_t cardinality() const
cardinality returns the number of integers in this set.
RangeSet join(RangeSet const &s) const
join returns the union of this set and s.
RangeSet intersection(RangeSet const &s) const
intersection returns the intersection of this set and s.