14#ifndef OR_TOOLS_MATH_OPT_SOLVERS_GLPK_GLPK_SPARSE_VECTOR_H_
15#define OR_TOOLS_MATH_OPT_SOLVERS_GLPK_GLPK_SPARSE_VECTOR_H_
22#include "absl/log/check.h"
77 int size()
const {
return size_; }
82 const int*
indices()
const {
return indices_.data(); }
87 const double*
values()
const {
return values_.data(); }
99 inline std::optional<double>
Get(
int index)
const;
132 static constexpr int kNotPresent = std::numeric_limits<int>::max();
147 std::vector<int> index_to_entry_;
151 std::vector<int> indices_;
155 std::vector<double> values_;
166 const int entry = index_to_entry_[
index];
167 if (entry == kNotPresent) {
172 DCHECK_LE(entry, capacity_);
173 DCHECK_EQ(indices_[entry],
index);
175 return values_[entry];
182 const int entry = index_to_entry_[
index];
183 if (entry == kNotPresent) {
184 DCHECK_LT(size_, capacity_);
186 index_to_entry_[
index] = size_;
187 indices_[size_] =
index;
188 values_[size_] =
value;
194 DCHECK_LE(entry, capacity_);
195 DCHECK_EQ(indices_[entry],
index);
197 values_[entry] =
value;
void Set(int index, double value)
const double * values() const
int size() const
Returns the number of entries in the sparse vector.
int capacity() const
Returns the capacity (the size of the vector if it was dense).
GlpkSparseVector(int capacity)
void Load(std::function< int(int *indices, double *values)> getter)
std::optional< double > Get(int index) const
const int * indices() const
An object oriented wrapper for quadratic constraints in ModelStorage.