SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
VariableIndex.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 namespace smtrat::qe::util {
6 
7 struct VariableIndex {
8  std::vector<carl::Variable> m_vars;
9 
11 
12 
13  explicit VariableIndex(const std::vector<carl::Variable>& vs) : m_vars(vs) {}
14 
15  std::size_t add_variable(const carl::Variable v) {
16  if (std::find(m_vars.begin(), m_vars.end(), v) == m_vars.end()) {
17  m_vars.push_back(v);
18  }
19  return m_vars.size() - 1;
20  }
21 
22  void gather_variables(const FormulasT& fs) {
23  carl::carlVariables vs;
24  for (const auto& f : fs) carl::variables(f, vs);
25  for (const auto v : vs) add_variable(v);
26  }
27 
28  std::size_t index(carl::Variable v) const {
29  auto it = std::find(m_vars.begin(), m_vars.end(), v);
30  assert(it != m_vars.end());
31  return std::distance(m_vars.begin(), it);
32  }
33  carl::Variable var(std::size_t i) const {
34  assert(i < m_vars.size());
35  return m_vars[i];
36  }
37 
38  std::size_t size() const { return m_vars.size(); }
39 };
40 
41 }
static bool find(V &ts, const T &t)
Definition: Alg.h:47
carl::Formulas< Poly > FormulasT
Definition: types.h:39
VariableIndex(const std::vector< carl::Variable > &vs)
Definition: VariableIndex.h:13
std::vector< carl::Variable > m_vars
Definition: VariableIndex.h:8
std::size_t index(carl::Variable v) const
Definition: VariableIndex.h:28
std::size_t add_variable(const carl::Variable v)
Definition: VariableIndex.h:15
carl::Variable var(std::size_t i) const
Definition: VariableIndex.h:33
void gather_variables(const FormulasT &fs)
Definition: VariableIndex.h:22