Vcsn  2.3
Be Rational
hash.hh
Go to the documentation of this file.
1 #pragma once
2 
4 
5 namespace vcsn
6 {
7  namespace rat
8  {
9  template <typename ExpSet>
10  class hash
11  : public ExpSet::const_visitor
12  {
13  public:
14  using expressionset_t = ExpSet;
16  using weight_t = typename context_t::weightset_t::value_t;
17  using super_t = typename expressionset_t::const_visitor;
18 
20  using node_t = typename super_t::node_t;
22  using expression_t = typename node_t::value_t;
23 
24  using inner_t = typename super_t::inner_t;
25  template <type_t Type>
26  using variadic_t = typename super_t::template variadic_t<Type>;
27  template <type_t Type>
28  using unary_t = typename super_t::template unary_t<Type>;
29  template <type_t Type>
30  using weight_node_t = typename super_t::template weight_node_t<Type>;
31  using leaf_t = typename super_t::leaf_t;
32 
34  constexpr static const char* me() { return "hash"; }
35 
37  size_t operator()(const expression_t& v)
38  {
39  res_ = 0;
40  v->accept(*this);
41  return res_;
42  }
43 
44  private:
45 
61 
62  using tuple_t = typename super_t::tuple_t;
63 
64  template <bool = context_t::is_lat,
65  typename Dummy = void>
66  struct visit_tuple
67  {
68  using tupleset_t = typename expressionset_t::template as_tupleset_t<>;
69  size_t operator()(const tuple_t& v)
70  {
71  return tupleset_t::hash(v.sub());
72  }
73  };
74 
75  template <typename Dummy>
76  struct visit_tuple<false, Dummy>
77  {
78  size_t operator()(const tuple_t&)
79  {
81  }
82  };
83 
84  void visit(const tuple_t& v, std::true_type) override
85  {
86  res_ = visit_tuple<>{}(v);
87  }
88 
90  void combine_type(const node_t& node);
91 
93  void visit_(const node_t& v);
94 
96  template <rat::exp::type_t Type>
97  void visit_(const unary_t<Type>& v);
98 
100  template <rat::exp::type_t Type>
101  void visit_(const variadic_t<Type>& v);
102 
104  template <rat::exp::type_t Type>
105  void visit_(const weight_node_t<Type>& v);
106 
107  size_t res_;
108  };
109  } // namespace rat
110 } // namespace vcsn
111 
112 #include <vcsn/core/rat/hash.hxx>
return v
Definition: multiply.hh:361
typename expressionset_t::template as_tupleset_t<> tupleset_t
Definition: hash.hh:68
size_t operator()(const tuple_t &)
Definition: hash.hh:78
typename super_t::template unary_t< Type > unary_t
Definition: hash.hh:28
The abstract parameterized, root for all rational expression types.
Definition: expression.hh:80
typename super_t::template weight_node_t< Type > weight_node_t
Definition: hash.hh:30
#define BUILTIN_UNREACHABLE()
Definition: builtins.hh:13
VCSN_RAT_VISIT(transposition, v)
Definition: hash.hh:59
typename expressionset_t::const_visitor super_t
Definition: hash.hh:17
VCSN_RAT_VISIT(infiltrate, v)
Definition: hash.hh:51
typename super_t::template variadic_t< Type > variadic_t
Definition: hash.hh:26
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
Definition: traits.hh:61
void combine_type(const node_t &node)
Update res_ by hashing the node type; this is needed for any node.
Definition: hash.hxx:36
VCSN_RAT_VISIT(compose, v)
Definition: hash.hh:49
VCSN_RAT_VISIT(complement, v)
Definition: hash.hh:48
An inner node implementing a weight.
Definition: expression.hh:264
VCSN_RAT_VISIT(conjunction, v)
Definition: hash.hh:50
VCSN_RAT_VISIT(one, v)
Definition: hash.hh:55
typename node_t::value_t expression_t
A shared_ptr to node_t.
Definition: hash.hh:22
ExpSet expressionset_t
Definition: hash.hh:14
VCSN_RAT_VISIT(mul, v)
Definition: hash.hh:54
VCSN_RAT_VISIT(shuffle, v)
Definition: hash.hh:57
typename super_t::node_t node_t
Actual node, without indirection.
Definition: hash.hh:20
size_t res_
Definition: hash.hh:107
Definition: a-star.hh:8
typename super_t::inner_t inner_t
Definition: hash.hh:24
context_t_of< expressionset_t > context_t
Definition: hash.hh:15
VCSN_RAT_VISIT(ldivide, v)
Definition: hash.hh:52
size_t operator()(const tuple_t &v)
Definition: hash.hh:69
size_t operator()(const expression_t &v)
Entry point: return the hash of v.
Definition: hash.hh:37
typename super_t::tuple_t tuple_t
Definition: hash.hh:62
VCSN_RAT_VISIT(zero, v)
Definition: hash.hh:60
void visit(const tuple_t &v, std::true_type) override
Definition: hash.hh:84
typename context_t::weightset_t::value_t weight_t
Definition: hash.hh:16
void visit_(const node_t &v)
Traverse a nullary node (atom, \z, \e).
Definition: hash.hxx:43
typename super_t::leaf_t leaf_t
Definition: hash.hh:31
An inner node with multiple children.
Definition: expression.hh:118
VCSN_RAT_VISIT(star, v)
Definition: hash.hh:58
VCSN_RAT_VISIT(add, v)
Definition: hash.hh:46
static constexpr const char * me()
Name of this algorithm, for error messages.
Definition: hash.hh:34