|
|
| RangeSet (RangeSet const &)=default |
|
| RangeSet (RangeSet &&)=default |
|
RangeSet & | operator= (RangeSet const &)=default |
|
RangeSet & | operator= (RangeSet &&)=default |
|
| RangeSet ()=default |
| | The default constructor creates an empty set.
|
| template<typename InputIterator, typename = typename std::enable_if< std::is_base_of< std::input_iterator_tag, typename std::iterator_traits<InputIterator>::iterator_category >::value >::type> |
| | RangeSet (InputIterator a, InputIterator b) |
| template<typename Container, typename = typename std::enable_if< std::is_base_of< std::input_iterator_tag, typename std::iterator_traits<decltype( std::begin(std::declval<typename std::add_const<Container>::type>()) )>::iterator_category, ::value &&std::is_base_of< std::input_iterator_tag, typename std::iterator_traits< decltype(std::end(std::declval< typename std::add_const< Container >::type >()))>::iterator_category, ::value, ::type> |
| | RangeSet (Container const &c) |
| RangeSet & | simplify (std::uint32_t n) |
|
RangeSet | simplified (std::uint32_t n) const |
| | simplified returns a simplified copy of this set.
|
| RangeSet & | scale (std::uint64_t i) |
|
RangeSet | scaled (std::uint64_t i) const |
| | scaled returns a scaled copy of this set.
|
|
void | clear () |
| | clear removes all integers from this set.
|
|
void | fill () |
| | fill adds all the unsigned 64 bit integers to this set.
|
|
bool | empty () const |
| | empty checks whether there are any integers in this set.
|
| bool | full () const |
| Iterator | beginc () const |
| Iterator | endc () const |
|
size_t | max_size () const |
| | max_size returns the maximum number of ranges a set can hold.
|
|
size_t | size () const |
| | size returns the number of ranges in this set.
|
| std::uint64_t | cardinality () const |
|
void | swap (RangeSet &s) |
| bool | isValid () const |
| | RangeSet (std::uint64_t u) |
|
| RangeSet (std::uint64_t first, std::uint64_t last) |
|
template<typename U, typename = typename std::enable_if< std::is_convertible<U, std::uint64_t>::value >::type> |
| | RangeSet (std::tuple< U, U > const &range) |
|
| RangeSet (std::initializer_list< std::uint64_t >) |
|
| RangeSet (std::initializer_list< std::pair< std::uint64_t, std::uint64_t > >) |
| bool | operator== (RangeSet const &rs) const |
|
bool | operator!= (RangeSet const &rs) const |
| void | insert (std::uint64_t u) |
|
template<typename U, typename = typename std::enable_if< std::is_convertible<U, std::uint64_t>::value >::type> |
| void | insert (std::tuple< U, U > const &range) |
|
void | insert (std::uint64_t first, std::uint64_t last) |
| void | erase (std::uint64_t u) |
|
template<typename U, typename = typename std::enable_if< std::is_convertible<U, std::uint64_t>::value >::type> |
| void | erase (std::tuple< U, U > const &range) |
|
void | erase (std::uint64_t first, std::uint64_t last) |
| RangeSet & | complement () |
|
RangeSet | complemented () const |
| | complemented returns a complemented copy of this set.
|
|
RangeSet | intersection (RangeSet const &s) const |
| | intersection returns the intersection of this set and s.
|
|
RangeSet | join (RangeSet const &s) const |
| | join returns the union of this set and s.
|
|
RangeSet | difference (RangeSet const &s) const |
| | difference returns the difference between this set and s.
|
| RangeSet | symmetricDifference (RangeSet const &s) const |
|
RangeSet | operator~ () const |
| | The ~ operator returns the complement 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.
|
|
RangeSet | operator- (RangeSet const &s) const |
| | The - operator returns the difference between this set and s.
|
|
RangeSet | operator^ (RangeSet const &s) const |
| | The ^ operator returns the symmetric difference between this set and s.
|
| RangeSet & | operator&= (RangeSet const &s) |
| RangeSet & | operator|= (RangeSet const &s) |
| RangeSet & | operator-= (RangeSet const &s) |
| RangeSet & | operator^= (RangeSet const &s) |
| bool | intersects (std::uint64_t u) const |
|
bool | intersects (std::uint64_t first, std::uint64_t last) const |
|
bool | intersects (RangeSet const &s) const |
| bool | contains (std::uint64_t u) const |
|
bool | contains (std::uint64_t first, std::uint64_t last) const |
|
bool | contains (RangeSet const &s) const |
| bool | isWithin (std::uint64_t u) const |
|
bool | isWithin (std::uint64_t first, std::uint64_t last) const |
|
bool | isWithin (RangeSet const &s) const |
| bool | isDisjointFrom (std::uint64_t u) const |
|
bool | isDisjointFrom (std::uint64_t first, std::uint64_t last) const |
|
bool | isDisjointFrom (RangeSet const &s) const |
| Iterator | begin () const |
|
Iterator | cbegin () const |
| Iterator | end () const |
|
Iterator | cend () const |
A RangeSet is a set of unsigned 64 bit integers.
Internally, elements in the set are tracked using a sorted vector of disjoint, non-empty, half-open ranges, which is memory efficient for sets containing many consecutive integers.
Given a hierarchical pixelization of the sphere and a simple spherical region, a RangeSet is a good way to store the indexes of pixels intersecting the region. For an in-depth discussion of this use case, see:
Efficient data structures for masks on 2D grids M. Reinecke and E. Hivon Astronomy & Astrophysics, Volume 580, id.A132, 9 pp.
http://www.aanda.org/articles/aa/abs/2015/08/aa26549-15/aa26549-15.html
The beginning and end points of the disjoint, non-empty, half-open integer ranges in the set are stored in a std::vector<std::uint64_t>, with monotonically increasing values, except for the last one. Each pair of consecutive elements [begin, end) in the vector is a non-empty half-open range, where the value of end is defined as the integer obtained by adding one to the largest element in the range.
Mathematically, a half-open range with largest element equal to 2^64 - 1 would have an end point of 2^64. But arithmetic for unsigned 64 bit integers is modular, and adding 1 to 2^64 - 1 "wraps around" to 0. So in practice, ranges containing the largest std::uint64_t value have an end point of 0. Note that overflow is undefined for signed integers, which motivates the use of unsigned 64 bit integers for this class.
The first and last values of the internal vector are are always 0, even if no range in the set has a beginning or end point of 0. To illustrate why, consider the contents of the vector for a set containing a single integer, 3:
[0, 3, 4, 0]
The range obtained by extracting pairs of elements from the vector starting at index 1 is [3, 4), which corresponds to the contents of the set. The ranges obtained by starting at index 0 are [0, 3) and [4, 0). They correspond to the unsigned 64 bit integers not in the set.
The use of bookended half open ranges means that simply toggling the index of the first range between 0 and 1 corresponds to complementing the set. This allows many simplifications in the implementation - for example, set union and difference can be implemented in terms of set intersection and complement, since A ∪ B = ¬(¬A ∩ ¬B) and A ∖ B = A ∩ ¬B.
Many of the RangeSet methods accept ranges of integers [first, last) as input, either directly or in the form of a tuple. The values in a range are generated by starting with a value equal to first, and incrementing it until last is reached. If first == last, the range is full (it contains all possible std::uint64_t values), and if first > last, it wraps around - that is, it contains all std::uint64_t values except for [last, first).
The ranges in a set can be iterated over. Set modification may invalidate all iterators.