LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
lar::sparse_vector< T >::datarange_t Class Reference

Range class, with range and data. More...

#include "sparse_vector.h"

Inheritance diagram for lar::sparse_vector< T >::datarange_t:
lar::range_t< size_type >

Public Types

typedef range_t< size_typebase_t
 base class More...
 
typedef vector_t::iterator iterator
 
typedef vector_t::const_iterator const_iterator
 
typedef size_type size_type
 type for the indices in the range More...
 
typedef std::ptrdiff_t difference_type
 type for index difference More...
 
typedef bool(* less_int_range) (size_type, const range_t &b)
 Helper type to be used for binary searches. More...
 

Public Member Functions

 datarange_t ()
 Default constructor: an empty range. More...
 
 datarange_t (const base_t &range)
 Constructor: range initialized with 0. More...
 
template<typename ITER >
 datarange_t (size_type offset, ITER first, ITER last)
 Constructor: offset and data. More...
 
 datarange_t (size_type offset, vector_t &&data)
 Constructor: offset and data as a vector (which will be used directly) More...
 
template<typename ITER >
datarange_textend (size_type index, ITER first, ITER last)
 Appends the specified elements to this range. More...
 
void move_head (size_type to_index, value_type def_value=value_zero)
 Moves the begin of this range. More...
 
void move_tail (size_type to_index, value_type def_value=value_zero)
 Moves the end of this range. More...
 
template<typename ITER >
lar::sparse_vector< T >::datarange_textend (size_type index, ITER first, ITER last)
 
void set (size_type from, size_type to)
 Sets the borders of the range. More...
 
size_type begin_index () const
 Returns the first absolute index included in the range. More...
 
size_type end_index () const
 Returns the first absolute index not included in the range. More...
 
size_type relative_index (size_type index) const
 Returns the position within the range of the absolute index specified. More...
 
size_type size () const
 Returns the size of the range. More...
 
void resize (size_type new_size)
 Moves the end of the range to fit the specified size. More...
 
void move_head (difference_type shift)
 Moves the begin of the range by the specified amount. More...
 
void move_tail (difference_type shift)
 Moves the end of the range by the specified amount. More...
 
bool empty () const
 Returns whether the range is empty. More...
 
bool includes (size_type index) const
 Returns whether the specified absolute index is included in this range. More...
 
bool includes (const range_t &r) const
 Returns whether the specified range is completely included in this one. More...
 
bool overlap (const range_t &r) const
 Returns if this and the specified range overlap. More...
 
bool separate (const range_t &r) const
 Returns if there are elements in between this and the specified range. More...
 
bool borders (size_type index) const
 Returns whether an index is within or immediately after this range. More...
 
bool operator== (const range_t &as) const
 Returns whether the specified range has our same offset and size. More...
 
bool is_valid () const
 Returns whether the range is valid (that is, non-negative size) More...
 
iterator get_iterator (size_type index)
 Returns an iterator to the specified absolute value (no check!) More...
 
const_iterator get_iterator (size_type index) const
 Returns an iterator to the specified absolute value (no check!) More...
 
const_iterator get_const_iterator (size_type index) const
 Returns an iterator to the specified absolute value (no check!) More...
 
iterator begin ()
 begin and end iterators More...
 
iterator end ()
 begin and end iterators More...
 
const_iterator begin () const
 begin and end iterators More...
 
const_iterator end () const
 begin and end iterators More...
 
const_iterator cbegin () const
 begin and end iterators More...
 
const_iterator cend () const
 begin and end iterators More...
 
void resize (size_t new_size)
 Resizes the range (optionally filling the new elements with def_value) More...
 
void resize (size_t new_size, value_type def_value)
 Resizes the range (optionally filling the new elements with def_value) More...
 
value_typeoperator[] (size_type index)
 Returns the value at the specified absolute index. More...
 
const value_typeoperator[] (size_type index) const
 Returns the value at the specified absolute index. More...
 
const vector_tdata () const
 Return the vector of data values. More...
 
bool operator< (const range_t &than) const
 Sort: this range is smaller if its offset is smaller. More...
 

Static Public Member Functions

static bool less (const range_t &a, const range_t &b)
 Returns if a is "less" than b. More...
 
static bool less (const range_t &a, size_type b)
 Returns if a is "less" than b. More...
 
static bool less (size_type a, const range_t &b)
 Returns if a is "less" than b. More...
 

Public Attributes

size_type offset
 offset (absolute index) of the first element More...
 
