14 #ifndef OR_TOOLS_MATH_OPT_SOLVERS_GLPK_GLPK_SPARSE_VECTOR_H_
15 #define OR_TOOLS_MATH_OPT_SOLVERS_GLPK_GLPK_SPARSE_VECTOR_H_
76 int size()
const {
return size_; }
81 const int*
indices()
const {
return indices_.data(); }
86 const double*
values()
const {
return values_.data(); }
98 inline std::optional<double>
Get(
int index)
const;
146 std::vector<int> index_to_entry_;
150 std::vector<int> indices_;
154 std::vector<double> values_;
163 CHECK_LE(
index, capacity_);
165 const int entry = index_to_entry_[
index];
166 if (entry == kNotPresent) {
171 DCHECK_LE(entry, capacity_);
172 DCHECK_EQ(indices_[entry],
index);
174 return values_[entry];
179 CHECK_LE(
index, capacity_);
181 const int entry = index_to_entry_[
index];
182 if (entry == kNotPresent) {
183 DCHECK_LT(size_, capacity_);
185 index_to_entry_[
index] = size_;
186 indices_[size_] =
index;
187 values_[size_] =
value;
193 DCHECK_LE(entry, capacity_);
194 DCHECK_EQ(indices_[entry],
index);
196 values_[entry] =
value;
const int * indices() const
const double * values() const
GlpkSparseVector(const int capacity)
void Load(std::function< int(int *indices, double *values)> getter)
void Set(int index, double value)
std::optional< double > Get(int index) const