LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar::sparse_vector< T >::const_datarange_t Class Reference

A constant reference to a data range. More...

#include "sparse_vector.h"

Inheritance diagram for lar::sparse_vector< T >::const_datarange_t:
lar::sparse_vector< T >::datarange_t

Public Types

using iterator = typename datarange_t::iterator
 
using const_iterator = typename datarange_t::const_iterator
 
using less_int_range = typename datarange_t::less_int_range
 

Public Member Functions

decltype(auto) begin ()
 
decltype(auto) end ()
 
const vector_tdata () const
 Return the vector of data values (only constant access). More...
 
 ~const_datarange_t ()=delete
 

Protected Member Functions

decltype(auto) friend details::make_const_datarange_t (datarange_t &)
 
datarange_t const & base () const
 
datarange_tbase ()
 

Static Protected Member Functions

static void static_check ()
 

Private Types

typedef range_t< size_typebase_t
 base class More...
 
typedef size_type size_type
 type for the indices in the range More...
 
typedef std::ptrdiff_t difference_type
 type for index difference More...
 

Private Member Functions

void resize (size_type new_size)
 Moves the end of the range to fit the specified size. More...
 
template<typename ITER >
datarange_textend (size_type index, ITER first, ITER last)
 Appends the specified elements to this range. More...
 
template<typename ITER >
lar::sparse_vector< T >::datarange_textend (size_type index, ITER first, ITER last)
 
void move_head (size_type to_index, value_type def_value=value_zero)
 Moves the begin of this range. More...
 
void move_head (difference_type shift)
 Moves the begin of the range by the specified amount. More...
 
void move_tail (size_type to_index, value_type def_value=value_zero)
 Moves the end of this range. More...
 
void move_tail (difference_type shift)
 Moves the end of the range by the specified amount. More...
 
template<typename Stream >
void dump (Stream &&out) const
 Dumps the content of this data range into a stream. More...
 
void fit_size_from_data ()
 
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...
 
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...
 
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...
 
bool operator< (const range_t &than) const
 Sort: this range is smaller if its offset is smaller. More...
 

Static Private 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...
 

Private Attributes

vector_t values
 data in the range More...
 
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 >::const_datarange_t

A constant reference to a data range.

Values in the range can be modified, but their position and number can not.

Definition at line 1360 of file sparse_vector.h.

Member Typedef Documentation

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

base class

Definition at line 1234 of file sparse_vector.h.

Definition at line 1363 of file sparse_vector.h.

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

type for index difference

Definition at line 206 of file sparse_vector.h.

template<typename T>
using lar::sparse_vector< T >::const_datarange_t::iterator = typename datarange_t::iterator

Definition at line 1362 of file sparse_vector.h.

template<typename T>
using lar::sparse_vector< T >::const_datarange_t::less_int_range = typename datarange_t::less_int_range

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

Constructor & Destructor Documentation

template<typename T>
lar::sparse_vector< T >::const_datarange_t::~const_datarange_t ( )
delete

Member Function Documentation

template<typename T>
datarange_t const& lar::sparse_vector< T >::const_datarange_t::base ( ) const
inlineprotected

Definition at line 1402 of file sparse_vector.h.

1402 { return static_cast<datarange_t const&>(*this); }
datarange_t()
Default constructor: an empty range.
template<typename T>
datarange_t& lar::sparse_vector< T >::const_datarange_t::base ( )
inlineprotected

Definition at line 1403 of file sparse_vector.h.

1403 { return static_cast<datarange_t&>(*this); }
datarange_t()
Default constructor: an empty range.
template<typename T>
const_iterator lar::sparse_vector< T >::datarange_t::begin ( ) const
inlineinherited

begin and end iterators

Definition at line 1270 of file sparse_vector.h.

References util::values().

1270 { return values.begin(); }
vector_t values
data in the range
template<typename T>
decltype(auto) lar::sparse_vector< T >::const_datarange_t::begin ( )
inline

Definition at line 1385 of file sparse_vector.h.

References util::begin().

1385 { return datarange_t::begin(); }
iterator begin()
begin and end iterators
size_type lar::range_t< size_type >::begin_index ( ) const
inlineinherited

Returns the first absolute index included in the range.

Definition at line 227 of file sparse_vector.h.