size_type last
 offset (absolute index) after the last element More...
 

Protected Member Functions

void fit_size_from_data ()
 

Protected Attributes

vector_t values
 data in the range More...
 

Detailed Description

template<typename T>
class lar::sparse_vector< T >::datarange_t

Range class, with range and data.

Definition at line 1087 of file sparse_vector.h.

Member Typedef Documentation

template<typename T>
typedef range_t<size_type> lar::sparse_vector< T >::datarange_t::base_t

base class

Definition at line 1089 of file sparse_vector.h.

template<typename T>
typedef vector_t::const_iterator lar::sparse_vector< T >::datarange_t::const_iterator

Definition at line 1092 of file sparse_vector.h.

typedef std::ptrdiff_t lar::range_t< size_type >::difference_type
inherited

type for index difference

Definition at line 189 of file sparse_vector.h.

template<typename T>
typedef vector_t::iterator lar::sparse_vector< T >::datarange_t::iterator

Definition at line 1091 of file sparse_vector.h.

typedef bool(* lar::range_t< size_type >::less_int_range) (size_type, const range_t &b)
inherited

Helper type to be used for binary searches.

Definition at line 279 of file sparse_vector.h.

typedef size_type lar::range_t< size_type >::size_type
inherited

type for the indices in the range

Definition at line 188 of file sparse_vector.h.

Constructor & Destructor Documentation

template<typename T>
lar::sparse_vector< T >::datarange_t::datarange_t ( )
inline

Default constructor: an empty range.

Definition at line 1095 of file sparse_vector.h.

1095 : base_t(), values() {}
vector_t values
data in the range
range_t< size_type > base_t
base class
template<typename T>
lar::sparse_vector< T >::datarange_t::datarange_t ( const base_t range)
inline

Constructor: range initialized with 0.

Definition at line 1098 of file sparse_vector.h.

1098 : base_t(range), values(range.size()) {}
const datarange_t & range(size_t i) const
Returns the i-th non-void range (zero-based)
vector_t values
data in the range
range_t< size_type > base_t
base class
size_type size() const
Returns the size of the range.
template<typename T>
template<typename ITER >
lar::sparse_vector< T >::datarange_t::datarange_t ( size_type  offset,
ITER  first,
ITER  last 
)
inline

Constructor: offset and data.

Definition at line 1102 of file sparse_vector.h.

1102  :
1103  base_t(offset, offset + std::distance(first, last)),
1104  values(first, last)
1105  {}
vector_t values
data in the range
size_type offset
offset (absolute index) of the first element
range_t< size_type > base_t
base class
size_type last
offset (absolute index) after the last element
template<typename T>
lar::sparse_vector< T >::datarange_t::datarange_t ( size_type  offset,
vector_t &&  data 
)
inline

Constructor: offset and data as a vector (which will be used directly)

Definition at line 1108 of file sparse_vector.h.

1108  :
1109  base_t(offset, offset + data.size()), values(data)
1110  {}
vector_t values
data in the range
size_type offset
offset (absolute index) of the first element
range_t< size_type > base_t
base class
const vector_t & data() const
Return the vector of data values.

Member Function Documentation

template<typename T>
iterator lar::sparse_vector< T >::datarange_t::begin ( )
inline

begin and end iterators

Definition at line 1125 of file sparse_vector.h.

Referenced by lar::sparse_vector< T >::unset_at().

1125 { return values.begin(); }
vector_t values
data in the range
template<typename T>
const_iterator lar::sparse_vector< T >::datarange_t::begin ( ) const
inline

begin and end iterators

Definition at line 1127 of file sparse_vector.h.

1127 { return values.begin(); }
vector_t values
data in the range
size_type lar::range_t< size_type >::begin_index ( ) const
inlineinherited

Returns the first absolute index included in the range.

Definition at line 210 of file sparse_vector.h.

210 { return offset; }
size_type offset
offset (absolute index) of the first element
bool lar::range_t< size_type >::borders ( size_type  index) const
inlineinherited

Returns whether an index is within or immediately after this range.

Returns whether the specified absolute index is included in this range or is immediately after it (not before it!)

Definition at line 253 of file sparse_vector.h.

References geo::operator<().

254  { return (index >= offset) && (index <= last); }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element
template<typename T>
const_iterator lar::sparse_vector< T >::datarange_t::cbegin ( ) const
inline

begin and end iterators

Definition at line 1129 of file sparse_vector.h.

