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

Represents a sparse 2D matrix. More...

#include <sparse_matrix.hh>

List of all members.

Classes

class  element
 Element of sparse matrix. More...

Public Types

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

Public Member Functions

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

Protected Types

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

Protected Attributes

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

Detailed Description

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

Represents a sparse 2D matrix.

Sparse matrix of entries val_t implements the matrix by a hash map. The class is designed to be largely exchangable with the non-sparse Matrix class. (A proxy class is used to provide the same syntax for the interface.)

See also:
Matrix

Member Typedef Documentation

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

Stl-compatible constant iterator over matrix elements.

Behaves like a const iterator of the hash map.


Constructor & Destructor Documentation

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

Construct with default value.

Parameters:
defdefault value of entries

Member Function Documentation

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

Begin const iterator over matrix entries.

Returns:
const iterator pointing to begin of entry hash
See also:
end()
template<typename T>
const value_t& LocARNA::SparseMatrix< T >::def ( ) const [inline]

Default value.

Returns:
default value
template<typename T>
bool LocARNA::SparseMatrix< T >::empty ( ) const [inline]

Check for emptiness.

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

End const iterator over matrix entries.

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

Access to matrix element.

Parameters:
iindex first dimension
jindex second dimension
Returns:
proxy to matrix entry (i,j)
template<typename T>
const value_t& LocARNA::SparseMatrix< T >::operator() ( size_type  i,
size_type  j 
) const [inline]

Read-only access to matrix element of const matrix.

Parameters:
iindex first dimension
jindex second dimension
Returns:
matrix entry (i,j)
template<typename T>
value_t& LocARNA::SparseMatrix< T >::ref ( size_type  i,
size_type  j 
) [inline]

Write access to matrix element of const matrix.

Parameters:
iindex first dimension
jindex second dimension
Note:
Creates the entry (i,j) if it is not represented yet.
Returns:
reference to matrix entry (i,j)
template<typename T>
void LocARNA::SparseMatrix< T >::reset ( size_type  i,
size_type  j 
) [inline]

Set matrix entry to default value.

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

Write access to matrix entry.

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

Size of sparse matrix.

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