Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

vbl_sparse_array_base< T, Index > Class Template Reference

#include <vbl_sparse_array_base.h>

Inheritance diagram for vbl_sparse_array_base< T, Index >:

Inheritance graph
[legend]
List of all members.

Detailed Description

template<class T, class Index>
class vbl_sparse_array_base< T, Index >

A fully featured sparse array which devolves indexing to its templated type.

If you just want an ordinary sparse array use vbl_sparse_array_1d, vbl_sparse_array_2d, or vbl_sparse_array_3d.

Design Decision: Advanced Users only.

The sparse array design has as much of the code as possible in this templated base class. This allows us to code harden this class while leaving the three derived classes in vbl, simple, easy to understand and use. I rejected to use templating over the number of dimensions because this can lead into recursive templating which is in theory very nice, but in practice very horrible. It also makes the interface rather unintuitive. If you are worried about the speed aspects of using a pair of integers instead of a single encoded integer, then you can create an encoder class as the index type, and use it directly, or hide the details by writing a specialising derivative of vbl_sparse_array_base.

Definition at line 37 of file vbl_sparse_array_base.h.

Public Types

typedef Map::const_iterator const_iterator
 The type of iterators into the efficient storage.
typedef Index Index_type
 The type of objects used to index the sparse array.
typedef T T_type
 The type of values stored by the sparse array.
typedef Map::value_type sequence_value_type
 The type of values of the controlled sequence.

Public Member Functions

T & operator() (Index i)
 Return contents at (i).
T const & operator() (Index i) const
 Return contents at (i). Asserts if (i) empty.
void erase (Index)
 Erase element at location (i). Assertion failure if not yet filled.
bool fullp (Index) const
 Return true if location (i) has been filled.
bool put (Index, const T &)
 Put a value into location (i).
T * get_addr (Index)
 Return the address of location (i). 0 if not yet filled.
void clear ()
 Empty the sparse matrix.
unsigned count_nonempty () const
 Return number of locations that have been assigned a value using "put".
const_iterator begin () const
 A bidirectional iterator pointing at the first non-empty element.
const_iterator end () const
 A bidirectional iterator pointing just beyond last non-empty element.

Protected Types

typedef vcl_map< Index, T,
vcl_less< Index > > 
Map
 The type of the storage.

Protected Attributes

Map storage_
 This stores a compact list of the values.


Member Typedef Documentation

template<class T, class Index>
typedef Map::const_iterator vbl_sparse_array_base< T, Index >::const_iterator
 

The type of iterators into the efficient storage.

Reimplemented in vbl_sparse_array_1d< T >, and vbl_sparse_array_2d< T >.

Definition at line 69 of file vbl_sparse_array_base.h.

template<class T, class Index>
typedef Index vbl_sparse_array_base< T, Index >::Index_type
 

The type of objects used to index the sparse array.

Reimplemented in vbl_sparse_array_2d< T >.

Definition at line 75 of file vbl_sparse_array_base.h.

template<class T, class Index>
typedef vcl_map<Index, T, vcl_less<Index> > vbl_sparse_array_base< T, Index >::Map [protected]
 

The type of the storage.

Definition at line 41 of file vbl_sparse_array_base.h.

template<class T, class Index>
typedef Map::value_type vbl_sparse_array_base< T, Index >::sequence_value_type
 

The type of values of the controlled sequence.

The value_type is a vcl_pair<Index_type, typename T_type>

Definition at line 82 of file vbl_sparse_array_base.h.

template<class T, class Index>
typedef T vbl_sparse_array_base< T, Index >::T_type
 

The type of values stored by the sparse array.

Definition at line 78 of file vbl_sparse_array_base.h.


Member Function Documentation

template<class T, class Index>
const_iterator vbl_sparse_array_base< T, Index >::begin  )  const [inline]
 

A bidirectional iterator pointing at the first non-empty element.

If the array is empty it points just beyond the end.

Definition at line 86 of file vbl_sparse_array_base.h.

template<class T, class Index>
void vbl_sparse_array_base< T, Index >::clear  ) 
 

Empty the sparse matrix.

Definition at line 15 of file vbl_sparse_array_base.txx.

template<class T, class Index>
unsigned vbl_sparse_array_base< T, Index >::count_nonempty  )  const [inline]
 

Return number of locations that have been assigned a value using "put".

Definition at line 72 of file vbl_sparse_array_base.h.

template<class T, class Index>
const_iterator vbl_sparse_array_base< T, Index >::end  )  const [inline]
 

A bidirectional iterator pointing just beyond last non-empty element.

Definition at line 89 of file vbl_sparse_array_base.h.

template<class T, class Index>
void vbl_sparse_array_base< T, Index >::erase Index   ) 
 

Erase element at location (i). Assertion failure if not yet filled.

Definition at line 33 of file vbl_sparse_array_base.txx.

template<class T, class Index>
bool vbl_sparse_array_base< T, Index >::fullp Index   )  const
 

Return true if location (i) has been filled.

Definition at line 56 of file vbl_sparse_array_base.txx.

template<class T, class Index>
T * vbl_sparse_array_base< T, Index >::get_addr Index   ) 
 

Return the address of location (i). 0 if not yet filled.

Definition at line 44 of file vbl_sparse_array_base.txx.

template<class T, class Index>
T const & vbl_sparse_array_base< T, Index >::operator() Index  i  )  const
 

Return contents at (i). Asserts if (i) empty.

Definition at line 22 of file vbl_sparse_array_base.txx.

template<class T, class Index>
T& vbl_sparse_array_base< T, Index >::operator() Index  i  )  [inline]
 

Return contents at (i).

Definition at line 48 of file vbl_sparse_array_base.h.

template<class T, class Index>
bool vbl_sparse_array_base< T, Index >::put Index  ,
const T & 
 

Put a value into location (i).

Definition at line 63 of file vbl_sparse_array_base.txx.


Member Data Documentation

template<class T, class Index>
Map vbl_sparse_array_base< T, Index >::storage_ [protected]
 

This stores a compact list of the values.

Definition at line 43 of file vbl_sparse_array_base.h.


The documentation for this class was generated from the following files:
Generated on Thu Jan 10 14:39:10 2008 for core/vbl by  doxygen 1.4.4