1129 { return values.cbegin(); }
vector_t values
data in the range
template<typename T>
const_iterator lar::sparse_vector< T >::datarange_t::cend ( ) const
inline

begin and end iterators

Definition at line 1130 of file sparse_vector.h.

1130 { return values.cend(); }
vector_t values
data in the range
template<typename T>
const vector_t& lar::sparse_vector< T >::datarange_t::data ( ) const
inline

Return the vector of data values.

Definition at line 1151 of file sparse_vector.h.

1151 { return values; }
vector_t values
data in the range
bool lar::range_t< size_type >::empty ( void  ) const
inlineinherited

Returns whether the range is empty.

Definition at line 231 of file sparse_vector.h.

231 { return last <= offset; }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element
template<typename T>
iterator lar::sparse_vector< T >::datarange_t::end ( )
inline

begin and end iterators

Definition at line 1126 of file sparse_vector.h.

Referenced by lar::sparse_vector< T >::unset_at().

1126 { return values.end(); }
vector_t values
data in the range
template<typename T>
const_iterator lar::sparse_vector< T >::datarange_t::end ( ) const
inline

begin and end iterators

Definition at line 1128 of file sparse_vector.h.

1128 { return values.end(); }
vector_t values
data in the range
size_type lar::range_t< size_type >::end_index ( ) const
inlineinherited

Returns the first absolute index not included in the range.

Definition at line 213 of file sparse_vector.h.

213 { return last; }
size_type last
offset (absolute index) after the last element
template<typename T>
template<typename ITER >
datarange_t& lar::sparse_vector< T >::datarange_t::extend ( size_type  index,
ITER  first,
ITER  last 
)

Appends the specified elements to this range.

Template Parameters
ITERtype of iterator of the range
Parameters
indexthe starting point
firstiterator to the first object to copy
lastiterator after the last object to copy
Returns
the extended range

Referenced by lar::sparse_vector< T >::merge_ranges(), and operator<<().

template<typename T>
template<typename ITER >
lar::sparse_vector<T>::datarange_t& lar::sparse_vector< T >::datarange_t::extend ( size_type  index,
ITER  first,
ITER  last 
)

Definition at line 2077 of file sparse_vector.h.

References max, and lar::sparse_vector< T >::datarange_t::move_head().

2078 {
2079  size_type new_size = std::max(
2080  base_t::relative_index(index) + std::distance(first, last),
2081  base_t::size());
2082  base_t::resize(new_size);
2083  values.resize(new_size);
2084  std::copy(first, last, get_iterator(index));
2085  return *this;
2086 } // lar::sparse_vector<T>::datarange_t::extend()
vector_t values
data in the range
Int_t max
Definition: plot.C:27
iterator get_iterator(size_type index)
Returns an iterator to the specified absolute value (no check!)
size_type size() const
Returns the size of the range.
size_type size_type
type for the indices in the range
void resize(size_type new_size)
Moves the end of the range to fit the specified size.
size_type last
offset (absolute index) after the last element
size_type relative_index(size_type index) const
Returns the position within the range of the absolute index specified.
template<typename T>
void lar::sparse_vector< T >::datarange_t::fit_size_from_data ( )
inlineprotected

Definition at line 1185 of file sparse_vector.h.

1185 { base_t::resize(values.size()); }
vector_t values
data in the range
void resize(size_type new_size)
Moves the end of the range to fit the specified size.
template<typename T>
const_iterator lar::sparse_vector< T >::datarange_t::get_const_iterator ( size_type  index) const
inline

Returns an iterator to the specified absolute value (no check!)

Definition at line 1119 of file sparse_vector.h.

References evd::details::begin().

1120  { return values.begin() + index - base_t::begin_index(); }
vector_t values
data in the range
size_type begin_index() const
Returns the first absolute index included in the range.
template<typename T>
iterator lar::sparse_vector< T >::datarange_t::get_iterator ( size_type  index)
inline

Returns an iterator to the specified absolute value (no check!)

Definition at line 1115 of file sparse_vector.h.

Referenced by lar::sparse_vector< T >::combine_range().

1116  { return values.begin() + index - base_t::begin_index(); }
vector_t values
data in the range
size_type begin_index() const
Returns the first absolute index included in the range.
template<typename T>
const_iterator lar::sparse_vector< T >::datarange_t::get_iterator ( size_type  index) const
inline

Returns an iterator to the specified absolute value (no check!)

Definition at line 1117 of file sparse_vector.h.