227 { 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 275 of file sparse_vector.h.

References geo::operator<().

275 { 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
inlineinherited

begin and end iterators

Definition at line 1272 of file sparse_vector.h.

References util::values().

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

begin and end iterators

Definition at line 1273 of file sparse_vector.h.

References util::values().

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

Return the vector of data values (only constant access).

Definition at line 1395 of file sparse_vector.h.

1395 { return base().values; }
vector_t values
data in the range
datarange_t const & base() const
template<typename T>
decltype(auto) friend lar::sparse_vector< T >::const_datarange_t::details::make_const_datarange_t ( datarange_t )
protected
template<typename T >
template<typename Stream >
void lar::sparse_vector< T >::datarange_t::dump ( Stream &&  out) const
inherited

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 2390 of file sparse_vector.h.

References util::size(), and util::values().

2391 {
2392  out << "[" << this->begin_index() << " - " << this->end_index() << "] (" << this->size()
2393  << "): {";
2394  for (auto const& v : this->values)
2395  out << " " << v;
2396  out << " }";
2397 } // 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.
bool lar::range_t< size_type >::empty ( ) const
inlineinherited

Returns whether the range is empty.

Definition at line 248 of file sparse_vector.h.

248 { 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>
const_iterator lar::sparse_vector< T >::datarange_t::end ( ) const
inlineinherited

begin and end iterators

Definition at line 1271 of file sparse_vector.h.

References util::values().

1271 { return values.end(); }
vector_t values
data in the range
template<typename T>
decltype(auto) lar::sparse_vector< T >::const_datarange_t::end ( )
inline

Definition at line 1386 of file sparse_vector.h.

References util::end().

1386 { return datarange_t::end(); }
iterator end()
begin and end iterators
size_type lar::range_t< size_type >::end_index ( ) const
inlineinherited

Returns the first absolute index not included in the range.

Definition at line 230 of file sparse_vector.h.

230 { 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 
)
inherited

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().

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 
)
inherited

Definition at line 2362 of file sparse_vector.h.

References util::size(), and util::values().

2363 {
2364  size_type new_size =
2365  std::max(base_t::relative_index(index) + std::distance(first, last), base_t::size());
2366  base_t::resize(new_size);
2367  values.resize(new_size);
2368  std::copy(first, last, get_iterator(index));
2369  return *this;
2370 } // 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!)
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 ( )
inlineprotectedinherited

Definition at line 1350 of file sparse_vector.h.

1350 { 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
inlineinherited

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

Definition at line 1260 of file sparse_vector.h.

References util::begin(), and util::values().

1261  {
1262  return values.begin() + index - base_t::begin_index();
1263  }
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)
inlineinherited

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

Definition at line 1258 of file sparse_vector.h.

1258 { 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
inlineinherited

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

Definition at line 1259 of file sparse_vector.h.

1259 { 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 251 of file sparse_vector.h.

251 { 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 254 of file sparse_vector.h.

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

255  {
256  return includes(r.begin_index()) && includes(r.end_index());
257  }
TRandom r
Definition: spectrum.C:23
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 286 of file sparse_vector.h.

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

286 { 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 290 of file sparse_vector.h.

290 { 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 291 of file sparse_vector.h.

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

291 { 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 292 of file sparse_vector.h.

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

292 { 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 242 of file sparse_vector.h.

242 { 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 
)
inherited

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 2373 of file sparse_vector.h.

References util::values().

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

2375 {
2376  difference_type delta = to_index - base_t::begin_index();
2377  if (delta == 0) return;
2378  base_t::move_head(delta);
2379  if (delta > 0) // shrink
2380  values.erase(values.begin(), values.begin() + delta);
2381  else { // extend
2382  values.insert(values.begin(),
2383  value_const_iterator<value_type>(def_value),
2384  value_const_iterator<value_type>(def_value) - delta);
2385  }
2386 } // 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 245 of file sparse_vector.h.

245 { 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 
)
inlineinherited

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 1328 of file sparse_vector.h.

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

1329  {
1330  resize(base_t::relative_index(to_index), def_value);
1331  }
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 279 of file sparse_vector.h.

279 { 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 283 of file sparse_vector.h.

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

283 { 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)
inlineinherited

Returns the value at the specified absolute index.

Definition at line 1292 of file sparse_vector.h.

1292 { 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
inlineinherited

Returns the value at the specified absolute index.

Definition at line 1293 of file sparse_vector.h.

References util::values().

1294  {
1295  return values[base_t::relative_index(index)];
1296  }
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 260 of file sparse_vector.h.

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

261  {
262  return (begin_index() < r.end_index()) && (end_index() > r.begin_index());
263  }
TRandom r
Definition: spectrum.C:23
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 233 of file sparse_vector.h.

233 { 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 239 of file sparse_vector.h.

239 { 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)
inlineinherited

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

Definition at line 1278 of file sparse_vector.h.

1279  {
1280  values.resize(new_size);
1282  }
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 
)
inlineinherited

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

Definition at line 1283 of file sparse_vector.h.

References util::values().

1284  {
1285  values.resize(new_size, def_value);
1287  }
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 266 of file sparse_vector.h.

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

267  {
268  return (begin_index() > r.end_index()) || (end_index() < r.begin_index());
269  }
TRandom r
Definition: spectrum.C:23
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 220 of file sparse_vector.h.

221  {
222  offset = from;
223  last = std::max(from, to);
224  }
size_type offset
offset (absolute index) of the first element
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 236 of file sparse_vector.h.

236 { 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>
static void lar::sparse_vector< T >::const_datarange_t::static_check ( )
inlinestaticprotected

Definition at line 1405 of file sparse_vector.h.

1405 { static_assert(sizeof(const_datarange_t) == sizeof(datarange_t)); }
datarange_t()
Default constructor: an empty range.

Member Data Documentation

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

offset (absolute index) after the last element

Definition at line 211 of file sparse_vector.h.

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

offset (absolute index) of the first element

Definition at line 208 of file sparse_vector.h.

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

data in the range

Definition at line 1348 of file sparse_vector.h.


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