48 template <
class U>
friend std::ostream& operator<<(std::ostream& _out, RangeMask<U>
const& _r);
70 _items -= (ret.
m_ranges[i->first] =
std::min(i->first + _items, i->second)) - i->first;
88 if (last !=
m_all.second)
128 return (--it)->second > _i;
149 m_all = std::make_pair(0, 0);
153 std::pair<T, T>
const&
all()
const {
return m_all; }
187 auto uit =
m_ranges.upper_bound(_t);
189 if (it !=
m_ranges.end() && it->first <= _t && it->second > _t)
199 c += r.second - r.first;
214 return m_ranges.rbegin()->second - 1;
224 template <
class T>
inline std::ostream& operator<<(std::ostream& _out, RangeMask<T>
const& _r)
226 _out << _r.m_all.first <<
"{ ";
227 for (
auto const& i: _r.m_ranges)
228 _out <<
"[" << i.first <<
", " << i.second <<
") ";
229 _out <<
"}" << _r.m_all.second;
236 for (
auto i = _m.first; i < _m.second;)
242 auto rangeAfter =
m_ranges.upper_bound(i);
244 auto it = rangeAfter ==
m_ranges.begin() ?
m_ranges.end() : std::prev(rangeAfter);
245 if (it ==
m_ranges.end() || it->second < i)
251 if (rangeAfter ==
m_ranges.end() || rangeAfter->first > _m.second)
259 if (rangeAfter->first == i)
261 i = rangeAfter->second;
266 i =
m_ranges[i] = rangeAfter->second;
271 else if (it->second == i)
275 if (rangeAfter ==
m_ranges.end() || rangeAfter->first > _m.second)
284 i =
m_ranges[it->first] = rangeAfter->second;
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
RangeMask(Range const &_c)
Constructs an empty range mask with ground range _c.
std::vector< Range > Ranges
RangeMask & operator+=(Range const &_m)
RangeMask unionedWith(RangeMask const &_m) const
RangeMask()
Constructs an empty range mask with empty ground range.
void extendAll(T _i)
Extends the ground range to include _i.
RangeMask & unionWith(T _i)
Adds the single element _i to the range mask.
assert(len-trim+(2 *lenIndices)<=WIDTH)
const_iterator & operator++()
UnsignedRange m_all
The ground range.
std::pair< unsigned, unsigned > UnsignedRange
RangeMask const * m_owner
RangeMask & unionWith(RangeMask const &_m)
RangeMask & invert()
Changes the range mask to its complement relative to the ground range and returns a reference to itse...
bool operator!=(const_iterator const &_i) const
std::vector< UnsignedRange > UnsignedRanges
const_iterator begin() const
const_iterator end() const
RangeMask inverted() const
RangeMask lowest(decltype(T{}-T{}) _items) const
const_iterator operator++(int)
bool contains(T _i) const
RangeMask & operator+=(T _m)
Adds the single element _i to the range mask.
RangeMask operator-(S const &_m) const
RangeMask operator~() const
RangeMask operator+(RangeMask const &_m) const
bool operator==(const_iterator const &_i) const
std::map< T, T > m_ranges
Mapping begin -> end containing the ranges.
std::pair< T, T > const & all() const
dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b)
Set of elements of a certain "ground range" representable by unions of ranges inside this ground rang...
RangeMask & operator-=(S const &_m)
bool operator<(const_iterator const &_i) const
const_iterator(RangeMask const &_m, bool _end)
RangeMask & operator+=(RangeMask const &_m)
RangeMask(T _begin, T _end)
Constructs an empty range mask with ground range [_begin, _end).