30#ifndef LSST_SPHGEOM_RANGESET_H_
31#define LSST_SPHGEOM_RANGESET_H_
38#include <initializer_list>
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));
324 erase(std::get<0>(range), std::get<1>(range));
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);
579 size_t s = _ranges.
size();
580 return _ranges.
data() + (s - ((s & 1) ^ _offset));
590 size_t s = _ranges.
size();
591 return _ranges.
data() + (s - ((s & 1) ^ !_offset));
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)
std::uint64_t cardinality() const
cardinality returns the number of integers in this set.
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.
RangeSet(std::uint64_t u)
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 full() const
full checks whether all integers in the universe of range sets, [0, 2^64), are in this set.
RangeSet & scale(std::uint64_t i)
scale multiplies the endpoints of each range in this set by the given integer.
bool intersects(std::uint64_t u) const
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.
RangeSet join(RangeSet const &s) const
join returns the union of this set and s.
bool isWithin(RangeSet const &s) const
bool empty() const
empty checks whether there are any integers in this set.
void insert(std::tuple< U, U > const &range)
RangeSet(std::uint64_t first, std::uint64_t last)
RangeSet & operator^=(RangeSet const &s)
The ^= operator assigns the symmetric difference between this set and s to this set.
void erase(std::uint64_t u)
bool contains(std::uint64_t u) const
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.
bool isDisjointFrom(std::uint64_t first, std::uint64_t last) const
bool isWithin(std::uint64_t u) const
RangeSet operator|(RangeSet const &s) const
The | operator returns the union of this set and s.
RangeSet simplified(std::uint32_t n) const
simplified returns a simplified copy of this set.
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...
bool isDisjointFrom(std::uint64_t u) const
RangeSet()=default
The default constructor creates an empty set.
RangeSet & simplify(std::uint32_t n)
simplify simplifies this range set by "coarsening" its ranges.
void fill()
fill adds all the unsigned 64 bit integers to this set.
bool isDisjointFrom(RangeSet const &s) const
RangeSet operator^(RangeSet const &s) const
The ^ operator returns the symmetric difference between this set and s.
RangeSet scaled(std::uint64_t i) const
scaled returns a scaled copy of this set.
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(std::tuple< U, U > const &range)
RangeSet & operator=(RangeSet &&)=default
RangeSet symmetricDifference(RangeSet const &s) const
symmetricDifference returns the symmetric difference of this set and s.
void insert(std::uint64_t u)
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< std::uint64_t, std::uint64_t > operator[](ptrdiff_t n) const
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
Iterator(std::uint64_t const *ptr)
bool operator>(Iterator const &i) const
bool operator<(Iterator const &i) const
std::tuple< std::uint64_t, std::uint64_t > operator*()