1118  { return get_const_iterator(index); }
const_iterator get_const_iterator(size_type index) const
Returns an iterator to the specified absolute value (no check!)
bool lar::range_t< size_type >::includes ( size_type  index) const
inlineinherited

Returns whether the specified absolute index is included in this range.

Definition at line 234 of file sparse_vector.h.

235  { return (index >= offset) && (index < last); }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element
bool lar::range_t< size_type >::includes ( const range_t< size_type > &  r) const
inlineinherited

Returns whether the specified range is completely included in this one.

Definition at line 238 of file sparse_vector.h.

References lar::range_t< SIZE >::begin_index(), and lar::range_t< SIZE >::end_index().

239  { return includes(r.begin_index()) && includes(r.end_index()); }
bool includes(size_type index) const
Returns whether the specified absolute index is included in this range.
bool lar::range_t< size_type >::is_valid ( ) const
inlineinherited

Returns whether the range is valid (that is, non-negative size)

Definition at line 266 of file sparse_vector.h.

References lar::range_t< SIZE >::offset.

266 { return last >= offset; }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element
static bool lar::range_t< size_type >::less ( const range_t< size_type > &  a,
const range_t< size_type > &  b 
)
inlinestaticinherited

Returns if a is "less" than b.

Definition at line 270 of file sparse_vector.h.

271  { return a.offset < b.offset; }
static bool lar::range_t< size_type >::less ( const range_t< size_type > &  a,
size_type  b 
)
inlinestaticinherited

Returns if a is "less" than b.

Definition at line 272 of file sparse_vector.h.

References lar::range_t< SIZE >::offset.

273  { return a.offset < b; }
static bool lar::range_t< size_type >::less ( size_type  a,
const range_t< size_type > &  b 
)
inlinestaticinherited

Returns if a is "less" than b.

Definition at line 274 of file sparse_vector.h.

References lar::range_t< SIZE >::offset.

275  { return a < b.offset; }
void lar::range_t< size_type >::move_head ( difference_type  shift)
inlineinherited

Moves the begin of the range by the specified amount.

Definition at line 225 of file sparse_vector.h.

225 { offset += shift; }
size_type offset
offset (absolute index) of the first element
template<typename T >
void lar::sparse_vector< T >::datarange_t::move_head ( size_type  to_index,
value_type  def_value = value_zero 
)

Moves the begin of this range.

Parameters
to_indexabsolute index to move the head to
def_valuevalue to be inserted in case of expansion of the range

Definition at line 2091 of file sparse_vector.h.

Referenced by lar::sparse_vector< T >::datarange_t::extend(), and lar::sparse_vector< T >::unset_at().

2092 {
2093  difference_type delta = to_index - base_t::begin_index();
2094  if (delta == 0) return;
2095  base_t::move_head(delta);
2096  if (delta > 0) // shrink
2097  values.erase(values.begin(), values.begin() + delta);
2098  else { // extend
2099  values.insert(values.begin(),
2100  value_const_iterator<value_type>(def_value),
2101  value_const_iterator<value_type>(def_value) - delta
2102  );
2103  }
2104 } // lar::sparse_vector<T>::datarange_t::move_head()
vector_t values
data in the range
size_type begin_index() const
Returns the first absolute index included in the range.
void move_head(difference_type shift)
Moves the begin of the range by the specified amount.
std::ptrdiff_t difference_type
type for index difference
void lar::range_t< size_type >::move_tail ( difference_type  shift)
inlineinherited

Moves the end of the range by the specified amount.

Definition at line 228 of file sparse_vector.h.

228 { last += shift; }
size_type last
offset (absolute index) after the last element
template<typename T>
void lar::sparse_vector< T >::datarange_t::move_tail ( size_type  to_index,
value_type  def_value = value_zero 
)
inline

Moves the end of this range.

Parameters
to_indexabsolute index to move the tail to
def_valuevalue to be inserted in case of expansion of the range

Definition at line 1178 of file sparse_vector.h.

Referenced by lar::sparse_vector< T >::unset_at().

1179  { resize(base_t::relative_index(to_index), def_value); }
void resize(size_t new_size)
Resizes the range (optionally filling the new elements with def_value)
size_type relative_index(size_type index) const
Returns the position within the range of the absolute index specified.
bool lar::range_t< size_type >::operator< ( const range_t< size_type > &  than) const
inlineinherited

Sort: this range is smaller if its offset is smaller.

Definition at line 258 of file sparse_vector.h.

