23#ifndef LSST_SPHGEOM_RANGESET_H_
24#define LSST_SPHGEOM_RANGESET_H_
31#include <initializer_list>
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) {
253 )>::iterator_category
260 )>::iterator_category
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));
299 void insert(uint64_t first, uint64_t last);
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(); }
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 *);
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.
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