SparseArray< 1, T > Class Template Reference

A sparse array of type T in 1 dimension. More...

#include <SparseArray1.h>

Inheritance diagram for SparseArray< 1, T >:
ArrayContainer< T > SparseArray< 2, T > SparseArraySigned< 1, T >

List of all members.

Public Types

typedef Types::value_type value_type
 The element type of the array.
typedef Types::parameter_type parameter_type
 The parameter type.
typedef
Types::unqualified_value_type 
unqualified_value_type
 The unqualified value type.
typedef Types::pointer pointer
 A pointer to an array element.
typedef Types::const_pointer const_pointer
 A pointer to a constant array element.
typedef Types::iterator iterator
 An iterator in the array.
typedef Types::const_iterator const_iterator
 A iterator on constant elements in the array.
typedef Types::reference reference
 A reference to an array element.
typedef Types::const_reference const_reference
 A reference to a constant array element.
typedef Types::size_type size_type
 The size type is a signed integer.
typedef Types::difference_type difference_type
 Pointer difference type.
typedef Array< 1, int >
::const_iterator 
IndexConstIterator
 A const iterator over the indices.

Public Member Functions

Constructors etc.

 SparseArray ()
 Default constructor.
template<typename IndexForwardIter , typename ValueForwardIter >
 SparseArray (IndexForwardIter indicesBeginning, IndexForwardIter indicesEnd, ValueForwardIter valuesBeginning, ValueForwardIter valuesEnd, parameter_type nullValue=value_type())
 Construct a 1-D array sparse array from the values and indices.
template<typename IndexForwardIter , typename ValueForwardIter >
void rebuild (IndexForwardIter indicesBeginning, IndexForwardIter indicesEnd, ValueForwardIter valuesBeginning, ValueForwardIter valuesEnd, parameter_type nullValue)
 Rebuild a 1-D sparse array from the values, the indices, and the null value.
template<typename IndexForwardIter , typename ValueForwardIter >
void rebuild (IndexForwardIter indicesBeginning, IndexForwardIter indicesEnd, ValueForwardIter valuesBeginning, ValueForwardIter valuesEnd)
 Rebuild a 1-D sparse array from the values and indices.
template<typename T2 , bool A>
 SparseArray (const Array< 1, T2, A > &array, parameter_type nullValue)
 Construct a 1-D sparse array from a 1-D dense array of possibly different value type.
 SparseArray (const size_type size)
 Construct from the array size (number of non-null elements).
void rebuild (const size_type size)
 Rebuild from the array size (number of non-null elements).
 SparseArray (const SparseArray &other)
 Copy constructor. Deep copy.
 ~SparseArray ()
 Destructor.
Assignment operators.

SparseArray & operator= (const SparseArray &other)
 Assignment operator.
template<typename T2 , bool A>
SparseArray & operator= (const Array< 1, T2, A > &array)
 Assignment operator for dense arrays.
Accessors.

size_type getMemoryUsage () const
 Return the memory size.
parameter_type getNull () const
 Return the null value.
bool isNull (const int i) const
 Return true if the element is null.
bool isNonNull (const int i) const
 Return true if the element is non-null.
parameter_type operator() (const int i) const
 Return the element with the specified index.
bool operator== (const SparseArray &x) const
 Return true if this sparse array is equal to the argument.
bool operator!= (const SparseArray &x) const
 Return true if this sparse array is not equal to the argument.
template<typename T2 , bool A>
void fill (ads::Array< 1, T2, A > *array) const
 Fill a dense array with the elements from this sparse array.
template<typename T2 , bool A>
void fillNonNull (ads::Array< 1, T2, A > *array) const
 Fill a dense array using only the non-null elements from this sparse array.
const Array< 1, int > & getIndices () const
 Return the array of indices.
int getIndex (const int n) const
 Return the index of the specified element.
IndexConstIterator getIndicesBeginning () const
 Get a const iterator to the beginning of the indices.
IndexConstIterator getIndicesEnd () const
 Get a const iterator to the end of the indices.
Manipulators.

void swap (SparseArray &other)
 Swaps data with another SparseArray.
Assignment operators with scalar operand.

SparseArray & operator= (parameter_type x)
 Set each component to x.
File I/O.

void put (std::ostream &out) const
 Write the array to a file stream in ascii format.
void get (std::istream &in)
 Read from a file stream in ascii format.

Static Public Member Functions

Static members.

static int getRank ()
 Return the rank (number of dimensions) of the array.

Protected Attributes

Array< 1, int > _indices
 The array indices.
value_type _null
 The null value.

Detailed Description

template<typename T>
class SparseArray< 1, T >

A sparse array of type T in 1 dimension.

Parameters:
T is the value type. By default it is double.

The free functions are grouped into the following categories.

Note that operator[] is container indexing. a[i] is the i_th non-null element. However, operator() is array indexing. a(i) is the element with index i.


Member Typedef Documentation

template<typename T >
typedef Types::parameter_type SparseArray< 1, T >::parameter_type

The parameter type.

This is used for passing the value type as an argument.

Reimplemented from ArrayContainer< T >.

Reimplemented in SparseArray< 2, T >, and SparseArraySigned< 1, T >.

template<typename T >
typedef Types::size_type SparseArray< 1, T >::size_type

The size type is a signed integer.

Having std::size_t (which is an unsigned integer) as the size type causes minor problems. Consult "Large Scale C++ Software Design" by John Lakos for a discussion of using unsigned integers in a class interface.

Reimplemented from ArrayContainer< T >.

Reimplemented in SparseArray< 2, T >, and SparseArraySigned< 1, T >.

template<typename T >
typedef Types::unqualified_value_type SparseArray< 1, T >::unqualified_value_type

The unqualified value type.

The value type with top level const and volatile qualifiers removed.

Reimplemented from ArrayContainer< T >.

Reimplemented in SparseArray< 2, T >, and SparseArraySigned< 1, T >.


Constructor & Destructor Documentation

template<typename T >
template<typename IndexForwardIter , typename ValueForwardIter >
SparseArray< 1, T >::SparseArray ( IndexForwardIter  indicesBeginning,
IndexForwardIter  indicesEnd,
ValueForwardIter  valuesBeginning,
ValueForwardIter  valuesEnd,
parameter_type  nullValue = value_type() 
) [inline]

Construct a 1-D array sparse array from the values and indices.

If the null value is not specified, the default value for the type is used. For built-in types, value_type() is equivalent to value_type(0).

template<typename T >
SparseArray< 1, T >::SparseArray ( const size_type  size  )  [inline, explicit]

Construct from the array size (number of non-null elements).

Leave the data uninitialized.


Member Function Documentation

template<typename T >
void SparseArray< 1, T >::rebuild ( const size_type  size  )  [inline]

Rebuild from the array size (number of non-null elements).

Leave the data uninitialized.


The documentation for this class was generated from the following file:
Generated on Thu Jun 30 02:14:52 2016 for Algorithms and Data Structures Package by  doxygen 1.6.3