258 { return less(*this, than); }
static bool less(const range_t &a, const range_t &b)
Returns if a is "less" than b.
bool lar::range_t< size_type >::operator== ( const range_t< size_type > &  as) const
inlineinherited

Returns whether the specified range has our same offset and size.

Definition at line 262 of file sparse_vector.h.

References lar::range_t< SIZE >::last, and lar::range_t< SIZE >::offset.

263  { return (offset == as.offset) && (last == as.last); }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element
template<typename T>
value_type& lar::sparse_vector< T >::datarange_t::operator[] ( size_type  index)
inline

Returns the value at the specified absolute index.

Definition at line 1143 of file sparse_vector.h.

1144  { return values[base_t::relative_index(index)]; }
vector_t values
data in the range
size_type relative_index(size_type index) const
Returns the position within the range of the absolute index specified.
template<typename T>
const value_type& lar::sparse_vector< T >::datarange_t::operator[] ( size_type  index) const
inline

Returns the value at the specified absolute index.

Definition at line 1145 of file sparse_vector.h.

1146  { return values[base_t::relative_index(index)]; }
vector_t values
data in the range
size_type relative_index(size_type index) const
Returns the position within the range of the absolute index specified.
bool lar::range_t< size_type >::overlap ( const range_t< size_type > &  r) const
inlineinherited

Returns if this and the specified range overlap.

Definition at line 242 of file sparse_vector.h.

References lar::range_t< SIZE >::begin_index(), and lar::range_t< SIZE >::end_index().

243  { return (begin_index() < r.end_index()) && (end_index() > r.begin_index()); }
size_type begin_index() const
Returns the first absolute index included in the range.
size_type end_index() const
Returns the first absolute index not included in the range.
size_type lar::range_t< size_type >::relative_index ( size_type  index) const
inlineinherited

Returns the position within the range of the absolute index specified.

Definition at line 216 of file sparse_vector.h.

216 { return index - offset; }
size_type offset
offset (absolute index) of the first element
void lar::range_t< size_type >::resize ( size_type  new_size)
inlineinherited

Moves the end of the range to fit the specified size.

Definition at line 222 of file sparse_vector.h.

222 { last = offset + new_size; }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element
template<typename T>
void lar::sparse_vector< T >::datarange_t::resize ( size_t  new_size)
inline

Resizes the range (optionally filling the new elements with def_value)

Definition at line 1135 of file sparse_vector.h.

1136  { values.resize(new_size); fit_size_from_data(); }
vector_t values
data in the range
template<typename T>
void lar::sparse_vector< T >::datarange_t::resize ( size_t  new_size,
value_type  def_value 
)
inline

Resizes the range (optionally filling the new elements with def_value)

Definition at line 1137 of file sparse_vector.h.

1138  { values.resize(new_size, def_value); fit_size_from_data(); }
vector_t values
data in the range
bool lar::range_t< size_type >::separate ( const range_t< size_type > &  r) const
inlineinherited

Returns if there are elements in between this and the specified range.

Definition at line 246 of file sparse_vector.h.

References lar::range_t< SIZE >::begin_index(), and lar::range_t< SIZE >::end_index().

247  { return (begin_index() > r.end_index()) || (end_index() < r.begin_index()); }
size_type begin_index() const
Returns the first absolute index included in the range.
size_type end_index() const
Returns the first absolute index not included in the range.
void lar::range_t< size_type >::set ( size_type  from,
size_type  to 
)
inlineinherited

Sets the borders of the range.

Definition at line 206 of file sparse_vector.h.

References max.

207  { offset = from; last = std::max(from, to); }
size_type offset
offset (absolute index) of the first element
Int_t max
Definition: plot.C:27
size_type last
offset (absolute index) after the last element
size_type lar::range_t< size_type >::size ( void  ) const
inlineinherited

Returns the size of the range.

Definition at line 219 of file sparse_vector.h.

219 { return last - offset; }
size_type offset
offset (absolute index) of the first element
size_type last
offset (absolute index) after the last element

Member Data Documentation

size_type lar::range_t< size_type >::last
inherited

offset (absolute index) after the last element

Definition at line 195 of file sparse_vector.h.

size_type lar::range_t< size_type >::offset
inherited

offset (absolute index) of the first element

Definition at line 192 of file sparse_vector.h.

template<typename T>
vector_t lar::sparse_vector< T >::datarange_t::values
protected

data in the range

Definition at line 1183 of file sparse_vector.h.


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