SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
ExpressionHash.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 #include <boost/functional/hash.hpp>
5 
6 #include "ExpressionContent.h"
7 
8 namespace std {
9 
10  template<typename T>
11  struct hash<std::vector<T>> {
12  std::size_t operator()(const std::vector<T>& v) const {
13  std::size_t seed = 0;
14  std::hash<T> h;
15  for (const auto& t: v) boost::hash_combine(seed, h(t));
16  return seed;
17  }
18  };
19 
20  template<typename... Args>
21  struct hash<boost::variant<Args...>>: boost::static_visitor<std::size_t> {
22  template<typename T>
23  std::size_t operator()(const T& t) const {
24  return std::hash<T>()(t);
25  }
26  std::size_t operator()(const boost::variant<Args...>& content) const {
27  return boost::apply_visitor(*this, content);
28  }
29  };
30 
31  struct hash_combiner {
32  std::size_t seed;
33  hash_combiner(std::size_t _seed = 0): seed(_seed) {}
34  hash_combiner& operator()(std::size_t h) {
35  boost::hash_combine(seed, h);
36  return *this;
37  }
38  template<typename T>
39  hash_combiner& operator()(const T& t) {
40  boost::hash_combine(seed, std::hash<T>()(t));
41  return *this;
42  }
43  operator std::size_t() const {
44  return seed;
45  }
46  };
47 
48  template<>
50  std::size_t operator()(const smtrat::expression::Expression& expr) const {
51  return expr.mContent->hash;
52  }
53  };
54 
55  template<>
56  struct hash<smtrat::expression::ITEExpression> {
57  std::size_t operator()(const smtrat::expression::ITEExpression& ec) const {
59  hc(ec.condition)(ec.thencase)(ec.elsecase);
60  return hc;
61  }
62  };
63  template<>
64  struct hash<smtrat::expression::QuantifierExpression> {
66  std::hash_combiner hc(std::size_t(ec.type));
67  hc(ec.variables)(ec.expression);
68  return hc;
69  }
70  };
71  template<>
72  struct hash<smtrat::expression::UnaryExpression> {
73  std::size_t operator()(const smtrat::expression::UnaryExpression& ec) const {
74  std::hash_combiner hc(std::size_t(ec.type));
75  hc(ec.expression);
76  return hc;
77  }
78  };
79  template<>
80  struct hash<smtrat::expression::BinaryExpression> {
81  std::size_t operator()(const smtrat::expression::BinaryExpression& ec) const {
82  std::hash_combiner hc(std::size_t(ec.type));
83  hc(ec.lhs)(ec.rhs);
84  return hc;
85  }
86  };
87  template<>
88  struct hash<smtrat::expression::NaryExpression> {
89  std::size_t operator()(const smtrat::expression::NaryExpression& ec) const {
90  std::hash_combiner hc(std::size_t(ec.type));
91  hc(ec.expressions);
92  return hc;
93  }
94  };
95  template<>
96  struct hash<const smtrat::expression::ExpressionContent*> {
97  std::size_t operator()(const smtrat::expression::ExpressionContent* ec) const {
98  return ec->hash;
99  }
100  };
101 }
const ExpressionContent * mContent
Definition: Expression.h:17
static uint32_t hash(uint32_t x)
Definition: Map.h:32
Class to create the formulas for axioms.
expression::Expression Expression
std::vector< carl::Variable > variables
std::size_t operator()(const smtrat::expression::ExpressionContent *ec) const
std::size_t operator()(const smtrat::expression::BinaryExpression &ec) const
std::size_t operator()(const smtrat::expression::Expression &expr) const
std::size_t operator()(const smtrat::expression::ITEExpression &ec) const
std::size_t operator()(const smtrat::expression::NaryExpression &ec) const
std::size_t operator()(const smtrat::expression::QuantifierExpression &ec) const
std::size_t operator()(const smtrat::expression::UnaryExpression &ec) const
std::size_t operator()(const std::vector< T > &v) const
hash_combiner(std::size_t _seed=0)
hash_combiner & operator()(std::size_t h)
hash_combiner & operator()(const T &t)