All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
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 > lar::sparse_vector< T >::const_datarange_t

Public Types

typedef range_t< size_typebase_t
 base class More...
 
typedef vector_t::iterator iterator
 
typedef vector_t::const_iterator const_iterator
 
- Public Types inherited from lar::range_t< size_type >
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 Stream >
void dump (Stream &&out) const
 Dumps the content of this data range into a stream. More...
 
template<typename ITER >
lar::sparse_vector< T >
::datarange_t
extend (size_type index, ITER first, ITER last)
 
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
 
const_iterator get_const_iterator (size_type index) const
 
iterator begin ()
 begin and end iterators More...
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
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)
 
value_typeoperator[] (size_type index)
 Returns the value at the specified absolute index. More...
 
const value_typeoperator[] (size_type index) const
 
const vector_tdata () const
 Return the vector of data values. More...
 
- Public Member Functions inherited from lar::range_t< size_type >
 range_t ()
 Default constructor: empty range. More...
 
 range_t (size_type from, size_type to)
 Constructor from first and last index. More...
 
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...
 
bool operator< (const range_t &than) const
 Sort: this range is smaller if its offset is smaller. More...
 

Protected Member Functions

void fit_size_from_data ()
 

Protected Attributes

vector_t values
 data in the range More...
 

Additional Inherited Members

- Static Public Member Functions inherited from lar::range_t< size_type >
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)
 
static bool less (size_type a, const range_t &b)
 
- Public Attributes inherited from lar::range_t< size_type >
size_type offset
 offset (absolute index) of the first element More...
 
size_type last
 offset (absolute index) after the last element More...
 

Detailed Description

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

Range class, with range and data.

Definition at line 1202 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 1204 of file sparse_vector.h.

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

Definition at line 1207 of file sparse_vector.h.

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

Definition at line 1206 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 1210 of file sparse_vector.h.

1210 : 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 1213 of file sparse_vector.h.

1213 : 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 1217 of file sparse_vector.h.

1217  :
1219  values(first, last)
1220  {}
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
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
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 1223 of file sparse_vector.h.

1223  :
1224  base_t(offset, offset + data.size()), values(data)
1225  {}
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 1240 of file sparse_vector.h.

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

Definition at line 1242 of file sparse_vector.h.

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

Definition at line 1244 of file sparse_vector.h.

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

Definition at line 1245 of file sparse_vector.h.

1245 { 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 1266 of file sparse_vector.h.

1266 { return values; }
vector_t values
data in the range
template<typename T >
template<typename Stream >
void lar::sparse_vector< T >::datarange_t::dump ( Stream &&  out) const

Dumps the content of this data range into a stream.

Template Parameters
Streamtype of stream to sent the dump to
Parameters
outstream to sent the dump to

The output format is:

[min - max] (size) { values... }

Output is on a single line, which is not terminated.

Definition at line 2384 of file sparse_vector.h.

2384  {
2385  out << "[" << this->begin_index() << " - " << this->end_index() << "] ("
2386  << this->size() << "): {";
2387  for (auto const& v: this->values) out << " " << v;
2388  out << " }";
2389 } // lar::sparse_vector<T>::datarange_t::dump()
vector_t values
data in the range
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 size() const
Returns the size of the range.
template<typename T>
iterator lar::sparse_vector< T >::datarange_t::end ( )
inline

Definition at line 1241 of file sparse_vector.h.

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

Definition at line 1243 of file sparse_vector.h.

1243 { return values.end(); }
vector_t values
data in the range
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
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 2352 of file sparse_vector.h.

2353 {
2354  size_type new_size = std::max(
2356  base_t::size());
2357  base_t::resize(new_size);
2358  values.resize(new_size);
2359  std::copy(first, last, get_iterator(index));
2360  return *this;
2361 } // lar::sparse_vector<T>::datarange_t::extend()
vector_t values
data in the range
iterator get_iterator(size_type index)
Returns an iterator to the specified absolute value (no check!)
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
size_type size() const
Returns the size of the range.
size_type size_type
type for the indices in the range
T copy(T const &v)
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 1314 of file sparse_vector.h.

1314 { 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

Definition at line 1234 of file sparse_vector.h.

1235  { 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 1230 of file sparse_vector.h.

1231  { 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

Definition at line 1232 of file sparse_vector.h.

1233  { return get_const_iterator(index); }
const_iterator get_const_iterator(size_type index) const
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 2366 of file sparse_vector.h.

2367 {
2368  difference_type delta = to_index - base_t::begin_index();
2369  if (delta == 0) return;
2370  base_t::move_head(delta);
2371  if (delta > 0) // shrink
2372  values.erase(values.begin(), values.begin() + delta);
2373  else { // extend
2374  values.insert(values.begin(),
2375  value_const_iterator<value_type>(def_value),
2376  value_const_iterator<value_type>(def_value) - delta
2377  );
2378  }
2379 } // 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
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 1293 of file sparse_vector.h.

1294  { 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.
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 1258 of file sparse_vector.h.

1259  { 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

Definition at line 1260 of file sparse_vector.h.

1261  { 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>
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 1250 of file sparse_vector.h.

1251  { 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

Definition at line 1252 of file sparse_vector.h.

1253  { values.resize(new_size, def_value); fit_size_from_data(); }
vector_t values
data in the range

Member Data Documentation

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

data in the range

Definition at line 1312 of file sparse_vector.h.


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