Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hash.hh
Go to the documentation of this file.
1 #ifndef VCSN_CORE_RAT_HASH_HH
2 # define VCSN_CORE_RAT_HASH_HH
3 
4 # include <vcsn/core/rat/visitor.hh>
5 # include <vcsn/misc/attributes.hh>
6 # include <vcsn/misc/cast.hh>
7 
8 namespace vcsn
9 {
10  namespace rat
11  {
12  template <typename RatExpSet>
13  class hash
14  : public RatExpSet::const_visitor
15  {
16  public:
17  using ratexpset_t = RatExpSet;
19  using weight_t = typename context_t::weightset_t::value_t;
20  using super_t = typename ratexpset_t::const_visitor;
21  using node_t = typename super_t::node_t;
22  using inner_t = typename super_t::inner_t;
23  template <type_t Type>
24  using variadic_t = typename super_t::template variadic_t<Type>;
25  template <type_t Type>
26  using unary_t = typename super_t::template unary_t<Type>;
27  template <type_t Type>
28  using weight_node_t = typename super_t::template weight_node_t<Type>;
29  using leaf_t = typename super_t::leaf_t;
30 
32  size_t
33  operator()(const node_t& v)
34  {
35  res_ = 0;
36  v.accept(*this);
37  return res_;
38  }
39 
41  size_t
42  operator()(const std::shared_ptr<const node_t>& v)
43  {
44  return operator()(*v);
45  }
46 
47  private:
48 
49 # define DEFINE(Type) \
50  using Type ## _t = typename super_t::Type ## _t; \
51  virtual void visit(const Type ## _t& v)
52 
66 
67 # undef DEFINE
68 
70  void combine_type(const node_t& node);
71 
73  void visit_nullary(const node_t& v);
74 
76  template <rat::exp::type_t Type>
77  void visit_unary(const unary_t<Type>& v);
78 
80  template <rat::exp::type_t Type>
81  void visit_variadic(const variadic_t<Type>& v);
82 
84  template <rat::exp::type_t Type>
85  void visit_weight_node(const weight_node_t<Type>& v);
86 
87  size_t res_;
88  };
89  } // namespace rat
90 } // namespace vcsn
91 
92 # include <vcsn/core/rat/hash.hxx>
93 
94 #endif // !VCSN_CORE_RAT_HASH_HH
void visit_variadic(const variadic_t< Type > &v)
Traverse an n-ary node (+, concatenation, &, :).
Definition: hash.hxx:79
An inner node with multiple children.
Definition: fwd.hh:123
void combine_type(const node_t &node)
Update res_ by hashing the node type; this is needed for any node.
Definition: hash.hxx:41
The abstract parameterized, root for all rational expression types.
Definition: fwd.hh:80
typename ratexpset_t::const_visitor super_t
Definition: hash.hh:20
size_t res_
Definition: hash.hh:87
typename super_t::template variadic_t< Type > variadic_t
Definition: hash.hh:24
typename super_t::template unary_t< Type > unary_t
Definition: hash.hh:26
void visit_nullary(const node_t &v)
Traverse a nullary node (atom, \z, \e).
Definition: hash.hxx:49
typename super_t::leaf_t leaf_t
Definition: hash.hh:29
void visit_weight_node(const weight_node_t< Type > &v)
Traverse a weight node (lweight, rweight).
Definition: hash.hxx:68
typename detail::context_t_of_impl< base_t< ValueSet >>::type context_t_of
Definition: traits.hh:32
size_t operator()(const std::shared_ptr< const node_t > &v)
Entry point: return the hash of v.
Definition: hash.hh:42
#define DEFINE(Type)
Definition: hash.hh:49
context_t_of< ratexpset_t > context_t
Definition: hash.hh:18
typename context_t::weightset_t::value_t weight_t
Definition: hash.hh:19
typename super_t::inner_t inner_t
Definition: hash.hh:22
An inner node implementing a weight.
Definition: fwd.hh:145
size_t operator()(const node_t &v)
Entry point: return the hash of v.
Definition: hash.hh:33
RatExpSet ratexpset_t
Definition: hash.hh:17
void visit_unary(const unary_t< Type > &v)
Traverse a unary node (*, {c}).
Definition: hash.hxx:58
typename super_t::node_t node_t
Definition: hash.hh:21
typename super_t::template weight_node_t< Type > weight_node_t
Definition: hash.hh:28