Public Types | Public Member Functions | Static Public Attributes

sparse_vector< BASIS, MAP > Class Template Reference

A class to store and manipulate sparse vectors. More...

#include <sparse_vector.h>

Inheritance diagram for sparse_vector< BASIS, MAP >:
MAP

List of all members.

Public Types

typedef BASIS::RATIONAL RATIONAL
 Import of the rational type from the BASIS class.
typedef MAP::key_type KEY
 Import of the KEY type from the MAP class.
typedef MAP::mapped_type SCALAR
 Import of the SCALAR type from the MAP class.
typedef MAP::iterator iterator
 Import of the iterator type from the MAP type.
typedef MAP::const_iterator const_iterator
 Import of the KEY constant iterator type from the MAP type.

Public Member Functions

void swap (typename sparse_vector &rhs)
 Swap the vector instance controlled by *this with the one in the RHS.
 sparse_vector (void)
 Default constructor.
 sparse_vector (const sparse_vector &v)
 Copy constructor.
 sparse_vector (const KEY &k, const SCALAR &s=one)
 Unidimensional constructor.
sparse_vector operator- (void) const
 Returns an instance of the additive inverse of the instance.
sparse_vectoroperator*= (const SCALAR &s)
 Multiplies the instance with scalar s.

Static Public Attributes

static const SCALAR zero
 The zero scalar value.
static const SCALAR one
 The +1 scalar value.
static const SCALAR mone
 The -1 scalar value.
static BASIS basis
 Static initialisation of the sparse_vector basis.

Detailed Description

template<class BASIS, class MAP>
class sparse_vector< BASIS, MAP >

A class to store and manipulate sparse vectors.

An instance of the sparse_vector class is just a MAP between KEY and SCALAR, with vector space operators. It is a vector of basis elements of type KEY, stored in a MAP class, associated to coefficients given by SCALAR instances. Each basis element refers to the static instance of type BASIS.

The MAP class must comes with a std::map<KEY, SCALAR> interface. The scalar type SCALAR correponds to MAP::mapped_type. By default, the MAP class is taken from the BASIS via the BASIS::MAP type, cf. forward declaration of the sparse_vector class in libalgebra.h.

The SCALAR type must comes with operators making it an associative algebra (non necessarily commutative) containing the integers (via a suitable constructor). Thus, operators *,+,- must be implemented.

There is a compatibility condition between the BASIS and MAP classes since the MAP::key_type type and the BASIS::KEY must be the same.


Constructor & Destructor Documentation

template<class BASIS, class MAP>
sparse_vector< BASIS, MAP >::sparse_vector ( void   )  [inline]

Default constructor.

Create an instance of an empty vector. Such a vector is a neutral element for operator+= and operator-=.

template<class BASIS, class MAP>
sparse_vector< BASIS, MAP >::sparse_vector ( const KEY k,
const SCALAR s = one 
) [inline, explicit]

Unidimensional constructor.

Constructs a sparse_vector correponding the unique basis element k with coefficient s (+1 by default).


Member Data Documentation

template<class BASIS, class MAP>
BASIS sparse_vector< BASIS, MAP >::basis [static]

Static initialisation of the sparse_vector basis.

The static basis. Can be dynamically updated by some internal mechanism.

template<class BASIS, class MAP>
const MAP::mapped_type sparse_vector< BASIS, MAP >::mone [static]

The -1 scalar value.

Static initialisation of the scalar constant -1.

template<class BASIS, class MAP>
const MAP::mapped_type sparse_vector< BASIS, MAP >::one [static]

The +1 scalar value.

Static initialisation of the scalar constant +1.

template<class BASIS, class MAP>
const MAP::mapped_type sparse_vector< BASIS, MAP >::zero [static]

The zero scalar value.

Static initialisation of the scalar constant 0.


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