Opm::SparseVector< T > Class Template Reference

#include <SparseVector.hpp>

Public Member Functions

 SparseVector ()
 Default constructor. Yields an empty SparseVector. More...
 
 SparseVector (int sz)
 
template<typename DataIter , typename IntegerIter >
 SparseVector (int sz, DataIter data_beg, DataIter data_end, IntegerIter index_beg, IntegerIter index_end)
 
void addElement (const T &elem, int index)
 
bool empty () const
 
int size () const
 
int nonzeroSize () const
 Returns the number of nonzero data elements. More...
 
void clear ()
 Makes the vector empty(). More...
 
bool operator== (const SparseVector &other) const
 Equality. More...
 
const T & element (int index) const
 
const T & nonzeroElement (int nzindex) const
 
int nonzeroIndex (int nzindex) const
 

Detailed Description

template<typename T>
class Opm::SparseVector< T >

A SparseVector stores a vector with possibly many empty elements as efficiently as possible. It is supposed to behave similarly to a standard vector, but since direct indexing is a O(log n) operation instead of O(1), we do not supply it as operator[].

Constructor & Destructor Documentation

template<typename T >
Opm::SparseVector< T >::SparseVector ( )
inline

Default constructor. Yields an empty SparseVector.

template<typename T >
Opm::SparseVector< T >::SparseVector ( int  sz)
inlineexplicit

Constructs a SparseVector with a given size, but no nonzero elements.

template<typename T >
template<typename DataIter , typename IntegerIter >
Opm::SparseVector< T >::SparseVector ( int  sz,
DataIter  data_beg,
DataIter  data_end,
IntegerIter  index_beg,
IntegerIter  index_end 
)
inline

A constructor taking all the element data for the vector and their indices.

Parameters
data_begThe start of the element data.
data_endOne-beyond-end of the element data.
rowsize_begThe start of the index data.
rowsize_endOne beyond the end of the index data.

Member Function Documentation

template<typename T >
void Opm::SparseVector< T >::addElement ( const T &  elem,
int  index 
)
inline

Appends an element to the vector. Note that this function does not increase the size() of the vector, it just adds another nonzero element. Elements must be added in index order.

template<typename T >
void Opm::SparseVector< T >::clear ( )
inline

Makes the vector empty().

template<typename T >
const T& Opm::SparseVector< T >::element ( int  index) const
inline

O(log n) element access.

Parameters
indexthe proper vector index
Returns
the element with the given index, or the default element if no element in the vector has the given index.
template<typename T >
bool Opm::SparseVector< T >::empty ( ) const
inline
Returns
true if the vector has size 0.
template<typename T >
const T& Opm::SparseVector< T >::nonzeroElement ( int  nzindex) const
inline

O(1) element access.

Parameters
nzindexan index counting only nonzero elements.
Returns
the nzindex'th nonzero element.

References Opm::SparseVector< T >::nonzeroSize().

template<typename T >
int Opm::SparseVector< T >::nonzeroIndex ( int  nzindex) const
inline

O(1) index access.

Parameters
nzindexan index counting only nonzero elements.
Returns
the index of the nzindex'th nonzero element.

References Opm::SparseVector< T >::nonzeroSize().

template<typename T >
int Opm::SparseVector< T >::nonzeroSize ( ) const
inline

Returns the number of nonzero data elements.

Referenced by Opm::SparseVector< T >::nonzeroElement(), and Opm::SparseVector< T >::nonzeroIndex().

template<typename T >
bool Opm::SparseVector< T >::operator== ( const SparseVector< T > &  other) const
inline

Equality.

template<typename T >
int Opm::SparseVector< T >::size ( ) const
inline

Returns the size of the vector. Recall that most or all of the vector may be default/zero.


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