Vaucanson  1.4.1
hash_visitor.hxx
1 // hash_visitor.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_HASH_VISITOR_HXX
18 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_HASH_VISITOR_HXX
19 
20 # include <boost/functional/hash/hash.hpp>
21 # include <vaucanson/algebra/implementation/series/rat/dump_visitor.hh>
22 # include <vaucanson/algebra/implementation/series/rat/nodes.hh>
23 
24 namespace vcsn {
25 
26  namespace rat {
27 
28  template <class Word, class Weight>
29  HashVisitor<Word, Weight>::HashVisitor()
30  : seed_(0)
31  {
32  }
33 
34  template <class Word, class Weight>
35  HashVisitor<Word, Weight>::~HashVisitor()
36  {}
37 
38  template <class Word, class Weight>
39  void
40  HashVisitor<Word, Weight>::product(const node_t* lhs, const node_t* rhs)
41  {
42  lhs->accept(*this);
43  ::boost::hash_combine(seed_, '.');
44  rhs->accept(*this);
45  }
46 
47  template <class Word, class Weight>
48  void
49  HashVisitor<Word, Weight>::sum(const node_t* lhs, const node_t* rhs)
50  {
51  lhs->accept(*this);
52  ::boost::hash_combine(seed_, '+');
53  rhs->accept(*this);
54  }
55 
56  template<class Word, class Weight>
57  void
58  HashVisitor<Word, Weight>::star(const node_t* node)
59  {
60  node->accept(*this);
61  ::boost::hash_combine(seed_, '*');
62  }
63 
64  template<class Word, class Weight>
65  void
66  HashVisitor<Word, Weight>::left_weight(const semiring_elt_value_t& w, const node_t* node)
67  {
68  ::boost::hash_combine(seed_, w);
69  node->accept(*this);
70  }
71 
72  template<class Word, class Weight>
73  void
74  HashVisitor<Word, Weight>::right_weight(const semiring_elt_value_t& w, const node_t* node)
75  {
76  ::boost::hash_combine(seed_, ' ');
77  ::boost::hash_combine(seed_, w);
78  node->accept(*this);
79  }
80 
81  template<class Word, class Weight>
82  void
83  HashVisitor<Word, Weight>::constant(const monoid_elt_value_t& m)
84  {
85  ::boost::hash_combine(seed_, m);
86  }
87 
88  template<class Word, class Weight>
89  void
90  HashVisitor<Word, Weight>::zero()
91  {
92  ::boost::hash_combine(seed_, rat::zero());
93  }
94 
95  template<class Word, class Weight>
96  void
97  HashVisitor<Word, Weight>::one()
98  {
99  ::boost::hash_combine(seed_, rat::id());
100  }
101 
102  template<class Word, class Weight>
103  std::size_t
104  HashVisitor<Word, Weight>::hash_value()
105  {
106  return seed_;
107  }
108 
109 
110  } // rat
111 
112 } // vcsn
113 
114 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_HASH_VISITOR_HXX