LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
util::UniqueRangeSet< T > Class Template Reference

std::set of util::Range, which does not allow any overlap in contained element. std::set<Range> w/ modified insert/emplace function. Original std::set does not allow
modification of element. I assume what we're interested in is "find if the range already \n exists, and merge if it exists". The insert function does that by recursively looking up
overlapping elements w.r.t. input argument of insert function.
More...

#include "Range.h"

Inheritance diagram for util::UniqueRangeSet< T >:

Public Member Functions

 UniqueRangeSet ()
 default ctor More...
 
 ~UniqueRangeSet ()
 default dtor More...
 
void Merge (const UniqueRangeSet< T > &in)
 Merge two UniqueRangeSet<T> More...
 
const T & Start () const
 Very first "start" of all contained range. More...
 
const T & End () const
 Very last "end" of all contained range. More...
 
UniqueRangeSet< T > Exclusive (const T start, const T end) const
 
size_t emplace (const T &start, const T &end)
 Modified emplace that merges overlapping range. Return = # merged range. More...
 
size_t insert (const Range< T > &a)
 Modified insert that merges overlapping range. Return = # merged range. More...
 

Public Attributes

K keys
 STL member. More...
 

Detailed Description

template<class T>
class util::UniqueRangeSet< T >

std::set of util::Range, which does not allow any overlap in contained element. std::set<Range> w/ modified insert/emplace function. Original std::set does not allow
modification of element. I assume what we're interested in is "find if the range already \n exists, and merge if it exists". The insert function does that by recursively looking up
overlapping elements w.r.t. input argument of insert function.

One important function worth noting is util::UniqueRangeSet::Exclusive which takes two
input arguments, "start" and "end", and returns util::UniqueRangeSet of all exclusive
regions between "start" and "end". By definition, merging this return with the original
instance will result in 1 huge util::Range.

Definition at line 24 of file Range.h.

Constructor & Destructor Documentation

template<class T >
util::UniqueRangeSet< T >::UniqueRangeSet ( )
inline

default ctor

Definition at line 41 of file UniqueRangeSet.h.

41 {}
template<class T >
util::UniqueRangeSet< T >::~UniqueRangeSet ( )
inline

default dtor

Definition at line 43 of file UniqueRangeSet.h.

43 {}

Member Function Documentation

template<class T >
size_t util::UniqueRangeSet< T >::emplace ( const T &  start,
const T &  end 
)
inline

Modified emplace that merges overlapping range. Return = # merged range.

Definition at line 96 of file UniqueRangeSet.h.

References evd::details::end(), util::UniqueRangeSet< T >::insert(), and util::Range< T >::Merge().

Referenced by util::UniqueRangeSet< T >::insert(), and util::UniqueRangeSet< T >::Merge().

96  {
97 
98  auto res = std::set<util::Range<T> >::emplace(start,end);
99  if(res.second) return 0;
100 
101  auto& iter = res.first;
102  auto tmp_a = Range<T>(start,end);
103  size_t ctr=0;
104  while(iter != this->end()) {
105  tmp_a.Merge((*iter));
106  this->erase(iter);
107  iter = this->find(tmp_a);
108  ++ctr;
109  }
110  this->insert(tmp_a);
111  return ctr;
112  }
size_t insert(const Range< T > &a)
Modified insert that merges overlapping range. Return = # merged range.
size_t emplace(const T &start, const T &end)
Modified emplace that merges overlapping range. Return = # merged range.
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
template<class T >
const T& util::UniqueRangeSet< T >::End ( ) const
inline

Very last "end" of all contained range.

Definition at line 57 of file UniqueRangeSet.h.

58  {
59  if(!(this->size())) throw std::runtime_error("Nothing in the set!");
60  return (*(this->rbegin()))._window.second;
61  }
template<class T >
UniqueRangeSet<T> util::UniqueRangeSet< T >::Exclusive ( const T  start,
const T  end 
) const
inline

It takes two input arguments, "start" and "end", and returns util::UniqueRangeSet
of all exclusive regions between "start" and "end". By definition, merging this
return with the original instance will result in 1 huge util::Range.

Definition at line 68 of file UniqueRangeSet.h.

References evd::details::begin(), and evd::details::end().

69  {
70  UniqueRangeSet<T> res;
71 
72  auto start_iter = std::lower_bound(this->begin(),this->end(),start);
73  auto end_iter = std::lower_bound(this->begin(),this->end(),end);
74 
75  // Anything to add to the head?
76  if(start < (*start_iter)._window.first) res.emplace(start,(*start_iter)._window.first);
77 
78  auto iter = start_iter;
79  T tmp_end=end;
80  while(iter != this->end()) {
81  if(iter != start_iter)
82  res.emplace(tmp_end,(*iter)._window.first);
83  tmp_end = (*iter)._window.second;
84  if(iter == end_iter) break;
85  ++iter;
86  }
87 
88  // Anything to add to the tail?
89  if(tmp_end < end)
90  res.emplace(tmp_end,end);
91 
92  return res;
93  }
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
template<class T >
size_t util::UniqueRangeSet< T >::insert ( const Range< T > &  a)
inline

Modified insert that merges overlapping range. Return = # merged range.

Definition at line 115 of file UniqueRangeSet.h.

References util::Range< T >::_window, and util::UniqueRangeSet< T >::emplace().

Referenced by util::UniqueRangeSet< T >::emplace().

116  {return emplace(a._window.first,a._window.second);}
size_t emplace(const T &start, const T &end)
Modified emplace that merges overlapping range. Return = # merged range.
template<class T >
void util::UniqueRangeSet< T >::Merge ( const UniqueRangeSet< T > &  in)
inline

Merge two UniqueRangeSet<T>

Definition at line 46 of file UniqueRangeSet.h.

References util::UniqueRangeSet< T >::emplace().

47  { for(auto const& r : in) emplace(r._window.first,r._window.second); }
size_t emplace(const T &start, const T &end)
Modified emplace that merges overlapping range. Return = # merged range.
ifstream in
Definition: comparison.C:7
template<class T >
const T& util::UniqueRangeSet< T >::Start ( ) const
inline

Very first "start" of all contained range.

Definition at line 50 of file UniqueRangeSet.h.

References evd::details::begin().

51  {
52  if(!(this->size())) throw std::runtime_error("Nothing in the set!");
53  return (*(this->begin()))._window.first;
54  }
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)

Member Data Documentation

K std::set< K >::keys
inherited

STL member.


The documentation for this class was generated from the following files: