Sparse vectors. More...
#include <ogdf/lib/abacus/sparvec.h>
Public Member Functions  
SparVec (AbacusGlobal *glob, int size, const Array< int > &s, const Array< double > &c, double reallocFac=10.0)  
Creates a sparse vector and initializes support and coefficients. More...  
SparVec (AbacusGlobal *glob, int size, double reallocFac=10.0)  
Creates an empty sparse vector. More...  
SparVec (AbacusGlobal *glob, int size, int *s, double *c, double reallocFac=10.0)  
Creates a sparse vector and initializes support and coefficients. More...  
SparVec (const SparVec &rhs)  
Copy constructor. More...  
~SparVec ()  
The destructor. More...  
void  clear () 
Removes all nonzeros from the sparse vector. More...  
double  coeff (int i) const 
void  copy (const SparVec &vec) 
Copies vector vec. More...  
void  insert (int s, double c) 
Adds a new support/coefficient pair to the vector. More...  
void  leftShift (ArrayBuffer< int > &del) 
Deletes the elements listed in a buffer from the sparse vector. More...  
int  nnz () const 
Returns the number of nonzero elements. More...  
double  norm () 
Returns the Euclidean norm of the sparse vector. More...  
SparVec &  operator= (const SparVec &rhs) 
The assignment operator. More...  
double  origCoeff (int i) const 
void  realloc () 
Increases the size of the sparse vector by reallocFac_ percent of the original size. More...  
void  realloc (int newSize) 
Reallocates the sparse vector to a given length. More...  
void  rename (Array< int > &newName) 
Replaces the index of the support by new names. More...  
int  size () const 
Returns the maximal length of the sparse vector. More...  
int  support (int i) const 
Public Member Functions inherited from abacus::AbacusRoot  
virtual  ~AbacusRoot () 
The destructor. More...  
Protected Member Functions  
void  rangeCheck (int i) const 
Checks whether i is a valid index. More...  
Protected Attributes  
double *  coeff_ 
The array storing the corresponding nonzero coefficients. More...  
AbacusGlobal *  glob_ 
A pointer to the corresponding global object. More...  
int  nnz_ 
The number of stored elements ("nonzeros"). More...  
double  reallocFac_ 
If a new element is inserted but the sparse vector is full, then its size is increased by reallocFac_ percent. More...  
int  size_ 
The maximal number of nonzero coefficients which can be stored without reallocation. More...  
int *  support_ 
The array storing the nonzero variables. More...  
Friends  
std::ostream &  operator<< (std::ostream &out, const SparVec &rhs) 
The output operator. More...  
Additional Inherited Members  
Static Public Member Functions inherited from abacus::AbacusRoot  
static bool  ascii2bool (const string &str) 
Converts the string str to a boolean value. More...  
static bool  endsWith (const string &str, const string &end) 
Returns true if str ends with end, false otherwise. More...  
static double  fracPart (double x) 
Returns the absolute value of the fractional part of x. More...  
static const char *  onOff (bool value) 
Converts a boolean variable to the strings "on" and "off". More...  
Sparse vectors.
If the number of components of a vector having nonzero coefficients is small (sparse), then it is more adequate to store only the number of these components together with the nonzero coefficients.
Since other classes, e.g., the class Row are derived from this class, all data members are protected in order to provide efficient access also in these derived classes.
abacus::SparVec::SparVec  (  AbacusGlobal *  glob, 
int  size,  
double  reallocFac = 10.0 

) 
Creates an empty sparse vector.
If no memory for support_ and coeff_ is allocated then an automatic allocation will be performed when the function insert() is called the first time.
glob  A pointer to the corresponding global object. 
size  The maximal number of nonzeros of the sparse vector (without reallocation). 
reallocFac  The reallocation factor (in percent of the original size), which is used in a default reallocation if a variable is inserted when the sparse vector is already full. Its default value is 10. 
abacus::SparVec::SparVec  (  AbacusGlobal *  glob, 
int  size,  
const Array< int > &  s,  
const Array< double > &  c,  
double  reallocFac = 10.0 

) 
Creates a sparse vector and initializes support and coefficients.
The minimum value of size and s.size is the number of nonzeros of the sparse vector.
If size is 0, then also no elements are copied in the forloop since nnz_ will be also 0.
glob  A pointer to the corresponding global object. 
size  The maximal number of nonzeros (without reallocation). 
s  An array storing the support of the sparse vector, i.e., the elements for which a (normally nonzero) coefficient is given in c. 
c  An array storing the coefficients of the support elements given in s. This array must have at least the length of the minimum of size and s.size(). 
reallocFac  The reallocation factor (in percent of the original size), which is used in a default reallocation if a variable is inserted when the sparse vector is already full. Its default value is 10. 
abacus::SparVec::SparVec  (  AbacusGlobal *  glob, 
int  size,  
int *  s,  
double *  c,  
double  reallocFac = 10.0 

) 
Creates a sparse vector and initializes support and coefficients.
This constructor is equivalent to the previous one except that it is using Cstyle arrays for the initialization of the sparse vector.
glob  A pointer to the corresponding global object. 
size  The maximal number of nonzeros (without reallocation). 
s  An array storing the support of the sparse vector, i.e., the elements for which a (normally nonzero) coefficient is given in c. 
c  An array storing the coefficients of the support elements given in s. This array must have at least the length of the minimum of size and s.size(). 
reallocFac  The reallocation factor (in percent of the original size), which is used in a default reallocation if a variable is inserted when the sparse vector is already full. Its default value is 10. 
abacus::SparVec::SparVec  (  const SparVec &  rhs  ) 
Copy constructor.
rhs  The sparse vector that is copied. 
abacus::SparVec::~SparVec  (  ) 
The destructor.

inline 

inline 
void abacus::SparVec::copy  (  const SparVec &  vec  ) 
Copies vector vec.
Is very similar to the assignment operator, yet the size of the two vectors need not be equal and only the support, the coefficients, and the number of nonzeros is copied. A reallocation is performed if required.
vec  The sparse vector that is copied. 

inline 
void abacus::SparVec::leftShift  (  ArrayBuffer< int > &  del  ) 
Deletes the elements listed in a buffer from the sparse vector.
The numbers of indices in this buffer must be upward sorted. The elements before the first element in the buffer are unchanged. Then the elements which are not deleted are shifted left in the arrays.
del  The numbers of the elements removed from the sparse vector. 

inline 
double abacus::SparVec::norm  (  ) 
Returns the Euclidean norm of the sparse vector.
The assignment operator.
Requires that the left hand and the right hand side have the same length (otherwise use the function copy()).
rhs  The right hand side of the assignment. 
double abacus::SparVec::origCoeff  (  int  i  )  const 
i  The number of the original coefficient. 

protected 
Checks whether i is a valid index.
Throws an exception if i is negative or greater or equal than the number of nonzero elements.
If the class SparVec is compiled with the flag OGDF_DEBUG, then before each access operation on element i of the sparse vector the function rangeCheck() is called.
i  An integer that should be checked if it is in the range of the sparse vector. 
void abacus::SparVec::realloc  (  ) 
Increases the size of the sparse vector by reallocFac_ percent of the original size.
void abacus::SparVec::realloc  (  int  newSize  ) 
Reallocates the sparse vector to a given length.
It is an error to decrease size below the current number of nonzeros.
newSize  The new maximal number of nonzeroes that can be stored in the sparse vector. 
void abacus::SparVec::rename  (  Array< int > &  newName  ) 
Replaces the index of the support by new names.
newName  The new names (support) of the elements of the sparse vector. The array newName must have at least a length equal to the maximal element in the support of the sparse vector. 

inline 

inline 

friend 
The output operator.
Writes the elements of the support and their coefficients line by line on an output stream.
out  The output stream. 
rhs  The sparse vector being output. 

protected 

protected 

protected 

protected 

protected 

protected 