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.  
SparVec (AbacusGlobal *glob, int size, double reallocFac=10.0)  
Creates an empty sparse vector.  
SparVec (AbacusGlobal *glob, int size, int *s, double *c, double reallocFac=10.0)  
Creates a sparse vector and initializes support and coefficients.  
SparVec (const SparVec &rhs)  
Copy constructor.  
~SparVec ()  
The destructor.  
void  clear () 
Removes all nonzeros from the sparse vector.  
double  coeff (int i) const 
void  copy (const SparVec &vec) 
Copies vector vec.  
void  insert (int s, double c) 
Adds a new support/coefficient pair to the vector.  
void  leftShift (ArrayBuffer< int > &del) 
Deletes the elements listed in a buffer from the sparse vector.  
int  nnz () const 
Returns the number of nonzero elements.  
double  norm () 
Returns the Euclidean norm of the sparse vector.  
SparVec &  operator= (const SparVec &rhs) 
The assignment operator.  
double  origCoeff (int i) const 
void  realloc () 
Increases the size of the sparse vector by reallocFac_ percent of the original size.  
void  realloc (int newSize) 
Reallocates the sparse vector to a given length.  
void  rename (Array< int > &newName) 
Replaces the index of the support by new names.  
int  size () const 
Returns the maximal length of the sparse vector.  
int  support (int i) const 
Public Member Functions inherited from abacus::AbacusRoot  
virtual  ~AbacusRoot () 
The destructor.  
Protected Member Functions  
void  rangeCheck (int i) const 
Checks whether i is a valid index.  
Protected Attributes  
double *  coeff_ 
The array storing the corresponding nonzero coefficients.  
AbacusGlobal *  glob_ 
A pointer to the corresponding global object.  
int  nnz_ 
The number of stored elements ("nonzeros").  
double  reallocFac_ 
If a new element is inserted but the sparse vector is full, then its size is increased by reallocFac_ percent.  
int  size_ 
The maximal number of nonzero coefficients which can be stored without reallocation.  
int *  support_ 
The array storing the nonzero variables.  
Friends  
std::ostream &  operator<< (std::ostream &out, const SparVec &rhs) 
The output operator.  
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.  
static bool  endsWith (const string &str, const string &end) 
Returns true if str ends with end, false otherwise.  
static double  fracPart (double x) 
Returns the absolute value of the fractional part of x.  
static const char *  onOff (bool value) 
Converts a boolean variable to the strings "on" and "off".  
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. 
Copy constructor.
rhs  The sparse vector that is copied. 
abacus::SparVec::~SparVec  (  ) 
The destructor.

inline 
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. 
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. 
i  The number of the original coefficient. 
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.
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. 
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 
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 