lsst.sphgeom
20.0.0-5-gfbfe500+d529cf1a41
|
Go to the documentation of this file.
23 #ifndef LSST_SPHGEOM_RANGESET_H_
24 #define LSST_SPHGEOM_RANGESET_H_
31 #include <initializer_list>
35 #include <type_traits>
124 using difference_type = ptrdiff_t;
125 using value_type = std::tuple<uint64_t, uint64_t>;
126 using pointer = void;
127 using reference = std::tuple<uint64_t, uint64_t>;
128 using iterator_category = std::input_iterator_tag;
131 explicit Iterator(uint64_t
const * ptr) : p{ptr} {}
138 Iterator & operator++() { p += 2;
return *
this; }
139 Iterator & operator--() { p -= 2;
return *
this; }
147 Iterator & operator+=(ptrdiff_t n) { p += 2 * n;
return *
this; }
148 Iterator & operator-=(ptrdiff_t n) { p -= 2 * n;
return *
this; }
154 ptrdiff_t operator-(
Iterator const & i)
const {
return (p - i.p) / 2; }
157 bool operator==(
Iterator const & i)
const {
return p == i.p; }
158 bool operator!=(
Iterator const & i)
const {
return p != i.p; }
159 bool operator<(
Iterator const & i)
const {
return p < i.p; }
160 bool operator>(
Iterator const & i)
const {
return p > i.p; }
161 bool operator<=(
Iterator const & i)
const {
return p <= i.p; }
162 bool operator>=(
Iterator const & i)
const {
return p >= i.p; }
164 std::tuple<uint64_t, uint64_t> operator*() {
165 return std::make_tuple(p[0], p[1]);
168 std::tuple<uint64_t, uint64_t> operator[](ptrdiff_t n)
const {
169 return std::make_tuple(p[2 * n], p[2 * n + 1]);
172 uint64_t
const * p =
nullptr;
175 using difference_type = ptrdiff_t;
176 using size_type = size_t;
177 using value_type = std::tuple<uint64_t, uint64_t>;
195 RangeSet(uint64_t first, uint64_t last) {
201 typename =
typename std::enable_if<
202 std::is_convertible<U, uint64_t>::value
205 explicit RangeSet(std::tuple<U, U>
const & range) {
206 insert(
static_cast<uint64_t
>(std::get<0>(range)),
207 static_cast<uint64_t
>(std::get<1>(range)));
210 RangeSet(std::initializer_list<uint64_t>);
218 RangeSet(std::initializer_list<std::pair<uint64_t, uint64_t>>);
227 typename InputIterator,
228 typename =
typename std::enable_if<
230 std::input_iterator_tag,
231 typename std::iterator_traits<InputIterator>::iterator_category
236 for (; a != b; ++a) {
248 typename =
typename std::enable_if<
250 std::input_iterator_tag,
251 typename std::iterator_traits<decltype(
252 std::begin(std::declval<
typename std::add_const<Container>::type>())
253 )>::iterator_category
257 std::input_iterator_tag,
258 typename std::iterator_traits<decltype(
259 std::end(std::declval<
typename std::add_const<Container>::type>())
260 )>::iterator_category
270 return _offset == rs._offset && _ranges == rs._ranges;
273 bool operator!=(
RangeSet const & rs)
const {
274 return _offset != rs._offset || _ranges != rs._ranges;
291 typename =
typename std::enable_if<
292 std::is_convertible<U, uint64_t>::value
295 void insert(std::tuple<U, U>
const & range) {
296 insert(std::get<0>(range), std::get<1>(range));
299 void insert(uint64_t first, uint64_t last);
312 typename =
typename std::enable_if<
313 std::is_convertible<U, uint64_t>::value
316 void erase(std::tuple<U, U>
const & 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(); }
517 Iterator cbegin()
const {
return begin(); }
524 Iterator cend()
const {
return end(); }
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);
561 std::vector<uint64_t> _ranges = {0, 0};
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);
589 static void _intersectOne(std::vector<uint64_t> &,
591 uint64_t
const *, uint64_t
const *);
593 static void _intersect(std::vector<uint64_t> &,
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 *);
608 inline void swap(RangeSet & a, RangeSet & b) {
612 std::ostream & operator<<(std::ostream &, RangeSet
const &);
616 #endif // LSST_SPHGEOM_RANGESET_H_
bool operator==(RangeSet const &rs) const
Definition: RangeSet.h:269
RangeSet operator|(RangeSet const &s) const
The | operator returns the union of this set and s.
Definition: RangeSet.h:363
RangeSet operator&(RangeSet const &s) const
The & operator returns the intersection of this set and s.
Definition: RangeSet.h:358
bool empty() const
empty checks whether there are any integers in this set.
Definition: RangeSet.h:507
Iterator end() const
Definition: RangeSet.h:523
uint64_t cardinality() const
Definition: RangeSet.cc:300
RangeSet complemented() const
complemented returns a complemented copy of this set.
Definition: RangeSet.h:331
RangeSet operator~() const
The ~ operator returns the complement of this set.
Definition: RangeSet.h:351
bool isDisjointFrom(uint64_t u) const
Definition: RangeSet.h:455
RangeSet(Container const &c)
Definition: RangeSet.h:264
RangeSet & operator-=(RangeSet const &s)
Definition: RangeSet.h:399
void insert(uint64_t u)
Definition: RangeSet.h:285
RangeSet symmetricDifference(RangeSet const &s) const
Definition: RangeSet.cc:166
void fill()
fill adds all the unsigned 64 bit integers to this set.
Definition: RangeSet.h:504
RangeSet & complement()
Definition: RangeSet.h:328
RangeSet()=default
The default constructor creates an empty set.
bool isValid() const
Definition: RangeSet.cc:377
RangeSet(uint64_t u)
Definition: RangeSet.h:191
RangeSet scaled(uint64_t i) const
scaled returns a scaled copy of this set.
Definition: RangeSet.h:494
RangeSet difference(RangeSet const &s) const
difference returns the difference between this set and s.
Definition: RangeSet.cc:157
Definition: RangeSet.h:122
Iterator begin() const
Definition: RangeSet.h:516
bool full() const
Definition: RangeSet.h:511
RangeSet & operator&=(RangeSet const &s)
Definition: RangeSet.h:379
RangeSet operator-(RangeSet const &s) const
The - operator returns the difference between this set and s.
Definition: RangeSet.h:368
bool isWithin(uint64_t u) const
Definition: RangeSet.h:445
RangeSet intersection(RangeSet const &s) const
intersection returns the intersection of this set and s.
Definition: RangeSet.cc:135
RangeSet & operator^=(RangeSet const &s)
Definition: RangeSet.h:411
bool contains(uint64_t u) const
Definition: RangeSet.h:435
size_t size() const
size returns the number of ranges in this set.
Definition: RangeSet.h:539
bool intersects(uint64_t u) const
Definition: RangeSet.h:425
RangeSet join(RangeSet const &s) const
join returns the union of this set and s.
Definition: RangeSet.cc:145
RangeSet simplified(uint32_t n) const
simplified returns a simplified copy of this set.
Definition: RangeSet.h:479
Iterator beginc() const
Definition: RangeSet.h:529
void clear()
clear removes all integers from this set.
Definition: RangeSet.h:501
RangeSet operator^(RangeSet const &s) const
The ^ operator returns the symmetric difference between this set and s.
Definition: RangeSet.h:373
void erase(uint64_t u)
Definition: RangeSet.h:306
RangeSet & operator|=(RangeSet const &s)
Definition: RangeSet.h:389
Definition: RangeSet.h:99
RangeSet(InputIterator a, InputIterator b)
Definition: RangeSet.h:235
RangeSet & simplify(uint32_t n)
Definition: RangeSet.cc:308
RangeSet & scale(uint64_t i)
Definition: RangeSet.cc:354
size_t max_size() const
max_size returns the maximum number of ranges a set can hold.
Definition: RangeSet.h:536
Iterator endc() const
Definition: RangeSet.h:533