Public Types | Public Member Functions | Protected Types | Protected Attributes
vbl_sparse_array_base< T, Index > Class Template Reference

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

#include <vbl_sparse_array_base.h>

Inheritance diagram for vbl_sparse_array_base< T, Index >:
Inheritance graph
[legend]

List of all members.

Public Types

typedef vcl_size_t size_type
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 that (i) is non-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.
size_type 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.

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.


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_2d< T >, and vbl_sparse_array_1d< T >.

Definition at line 71 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 77 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 84 of file vbl_sparse_array_base.h.

template<class T, class Index>
typedef vcl_size_t vbl_sparse_array_base< T, Index >::size_type

Definition at line 47 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 80 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 88 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>
size_type 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 74 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 91 of file vbl_sparse_array_base.h.

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

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  i) 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  i)

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

Return the memory 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& vbl_sparse_array_base< T, Index >::operator() ( Index  i) [inline]

Return contents at (i).

Definition at line 50 of file vbl_sparse_array_base.h.

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

Return contents at (i). Asserts that (i) is non-empty.

Return contents of (i). Assertion failure if not yet filled.

Definition at line 22 of file vbl_sparse_array_base.txx.

template<class T, class Index>
bool vbl_sparse_array_base< T, Index >::put ( Index  i,
const T &  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: