Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

sparvec.h
Go to the documentation of this file.
1 
30 #pragma once
31 
32 #include <ogdf/lib/abacus/global.h>
33 
34 #pragma GCC visibility push(default)
35 namespace abacus {
36 
37 
39 
48 class SparVec : public AbacusRoot {
49 public:
50 
52 
62  SparVec(AbacusGlobal *glob,
63  int size,
64  double reallocFac = 10.0);
65 
67 
86  SparVec(AbacusGlobal *glob,
87  int size,
88  const Array<int> &s,
89  const Array<double> &c,
90  double reallocFac = 10.0);
91 
93 
110  SparVec(AbacusGlobal *glob,
111  int size,
112  int *s,
113  double *c,
114  double reallocFac = 10.0);
115 
117 
120  SparVec(const SparVec& rhs);
121 
123  ~SparVec();
124 
126 
134  SparVec& operator=(const SparVec& rhs);
135 
137 
145  friend std::ostream& operator<<(std::ostream& out, const SparVec& rhs);
146 
152  int support(int i) const {
153 #ifdef OGDF_DEBUG
154  rangeCheck(i);
155 #endif
156  return support_[i];
157  }
158 
164  double coeff(int i) const {
165 #ifdef OGDF_DEBUG
166  rangeCheck(i);
167 #endif
168  return coeff_[i];
169  }
170 
176  double origCoeff(int i) const;
177 
179 
185  void insert(int s, double c) {
186  if (nnz_ == size_) realloc();
187 
188  support_[nnz_] = s;
189  coeff_[nnz_] = c;
190  ++nnz_;
191  }
192 
194 
201  void leftShift(ArrayBuffer<int> &del);
202 
204 
211  void copy (const SparVec &vec);
212 
214  void clear() { nnz_ = 0; }
215 
217 
222  void rename(Array<int> &newName);
223 
225  int size() const { return size_; }
226 
228 
233  int nnz() const { return nnz_; }
234 
236  double norm();
237 
239  /***
240  * This function is called if an automatic reallocation takes place.
241  */
242  void realloc();
243 
245 
250  void realloc(int newSize);
251 
252 protected:
253 
255 
265  void rangeCheck(int i) const;
266 
269 
271  int size_;
272 
274  int nnz_;
275 
278  double reallocFac_;
279 
281  int *support_;
282 
284  double *coeff_;
285 };
286 
287 }
288 #pragma GCC visibility pop
ogdf::ArrayBuffer
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition: Array.h:53
abacus::SparVec::nnz_
int nnz_
The number of stored elements ("nonzeros").
Definition: sparvec.h:274
abacus::SparVec::origCoeff
double origCoeff(int i) const
global.h
global.
abacus::SparVec::norm
double norm()
Returns the Euclidean norm of the sparse vector.
abacus::SparVec::insert
void insert(int s, double c)
Adds a new support/coefficient pair to the vector.
Definition: sparvec.h:185
abacus::SparVec::~SparVec
~SparVec()
The destructor.
abacus::SparVec::SparVec
SparVec(AbacusGlobal *glob, int size, double reallocFac=10.0)
Creates an empty sparse vector.
abacus::SparVec::glob_
AbacusGlobal * glob_
A pointer to the corresponding global object.
Definition: sparvec.h:268
abacus
Definition: ILPClusterPlanarity.h:50
abacus::SparVec::support_
int * support_
The array storing the nonzero variables.
Definition: sparvec.h:281
abacus::SparVec::nnz
int nnz() const
Returns the number of nonzero elements.
Definition: sparvec.h:233
abacus::SparVec::reallocFac_
double reallocFac_
If a new element is inserted but the sparse vector is full, then its size is increased by reallocFac_...
Definition: sparvec.h:278
abacus::SparVec::size_
int size_
The maximal number of nonzero coefficients which can be stored without reallocation.
Definition: sparvec.h:271
abacus::SparVec::rename
void rename(Array< int > &newName)
Replaces the index of the support by new names.
abacus::SparVec::copy
void copy(const SparVec &vec)
Copies vector vec.
abacus::SparVec::coeff
double coeff(int i) const
Definition: sparvec.h:164
abacus::SparVec::coeff_
double * coeff_
The array storing the corresponding nonzero coefficients.
Definition: sparvec.h:284
abacus::SparVec::rangeCheck
void rangeCheck(int i) const
Checks whether i is a valid index.
abacus::AbacusRoot
Base class of all other classes of ABACUS.
Definition: abacusroot.h:69
ogdf::Array
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:219
abacus::SparVec
Sparse vectors.
Definition: sparvec.h:48
abacus::SparVec::size
int size() const
Returns the maximal length of the sparse vector.
Definition: sparvec.h:225
abacus::SparVec::support
int support(int i) const
Definition: sparvec.h:152
abacus::SparVec::operator<<
friend std::ostream & operator<<(std::ostream &out, const SparVec &rhs)
The output operator.
abacus::SparVec::operator=
SparVec & operator=(const SparVec &rhs)
The assignment operator.
abacus::SparVec::leftShift
void leftShift(ArrayBuffer< int > &del)
Deletes the elements listed in a buffer from the sparse vector.
abacus::SparVec::realloc
void realloc()
Increases the size of the sparse vector by reallocFac_ percent of the original size.
abacus::AbacusGlobal
Global data and functions.
Definition: global.h:58
abacus::SparVec::clear
void clear()
Removes all nonzeros from the sparse vector.
Definition: sparvec.h:214