All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
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...
 

Additional Inherited Members

- Public Attributes inherited from std::set< 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 23 of file Range.h.

Constructor & Destructor Documentation

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

default ctor

Definition at line 39 of file UniqueRangeSet.h.

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

default dtor

Definition at line 41 of file UniqueRangeSet.h.

41 {}

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 94 of file UniqueRangeSet.h.

94  {
95 
96  auto res = std::set<util::Range<T> >::emplace(start,end);
97  if(res.second) return 0;
98 
99  auto& iter = res.first;
100  auto tmp_a = Range<T>(start,end);
101  size_t ctr=0;
102  while(iter != this->end()) {
103  tmp_a.Merge((*iter));
104  this->erase(iter);
105  iter = this->find(tmp_a);
106  ++ctr;
107  }
108  this->insert(tmp_a);
109  return ctr;
110  }
size_t insert(const Range< T > &a)
Modified insert that merges overlapping range. Return = # merged range.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
size_t emplace(const T &start, const T &end)
Modified emplace that merges overlapping range. Return = # merged range.
template<class T >
const T& util::UniqueRangeSet< T >::End ( ) const
inline

Very last "end" of all contained range.

Definition at line 55 of file UniqueRangeSet.h.

56  {
57  if(!(this->size())) throw std::runtime_error("Nothing in the set!");
58  return (*(this->rbegin()))._window.second;
59  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
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 66 of file UniqueRangeSet.h.

67  {
68  UniqueRangeSet<T> res;
69 
70  auto start_iter = std::lower_bound(this->begin(),this->end(),start);
71  auto end_iter = std::lower_bound(this->begin(),this->end(),end);
72 
73  // Anything to add to the head?
74  if(start < (*start_iter)._window.first) res.emplace(start,(*start_iter)._window.first);
75 
76  auto iter = start_iter;
77  T tmp_end=end;
78  while(iter != this->end()) {
79  if(iter != start_iter)
80  res.emplace(tmp_end,(*iter)._window.first);
81  tmp_end = (*iter)._window.second;
82  if(iter == end_iter) break;
83  ++iter;
84  }
85 
86  // Anything to add to the tail?
87  if(tmp_end < end)
88  res.emplace(tmp_end,end);
89 
90  return res;
91  }
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
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 113 of file UniqueRangeSet.h.

114  {return emplace(a._window.first,a._window.second);}
process_name gaushit a
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 44 of file UniqueRangeSet.h.

45  { 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.
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
esac echo uname r
template<class T >
const T& util::UniqueRangeSet< T >::Start ( ) const
inline

Very first "start" of all contained range.

Definition at line 48 of file UniqueRangeSet.h.

49  {
50  if(!(this->size())) throw std::runtime_error("Nothing in the set!");
51  return (*(this->begin()))._window.first;
52  }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72

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