sparse1D<RepType> [MTL Home] Programmers Guide
  Contents | Index |  Search 


Category:containers,adaptors Component type:type
Description
This is a sparse vector implementation that can use several different underlying containers, including std::vector, std::list, and std::set.

This adaptor is used in the implementation of the linked_list, tree, and sparse_pair OneD storage types (used with the array matrix storage type). This adaptor can also be used as a stand-alone Vector.

The value_type of the underlying containers must be entry1, which is just an index-value pair.

The elements are ordered by their index as they are inserted.

Example
In gather_scatter.cc:
void do_gather_scatter(DenseVec& d, SparseVec& c) {
  using namespace mtl;

  c[2] = 0;
  c[5] = 0;
  c[7] = 0;

  gather(d,c);
  scale(c,2.0);
  scatter(c,d);
  typedef dense1D<double> denseVec;
  typedef compressed1D<double> compVec;
  denseVec d(9,2);
  compVec c;
  do_gather_scatter(d, c);

Definition
sparse1D.h
Template Parameters

ParameterDescriptionDefault
RepTypeThe Container type used to store the index value pairs. 
Model of
ContainerRef?
Type requirements
  • The value_type of RepType must be of type entry1
Members
Member Where defined Description
enum { N = 0 }    
sparsity   This is a sparse vector
entry_type   The index-value pair type
dimension   This is a 1D container
scaled_type   The scaled type
value_type   The value type
pointer   The type for pointers to the value type
size_type   The unsigned integral type for dimensions and indices
difference_type   The type for differences between iterators
reference   The type for references to the value type
const_reference   The type for const references to the value type
iterator   The iterator type
const_iterator   The const iterator type
reverse_iterator   The reverse iterator type
const_reverse_iterator   The const reverse iterator type
IndexArray   The type for the index array
IndexArrayRef   The reference type for the index array
subrange_type   The type for subrange vectors
iterator __find_set (int i)    
iterator __find_normal (int i)    
sparse1D ()   Default Constructor
sparse1D (size_type n)   Length N Constructor
sparse1D (const self& x)   Copy Constructor
template <class IndexArray>
sparse1D (const IndexArray& x, size_type n)
  Construct from index array
self& operator= (const self& x)   Assignment Operator
iterator begin () Container Return an iterator pointing to the beginning of the vector
iterator end () Container Return an iterator pointing past the end of the vector
const_iterator begin () const Container Return a const iterator pointing to the begining of the vector
const_iterator end () const Container Return a const iterator pointing past the end of the vector
reverse_iterator rbegin () Reversible Container Return a reverse iterator pointing to the last element of the vector
reverse_iterator rend () Reversible Container Return a reverse iterator pointing past the end of the vector
const_reverse_iterator rbegin () const Reversible Container Return a const reverse iterator pointing to the last element of the vector
const_reverse_iterator rend () const Reversible Container Return a const reverse iterator pointing past the end of the vector
const_reference operator[] (int i) const   Element Access, return element with index i
reference operator[] (int i)   Element Access, return element with index i
iterator insert (int i, const value_type& value)   Insert the value at index i of the vector
void clear ()    
void push_back (int i, const value_type& value)    
int size () const   Returns length of the vector (including non-zeroes)
int nnz () const   Number of non-zero (stored) elements
template <class R>
void resize_imp (int n, R*)
   
template <class R>
void resize_imp (int n, R*)
   
void resize (int n)   Resizes the vector to size n
rep_type& get_rep ()    
void print () const    
IndexArrayRef nz_struct () const   Return an array of indices describing the non-zero structure
New members
Notes
See also

[MTL Home] Copyright © 1998,1999 University of Notre Dame. All Rights Reserved.