summaryrefslogtreecommitdiff
path: root/src/theory/arith/arithvar_node_map.h
blob: c8b7f62a4eb2c6ca1e0d8e594291094a3a68f7ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/******************************************************************************
 * Top contributors (to current version):
 *   Tim King, Mathias Preiner
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * [[ Add one-line brief description here ]]
 *
 * [[ Add lengthier description here ]]
 * \todo document this file
 */

#include "cvc5_private.h"

#ifndef CVC5__THEORY__ARITH__ARITHVAR_NODE_MAP_H
#define CVC5__THEORY__ARITH__ARITHVAR_NODE_MAP_H

#include "theory/arith/arithvar.h"
#include "context/context.h"
#include "context/cdlist.h"
#include "context/cdhashmap.h"
#include "context/cdo.h"

namespace cvc5 {
namespace theory {
namespace arith {

class ArithVarNodeMap {
private:
  /**
   * Bidirectional map between Nodes and ArithVars.
   */
  NodeToArithVarMap d_nodeToArithVarMap;
  ArithVarToNodeMap d_arithVarToNodeMap;

public:

  typedef ArithVarToNodeMap::const_iterator var_iterator;

  ArithVarNodeMap() {}

  inline bool hasArithVar(TNode x) const {
    return d_nodeToArithVarMap.find(x) != d_nodeToArithVarMap.end();
  }

  inline bool hasNode(ArithVar a) const {
    return d_arithVarToNodeMap.isKey(a);
  }

  inline ArithVar asArithVar(TNode x) const{
    Assert(hasArithVar(x));
    Assert((d_nodeToArithVarMap.find(x))->second <= ARITHVAR_SENTINEL);
    return (d_nodeToArithVarMap.find(x))->second;
  }

  inline Node asNode(ArithVar a) const{
    Assert(hasNode(a));
    return d_arithVarToNodeMap[a];
  }

  inline void setArithVar(TNode x, ArithVar a){
    Assert(!hasArithVar(x));
    Assert(!d_arithVarToNodeMap.isKey(a));
    d_arithVarToNodeMap.set(a, x);
    d_nodeToArithVarMap[x] = a;
  }

  inline void remove(ArithVar x){
    Assert(hasNode(x));
    Node node = asNode(x);

    d_nodeToArithVarMap.erase(d_nodeToArithVarMap.find(node));
    d_arithVarToNodeMap.remove(x);
  }

  var_iterator var_begin() const {
    return d_arithVarToNodeMap.begin();
  }
  var_iterator var_end() const {
    return d_arithVarToNodeMap.end();
  }

};/* class ArithVarNodeMap */

}  // namespace arith
}  // namespace theory
}  // namespace cvc5

#endif /* CVC5__THEORY__ARITH__ARITHVAR_NODE_MAP_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback