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

Iterator to the sparse vector values. More...

#include "sparse_vector.h"

Inheritance diagram for lar::sparse_vector< T >::const_iterator:
lar::sparse_vector< T >::iterator

Classes

struct  special
 Namespace for special initialization. More...
 

Public Types

typedef std::forward_iterator_tag iterator_category
 
typedef container_t::value_type value_type
 
typedef container_t::difference_type difference_type
 
typedef container_t::pointer pointer
 
typedef container_t::reference reference
 
typedef vector_t::const_reference const_reference
 

Public Member Functions

 const_iterator ()
 Default constructor, does not iterate anywhere. More...
 
 const_iterator (const container_t &c, size_type offset)
 Constructor from a container and a offset. More...
 
 const_iterator (const container_t &c, const typename special::begin)
 Special constructor: initializes at the beginning of the container. More...
 
 const_iterator (const container_t &c, const typename special::end)
 Special constructor: initializes at the end of the container. More...
 
const_reference operator[] (size_type offset) const
 Random access. More...
 
const_reference operator* () const
 Constant dereferenciation operator. More...
 
difference_type operator- (const const_iterator &iter) const
 Distance operator. More...
 
range_const_iterator get_current_range () const
 Returns the current range internal value; use it at your own risk!! More...
 
const_iteratoroperator++ ()
 Increment and decrement operators. More...
 
const_iterator operator++ (int)
 Increment and decrement operators. More...
 
const_iteratoroperator+= (difference_type delta)
 Increment and decrement operators. More...
 
const_iteratoroperator-= (difference_type delta)
 Increment and decrement operators. More...
 
const_iterator operator+ (difference_type delta) const
 Increment and decrement operators. More...
 
const_iterator operator- (difference_type delta) const
 Increment and decrement operators. More...
 
bool operator== (const const_iterator &as) const
 Iterator comparisons. More...
 
bool operator!= (const const_iterator &as) const
 Iterator comparisons. More...
 
bool operator< (const const_iterator &than) const
 Iterator comparisons. More...
 
bool operator> (const const_iterator &than) const
 Iterator comparisons. More...
 
bool operator<= (const const_iterator &than) const
 Iterator comparisons. More...
 
bool operator>= (const const_iterator &than) const
 Iterator comparisons. More...
 

Protected Types

typedef sparse_vector< T > container_t
 
typedef container_t::size_type size_type
 
typedef container_t::range_list_t::const_iterator ranges_const_iterator
 

Protected Member Functions

void refresh_state ()
 Reassigns the internal state according to the index. More...
 

Protected Attributes

const container_tcont
 pointer to the container More...
 
size_type index
 pointer to the current value, as absolute index More...
 
ranges_const_iterator currentRange
 pointer to the current (or next) range More...
 

Friends

class container_t
 

Detailed Description

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

Iterator to the sparse vector values.

Definition at line 1144 of file sparse_vector.h.

Member Typedef Documentation

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

Definition at line 1175 of file sparse_vector.h.

template<typename T>
typedef sparse_vector<T> lar::sparse_vector< T >::const_iterator::container_t
protected

Definition at line 1152 of file sparse_vector.h.

template<typename T>
typedef container_t::difference_type lar::sparse_vector< T >::const_iterator::difference_type

Definition at line 1170 of file sparse_vector.h.

template<typename T>
typedef std::forward_iterator_tag lar::sparse_vector< T >::const_iterator::iterator_category

Definition at line 1160 of file sparse_vector.h.

template<typename T>
typedef container_t::pointer lar::sparse_vector< T >::const_iterator::pointer

Definition at line 1171 of file sparse_vector.h.

template<typename T>
typedef container_t::range_list_t::const_iterator lar::sparse_vector< T >::const_iterator::ranges_const_iterator
protected

Definition at line 1154 of file sparse_vector.h.

template<typename T>
typedef container_t::reference lar::sparse_vector< T >::const_iterator::reference

Definition at line 1172 of file sparse_vector.h.

template<typename T>
typedef container_t::size_type lar::sparse_vector< T >::const_iterator::size_type
protected

Definition at line 1153 of file sparse_vector.h.

template<typename T>
typedef container_t::value_type lar::sparse_vector< T >::const_iterator::value_type

Definition at line 1169 of file sparse_vector.h.

Constructor & Destructor Documentation

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

Default constructor, does not iterate anywhere.

Definition at line 1179 of file sparse_vector.h.

1179 : cont(nullptr), index(0), currentRange() {}
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
size_type index
pointer to the current value, as absolute index
template<typename T>
lar::sparse_vector< T >::const_iterator::const_iterator ( const container_t c,
size_type  offset 
)
inline

Constructor from a container and a offset.

Definition at line 1182 of file sparse_vector.h.

1182  :
1183  cont(&c), index(std::min(offset, c.size())), currentRange()
1184  { refresh_state(); }
void refresh_state()
Reassigns the internal state according to the index.
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
size_type index
pointer to the current value, as absolute index
Int_t min
Definition: plot.C:26
template<typename T>
lar::sparse_vector< T >::const_iterator::const_iterator ( const container_t c,
const typename special::begin   
)
inline

Special constructor: initializes at the beginning of the container.

Definition at line 1187 of file sparse_vector.h.

1187  :
1188  cont(&c), index(0), currentRange(c.get_ranges().begin())
1189  {}
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
size_type index
pointer to the current value, as absolute index
template<typename T>
lar::sparse_vector< T >::const_iterator::const_iterator ( const container_t c,
const typename special::end   
)
inline

Special constructor: initializes at the end of the container.

Definition at line 1192 of file sparse_vector.h.

1192  :
1193  cont(&c), index(c.size()), currentRange(c.get_ranges().end())
1194  {}
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
size_type index
pointer to the current value, as absolute index

Member Function Documentation

template<typename T>
range_const_iterator lar::sparse_vector< T >::const_iterator::get_current_range ( ) const
inline

Returns the current range internal value; use it at your own risk!!

Definition at line 1239 of file sparse_vector.h.

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

1239 { return currentRange; }
ranges_const_iterator currentRange
pointer to the current (or next) range
template<typename T>
bool lar::sparse_vector< T >::const_iterator::operator!= ( const const_iterator as) const
inline

Iterator comparisons.

Definition at line 1226 of file sparse_vector.h.

References lar::sparse_vector< T >::const_iterator::cont, and lar::sparse_vector< T >::const_iterator::index.

1227  { return (cont != as.cont) || (index != as.index); }
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T >
lar::sparse_vector< T >::const_iterator::const_reference lar::sparse_vector< T >::const_iterator::operator* ( ) const

Constant dereferenciation operator.

Definition at line 1909 of file sparse_vector.h.

1909  {
1910  // no container, no idea what to do
1911  if (!cont) throw std::out_of_range("iterator to no sparse vector");
1912 
1913  // index beyond the end: can't return any reference
1914  if (index >= cont->size()) return value_zero;
1915 
1916  // are we in a valid range? if not, we are past the last range
1917  if (currentRange == cont->ranges.end()) return value_zero;
1918 
1919  // if the index is beyond the current range, we are in the void
1920  if (index < currentRange->begin_index()) return value_zero;
1921 
1922  return (*currentRange)[index];
1923 } // lar::sparse_vector<T>::const_iterator::operator*()
size_type size() const
Returns the size of the vector.
static constexpr value_type value_zero
a representation of 0
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
range_list_t ranges
list of ranges
size_type index
pointer to the current value, as absolute index
template<typename T >
lar::sparse_vector< T >::const_iterator lar::sparse_vector< T >::const_iterator::operator+ ( difference_type  delta) const

Increment and decrement operators.

Definition at line 1947 of file sparse_vector.h.

References lar::sparse_vector< T >::const_iterator::index.

1948 {
1949  if ((currentRange == cont->ranges.end())
1950  || !currentRange->includes(index + delta)
1951  )
1952  return const_iterator(*cont, index + delta);
1953  const_iterator iter(*this);
1954  iter.index += delta;
1955  return iter;
1956 } // lar::sparse_vector<T>::const_iterator::operator+()
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
range_list_t ranges
list of ranges
size_type index
pointer to the current value, as absolute index
const_iterator()
Default constructor, does not iterate anywhere.
template<typename T >
lar::sparse_vector< T >::const_iterator & lar::sparse_vector< T >::const_iterator::operator++ ( )

Increment and decrement operators.

Definition at line 1889 of file sparse_vector.h.

1889  {
1890  // no container, not doing anything;
1891  // index beyond the end: stays there
1892  if (!cont || (index >= cont->size())) return *this;
1893 
1894  // increment the internal index
1895  ++index;
1896 
1897  // were we in a valid range?
1898  if (currentRange != cont->ranges.end()) {
1899  // if the new index is beyond the current range, pick the next
1900  if (currentRange->end_index() <= index) ++currentRange;
1901  }
1902  // if we have no valid range, we are forever in the void
1903  return *this;
1904 } // lar::sparse_vector<T>::iterator::operator++()
size_type size() const
Returns the size of the vector.
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
range_list_t ranges
list of ranges
size_type index
pointer to the current value, as absolute index
template<typename T >
lar::sparse_vector< T >::const_iterator & lar::sparse_vector< T >::const_iterator::operator+= ( difference_type  delta)

Increment and decrement operators.

Definition at line 1928 of file sparse_vector.h.

1929 {
1930  if (delta == 1) return this->operator++();
1931  index += delta;
1932  if ((currentRange == cont->ranges.end())
1933  || !currentRange->includes(index)
1934  )
1935  refresh_state();
1936  return *this;
1937 } // lar::sparse_vector<T>::const_iterator::operator+=()
void refresh_state()
Reassigns the internal state according to the index.
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
range_list_t ranges
list of ranges
const_iterator & operator++()
Increment and decrement operators.
size_type index
pointer to the current value, as absolute index
template<typename T >
lar::sparse_vector< T >::const_iterator lar::sparse_vector< T >::const_iterator::operator- ( difference_type  delta) const
inline

Increment and decrement operators.

Definition at line 1960 of file sparse_vector.h.

References lar::operator+().

1961  { return this->operator+ (-delta); }
const_iterator operator+(difference_type delta) const
Increment and decrement operators.
template<typename T >
lar::sparse_vector< T >::const_iterator::difference_type lar::sparse_vector< T >::const_iterator::operator- ( const const_iterator iter) const
inline

Distance operator.

distance operator

Definition at line 1968 of file sparse_vector.h.

1969 {
1970  if (cont != iter.cont) {
1971  throw std::runtime_error("lar::sparse_vector::const_iterator:"
1972  " difference with alien iterator");
1973  }
1974  return index -iter.index;
1975 } // lar::sparse_vector<T>::const_iterator::operator-(const_iterator)
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T >
lar::sparse_vector< T >::const_iterator & lar::sparse_vector< T >::const_iterator::operator-= ( difference_type  delta)
inline

Increment and decrement operators.

Definition at line 1941 of file sparse_vector.h.

References lar::dump::operator+=().

1942  { return this->operator+= (-delta); }
const_iterator & operator+=(difference_type delta)
Increment and decrement operators.
template<typename T>
bool lar::sparse_vector< T >::const_iterator::operator< ( const const_iterator than) const
inline

Iterator comparisons.

Definition at line 1228 of file sparse_vector.h.

References lar::sparse_vector< T >::const_iterator::cont, and lar::sparse_vector< T >::const_iterator::index.

1229  { return (cont == than.cont) && (index < than.index); }
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T>
bool lar::sparse_vector< T >::const_iterator::operator<= ( const const_iterator than) const
inline

Iterator comparisons.

Definition at line 1232 of file sparse_vector.h.

References lar::sparse_vector< T >::const_iterator::cont, and lar::sparse_vector< T >::const_iterator::index.

1233  { return (cont == than.cont) && (index <= than.index); }
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T>
bool lar::sparse_vector< T >::const_iterator::operator== ( const const_iterator as) const
inline

Iterator comparisons.

Definition at line 1224 of file sparse_vector.h.

1225  { return (cont == as.cont) && (index == as.index); }
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T>
bool lar::sparse_vector< T >::const_iterator::operator> ( const const_iterator than) const
inline

Iterator comparisons.

Definition at line 1230 of file sparse_vector.h.

References lar::sparse_vector< T >::const_iterator::cont, and lar::sparse_vector< T >::const_iterator::index.

1231  { return (cont == than.cont) && (index > than.index); }
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T>
bool lar::sparse_vector< T >::const_iterator::operator>= ( const const_iterator than) const
inline

Iterator comparisons.

Definition at line 1234 of file sparse_vector.h.

References lar::sparse_vector< T >::const_iterator::cont, and lar::sparse_vector< T >::const_iterator::index.

1235  { return (cont == than.cont) && (index >= than.index); }
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T>
const_reference lar::sparse_vector< T >::const_iterator::operator[] ( size_type  offset) const
inline

Random access.

Definition at line 1197 of file sparse_vector.h.

References operator*().

1198  { return (*cont)[index + offset]; }
const container_t * cont
pointer to the container
size_type index
pointer to the current value, as absolute index
template<typename T >
void lar::sparse_vector< T >::const_iterator::refresh_state ( )
protected

Reassigns the internal state according to the index.

Definition at line 1979 of file sparse_vector.h.

1979  {
1980  // update the currentRange
1981  // currentRange is the range including the current item, or next to it
1982  if (cont) {
1983  // the following is actually the range after the index:
1985  // if the index is inside the previous index, then we want to move there:
1986  if (currentRange != cont->ranges.begin()) {
1987  if ((currentRange - 1)->end_index() > index) --currentRange;
1988  }
1989  }
1990  else {
1991  currentRange = {};
1992  }
1993 } // lar::sparse_vector<T>::const_iterator::refresh_state()
const container_t * cont
pointer to the container
ranges_const_iterator currentRange
pointer to the current (or next) range
range_list_t ranges
list of ranges
range_iterator find_next_range_iter(size_type index)
Returns an iterator to the range after index, or end() if none.
size_type index
pointer to the current value, as absolute index

Friends And Related Function Documentation

template<typename T>
friend class container_t
friend

Definition at line 1150 of file sparse_vector.h.

Member Data Documentation

template<typename T>
ranges_const_iterator lar::sparse_vector< T >::const_iterator::currentRange
protected

pointer to the current (or next) range

Definition at line 1274 of file sparse_vector.h.


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