ug4
ug::UnsortedSparseVector< TValue > Class Template Reference

#include <unsorted_sparse_vector.h>

Public Types

typedef AlgebraicConnection< TValue > connection
 
typedef std::vector< connection >::const_iterator const_iterator
 
typedef std::vector< connection >::iterator iterator
 
typedef TValue value_type
 

Public Member Functions

iterator begin ()
 
const_iterator begin () const
 
void clear ()
 
iterator end ()
 
const_iterator end () const
 
bool has_connection (size_t c) const
 
size_t num_connections () const
 
value_typeoperator() (size_t c)
 
const value_typeoperator() (size_t c) const
 
size_t size () const
 
connectionunsorted_raw_ptr ()
 
 UnsortedSparseVector (size_t s)
 

Private Attributes

std::vector< connectioncon
 
size_t m_size
 
std::vector< int > posInConnections
 

Detailed Description

template<typename TValue>
class ug::UnsortedSparseVector< TValue >

This is in most cases faster than the std::map-based SparseVector in sparse_vector.h because it uses and "posInConnection" array which reduces all operations to O(1), instead of O(log n) for std::map when number of non-zeroes in the vector. The additional array is as long as the (non-sparse) size of the vector, so this makes only sense if you REUSE the UnsortedSparseVector, like

N = 10000; // N is the non-sparse total size of the vector
UnsortedSparseVector<int> vec(N); // expensive.
for(size_t i=0; i < N; i++)
{
vec.clear();
for(size_t j=0; j<50; j++)
vec(rand()%N)++; // O(1)
}

Member Typedef Documentation

◆ connection

template<typename TValue >
typedef AlgebraicConnection<TValue> ug::UnsortedSparseVector< TValue >::connection

◆ const_iterator

template<typename TValue >
typedef std::vector<connection>::const_iterator ug::UnsortedSparseVector< TValue >::const_iterator

◆ iterator

template<typename TValue >
typedef std::vector<connection>::iterator ug::UnsortedSparseVector< TValue >::iterator

◆ value_type

template<typename TValue >
typedef TValue ug::UnsortedSparseVector< TValue >::value_type

Constructor & Destructor Documentation

◆ UnsortedSparseVector()

template<typename TValue >
ug::UnsortedSparseVector< TValue >::UnsortedSparseVector ( size_t  s)
inline

Member Function Documentation

◆ begin() [1/2]

template<typename TValue >
iterator ug::UnsortedSparseVector< TValue >::begin ( )
inline

◆ begin() [2/2]

template<typename TValue >
const_iterator ug::UnsortedSparseVector< TValue >::begin ( ) const
inline

◆ clear()

template<typename TValue >
void ug::UnsortedSparseVector< TValue >::clear ( )
inline

◆ end() [1/2]

template<typename TValue >
iterator ug::UnsortedSparseVector< TValue >::end ( )
inline

◆ end() [2/2]

template<typename TValue >
const_iterator ug::UnsortedSparseVector< TValue >::end ( ) const
inline

◆ has_connection()

template<typename TValue >
bool ug::UnsortedSparseVector< TValue >::has_connection ( size_t  c) const
inline

◆ num_connections()

template<typename TValue >
size_t ug::UnsortedSparseVector< TValue >::num_connections ( ) const
inline

◆ operator()() [1/2]

◆ operator()() [2/2]

◆ size()

template<typename TValue >
size_t ug::UnsortedSparseVector< TValue >::size ( ) const
inline

◆ unsorted_raw_ptr()

template<typename TValue >
connection* ug::UnsortedSparseVector< TValue >::unsorted_raw_ptr ( )
inline

Member Data Documentation

◆ con

◆ m_size

◆ posInConnections


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