LocARNA-1.9.2
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends
Classes | Public Types | Public Member Functions | Protected Types | Protected Attributes
LocARNA::SparseVector< T > Class Template Reference

Represents a sparse vector. More...

#include <sparse_vector.hh>

List of all members.

Classes

class  element
 Element of sparse vector. More...

Public Types

typedef T value_t
 type of vector entries
typedef size_t size_type
 usual definition of size_type
typedef size_type key_t
 type of vector index pair
typedef map_t::const_iterator const_iterator
 Stl-compatible constant iterator over vector elements.

Public Member Functions

 SparseVector (const value_t &def)
 Construct with default value.
element operator[] (size_type i)
 Access to vector element.
const value_toperator[] (size_type i) const
 Read-only access to vector element of const vector.
void set (size_type i, const value_t &val)
 Write access to vector entry.
void reset (size_type i)
 Set vector entry to default value.
size_type size () const
 Size of sparse vector.
bool empty () const
 Check for emptiness.
void clear ()
 Clear the vector.
const_iterator begin () const
 Begin const iterator over vector entries.
const_iterator end () const
 End const iterator over vector entries.

Protected Types

typedef unordered_map< key_t,
value_t >::type 
map_t
 map type

Protected Attributes

map_t the_map_
 internal representation of sparse vector
value_t def_
 default value of vector entries

Detailed Description

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

Represents a sparse vector.

Sparse vector of entries val_t implements the vector by a hash map. The class is designed to be largely exchangable with non-sparse vectors.

Todo:
this code is basically a stripped down version of the SparseMatrix code; likely one could reduce redundancy

Member Typedef Documentation

template<typename T>
typedef map_t::const_iterator LocARNA::SparseVector< T >::const_iterator

Stl-compatible constant iterator over vector elements.

Behaves like a const iterator of the hash map.


Constructor & Destructor Documentation

template<typename T>
LocARNA::SparseVector< T >::SparseVector ( const value_t def) [inline, explicit]

Construct with default value.

Parameters:
defdefault value of entries

Member Function Documentation

template<typename T>
const_iterator LocARNA::SparseVector< T >::begin ( ) const [inline]

Begin const iterator over vector entries.

Returns:
const iterator pointing to begin of entry hash
See also:
end()
template<typename T>
bool LocARNA::SparseVector< T >::empty ( ) const [inline]

Check for emptiness.

Returns:
true, if sparse vector contains only implicite default entries.
template<typename T>
const_iterator LocARNA::SparseVector< T >::end ( ) const [inline]

End const iterator over vector entries.

Returns:
const iterator pointing after end of entry hash
See also:
begin()
template<typename T>
element LocARNA::SparseVector< T >::operator[] ( size_type  i) [inline]

Access to vector element.

Parameters:
iindex first dimension
Returns:
proxy to vector entry i
template<typename T>
const value_t& LocARNA::SparseVector< T >::operator[] ( size_type  i) const [inline]

Read-only access to vector element of const vector.

Parameters:
iindex first dimension
Returns:
vector entry i
template<typename T>
void LocARNA::SparseVector< T >::reset ( size_type  i) [inline]

Set vector entry to default value.

Parameters:
iindex first dimension
template<typename T>
void LocARNA::SparseVector< T >::set ( size_type  i,
const value_t val 
) [inline]

Write access to vector entry.

Parameters:
iindex first dimension
valvalue to be written to entry i
Note:
Unlike the assignment operator (via element), there is no test whether the default value is assigned. Use reset(i) if you want to reset vector entries to the default.
Postcondition:
writes entry. If entry didn't exist already it is created.
template<typename T>
size_type LocARNA::SparseVector< T >::size ( ) const [inline]

Size of sparse vector.

Returns:
number of non-empty entries

The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends