14 #ifndef UNIQUERANGESET_H 15 #define UNIQUERANGESET_H 36 class UniqueRangeSet :
public std::set<util::Range<T>> {
46 for (
auto const&
r : in)
47 emplace(
r._window.first,
r._window.second);
53 if (!(this->
size()))
throw std::runtime_error(
"Nothing in the set!");
54 return (*(this->
begin()))._window.first;
60 if (!(this->
size()))
throw std::runtime_error(
"Nothing in the set!");
61 return (*(this->rbegin()))._window.second;
73 auto start_iter = std::lower_bound(this->
begin(), this->
end(), start);
74 auto end_iter = std::lower_bound(this->
begin(), this->
end(), end);
77 if (start < (*start_iter)._window.first) res.emplace(start, (*start_iter)._window.first);
79 auto iter = start_iter;
81 while (iter != this->
end()) {
82 if (iter != start_iter) res.emplace(tmp_end, (*iter)._window.first);
83 tmp_end = (*iter)._window.second;
84 if (iter == end_iter)
break;
89 if (tmp_end < end) res.emplace(tmp_end, end);
98 auto res = std::set<util::Range<T>>
::emplace(start, end);
99 if (res.second)
return 0;
101 auto& iter = res.first;
104 while (iter != this->
end()) {
105 tmp_a.
Merge((*iter));
107 iter = this->find(tmp_a);
size_t insert(const Range< T > &a)
Modified insert that merges overlapping range. Return = # merged range.
void Merge(const Range &a)
Merge two util::Range into 1.
Namespace for general, non-LArSoft-specific utilities.
UniqueRangeSet()
default ctor
void Merge(const UniqueRangeSet< T > &in)
Merge two UniqueRangeSet<T>
~UniqueRangeSet()
default dtor
const T & Start() const
Very first "start" of all contained range.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Class def header for a class Range.
size_t emplace(const T &start, const T &end)
Modified emplace that merges overlapping range. Return = # merged range.
UniqueRangeSet< T > Exclusive(const T start, const T end) const
std::pair< T, T > _window
Protected to avoid user's illegal modification on first/second (sorry users!)
std::set of util::Range, which does not allow any overlap in contained element. std::set<Range> w/ mo...
represents a "Range" w/ notion of ordering. A range is defined by a pair of "start" and "end" values...
const T & End() const
Very last "end" of all contained range.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.