30#ifndef LSST_SPHGEOM_RANGESET_H_
31#define LSST_SPHGEOM_RANGESET_H_
38#include <initializer_list>
179 uint64_t
const *
p =
nullptr;
213 insert(
static_cast<uint64_t
>(std::get<0>(range)),
214 static_cast<uint64_t
>(std::get<1>(range)));
234 typename InputIterator,
243 for (; a !=
b; ++
a) {
260 )>::iterator_category
267 )>::iterator_category
277 return _offset == rs._offset && _ranges == rs._ranges;
281 return _offset != rs._offset || _ranges != rs._ranges;
303 insert(std::get<0>(range), std::get<1>(range));
306 void insert(uint64_t first, uint64_t last);
324 erase(std::get<0>(range), std::get<1>(range));
327 void erase(uint64_t first, uint64_t last);
434 bool intersects(uint64_t first, uint64_t last)
const;
444 bool contains(uint64_t first, uint64_t last)
const;
454 bool isWithin(uint64_t first, uint64_t last)
const;
508 void clear() { _ranges = {0, 0}; _offset =
true; }
511 void fill() { _ranges = {0, 0}; _offset =
false; }
514 bool empty()
const {
return _begin() == _end(); }
518 bool full()
const {
return _beginc() == _endc(); }
546 size_t size()
const {
return (_ranges.
size() - _offset) / 2; }
556 swap(_ranges, s._ranges);
557 swap(_offset, s._offset);
575 uint64_t
const * _begin()
const {
return _ranges.
data() + _offset; }
578 uint64_t
const * _end()
const {
579 size_t s = _ranges.
size();
580 return _ranges.
data() + (s - ((s & 1) ^ _offset));
585 uint64_t
const * _beginc()
const {
return _ranges.
data() + !_offset; }
589 uint64_t
const * _endc()
const {
590 size_t s = _ranges.
size();
591 return _ranges.
data() + (s - ((s & 1) ^ !_offset));
594 void _insert(uint64_t first, uint64_t last);
598 uint64_t
const *, uint64_t
const *);
601 uint64_t
const *, uint64_t
const *,
602 uint64_t
const *, uint64_t
const *);
604 void _intersect(uint64_t
const *, uint64_t
const *,
605 uint64_t
const *, uint64_t
const *);
607 static bool _intersectsOne(uint64_t
const *,
608 uint64_t
const *, uint64_t
const *);
610 static bool _intersects(uint64_t
const *, uint64_t
const *,
611 uint64_t
const *, uint64_t
const *);
A RangeSet is a set of unsigned 64 bit integers.
RangeSet intersection(RangeSet const &s) const
intersection returns the intersection of this set and s.
void erase(std::tuple< U, U > const &range)
bool intersects(uint64_t u) const
RangeSet operator-(RangeSet const &s) const
The - operator returns the difference between this set and s.
RangeSet & operator=(RangeSet const &)=default
RangeSet operator~() const
The ~ operator returns the complement of this set.
void clear()
clear removes all integers from this set.
Iterator beginc() const
beginc returns a constant iterator to the first range in the complement of this set.
bool isValid() const
isValid checks that this RangeSet is in a valid state.
bool operator!=(RangeSet const &rs) const
ptrdiff_t difference_type
size_t max_size() const
max_size returns the maximum number of ranges a set can hold.
RangeSet(RangeSet &&)=default
RangeSet & operator|=(RangeSet const &s)
The |= operator assigns the union of this set and s to this set.
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.
RangeSet(InputIterator a, InputIterator b)
This generic constructor creates a set containing the integers or ranges obtained by dereferencing th...
RangeSet & operator-=(RangeSet const &s)
The -= operator assigns the difference between this set and s to this set.
bool contains(uint64_t u) const
RangeSet join(RangeSet const &s) const
join returns the union of this set and s.
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.
bool isDisjointFrom(uint64_t u) const
RangeSet simplified(uint32_t n) const
simplified returns a simplified copy of this set.
bool empty() const
empty checks whether there are any integers in this set.
RangeSet scaled(uint64_t i) const
scaled returns a scaled copy of this set.
void insert(std::tuple< U, U > const &range)
RangeSet & operator^=(RangeSet const &s)
The ^= operator assigns the symmetric difference between this set and s to this set.
RangeSet & complement()
complement replaces this set S with U ∖ S, where U is the universe of range sets, [0,...
Iterator endc() const
endc returns a constant iterator to to the range after the last one in the complement of this set.
RangeSet operator|(RangeSet const &s) const
The | operator returns the union of this set and s.
RangeSet operator&(RangeSet const &s) const
The & operator returns the intersection of this set and s.
size_t size() const
size returns the number of ranges in this set.
RangeSet & operator&=(RangeSet const &s)
The &= operator assigns the intersection of this set and s to this set.
RangeSet(Container const &c)
This generic constructor creates a set containing the integers or integer ranges in the given contain...
RangeSet()=default
The default constructor creates an empty set.
void fill()
fill adds all the unsigned 64 bit integers to this set.
bool isDisjointFrom(uint64_t first, uint64_t last) const
bool isDisjointFrom(RangeSet const &s) const
RangeSet operator^(RangeSet const &s) const
The ^ operator returns the symmetric difference between this set and s.
RangeSet(uint64_t first, uint64_t last)
RangeSet(RangeSet const &)=default
RangeSet complemented() const
complemented returns a complemented copy of this set.
bool operator==(RangeSet const &rs) const
RangeSet difference(RangeSet const &s) const
difference returns the difference between this set and s.
RangeSet & simplify(uint32_t n)
simplify simplifies this range set by "coarsening" its ranges.
RangeSet(std::tuple< U, U > const &range)
RangeSet & operator=(RangeSet &&)=default
uint64_t cardinality() const
cardinality returns the number of integers in this set.
RangeSet symmetricDifference(RangeSet const &s) const
symmetricDifference returns the symmetric difference of this set and s.
void swap(RangeSet &a, RangeSet &b)
std::ostream & operator<<(std::ostream &, Angle const &)
A constant iterator over the ranges (represented as 2-tuples) in a RangeSet.
friend void swap(Iterator &a, Iterator &b)
bool operator<=(Iterator const &i) const
Iterator & operator+=(ptrdiff_t n)
ptrdiff_t operator-(Iterator const &i) const
Iterator operator-(ptrdiff_t n) const
std::tuple< uint64_t, uint64_t > operator[](ptrdiff_t n) const
std::tuple< uint64_t, uint64_t > operator*()
Iterator(uint64_t const *ptr)
Iterator operator+(ptrdiff_t n) const
friend Iterator operator+(ptrdiff_t n, Iterator const &i)
bool operator>=(Iterator const &i) const
bool operator==(Iterator const &i) const
bool operator!=(Iterator const &i) const
Iterator & operator-=(ptrdiff_t n)
ptrdiff_t difference_type
bool operator>(Iterator const &i) const
bool operator<(Iterator const &i) const