3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-27 10:55:50 +00:00
z3/src/math/lp/sparse_vector.h
Lev Nachmanson 33cbd29ed0 mv util/lp to math/lp
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
2020-01-28 10:04:21 -08:00

53 lines
947 B
C++

/*++
Copyright (c) 2017 Microsoft Corporation
Module Name:
<name>
Abstract:
<abstract>
Author:
Lev Nachmanson (levnach)
Revision History:
--*/
#pragma once
#include "util/vector.h"
#include <utility>
#include "util/debug.h"
#include "math/lp/lp_utils.h"
#include "math/lp/lp_settings.h"
namespace lp {
template <typename T>
class sparse_vector {
public:
vector<std::pair<unsigned, T>> m_data;
void push_back(unsigned index, T val) {
m_data.push_back(std::make_pair(index, val));
}
#ifdef Z3DEBUG
T operator[] (unsigned i) const {
for (auto &t : m_data) {
if (t.first == i) return t.second;
}
return numeric_traits<T>::zero();
}
#endif
void divide(T const & a) {
lp_assert(!lp_settings::is_eps_small_general(a, 1e-12));
for (auto & t : m_data) { t.second /= a; }
}
unsigned size() const {
return m_data.size();
}
};
}