Vaucanson  1.4.1
hash.hh
1 // hash_label.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2007, 2008 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 
18 #ifndef VCSN_MISC_HASH_HH_
19 # define VCSN_MISC_HASH_HH_
20 
21 # include <cstddef>
22 # include <vaucanson/algebra/implementation/series/polynoms.hh>
23 # include <vaucanson/algebra/implementation/series/rat/exp.hh>
24 # include <vaucanson/automata/concept/handlers.hh>
25 # include <boost/functional/hash/hash.hpp>
26 # include <boost/shared_ptr.hpp>
27 
28 namespace vcsn
29 {
30  namespace misc
31  {
32  template <typename T>
33  struct hash_label;
34 
35  template <>
36  struct hash_label<char>
37  {
38  std::size_t operator() (const char) const;
39  };
40 
41  template <>
42  struct hash_label<int>
43  {
44  std::size_t operator() (const int) const;
45  };
46 
47  template <typename U, typename V>
48  struct hash_label<std::pair<U, V> >
49  {
50  std::size_t operator() (const std::pair<U, V>&) const;
51  };
52 
53  template <typename Word, typename Weight>
54  struct hash_label<algebra::polynom<Word, Weight> >
55  {
56  std::size_t operator() (const algebra::polynom<Word, Weight>& l) const;
57  };
58 
59  template <typename Weight, typename T, typename U>
60  struct hash_label<algebra::polynom<std::pair<T, U>, Weight> >
61  {
62  std::size_t operator() (const algebra::polynom<std::pair<T, U>, Weight>& l) const;
63  };
64 
65  template <typename Word, typename Word2, typename WeightT>
66  struct hash_label<algebra::polynom<Word, rat::exp<Word2, WeightT> > >
67  {
68  std::size_t operator() (const algebra::polynom<Word, rat::exp<Word2, WeightT> >& l) const;
69  std::size_t operator() (const rat::exp<Word2, WeightT>& l) const;
70  };
71 
72 #if 0
73  template <typename Word, typename LetterT, typename WeightT>
74  struct hash_label<algebra::polynom<Word, rat::exp<LetterT, WeightT> > >
75  {
76  std::size_t operator() (const algebra::polynom<Word, rat::exp<LetterT, WeightT> >& l) const;
77  };
78 #endif
79 
80 
81 /* template <typename Word, typename LetterT, typename WeightT>
82  struct hash_label<algebra::polynom<Word, rat::exp<std::string, rat::exp<LetterT, WeightT> > > >
83  {
84  std::size_t operator() (const algebra::polynom<Word, rat::exp<std::string, rat::exp<LetterT, WeightT > > >& l) const;
85  };
86 */
87  template <typename Word, typename Weight>
88  struct hash_label<rat::exp<Word, Weight> >
89  {
90  std::size_t operator() (const rat::exp<Word, Weight>& l) const;
91  };
92 
93  template <typename T>
94  struct hash_handler;
95 
96  template <typename Kind, typename Type>
97  struct hash_handler<handler<Kind, Type> >
98  {
99  std::size_t operator() (const handler<Kind, Type>& h) const;
100  };
101 
102  template<>
103  struct hash_handler<char>
104  {
105  std::size_t operator() (const char h) const;
106  };
107 
108  struct hash_state_handler
109  {
110  inline std::size_t operator() (const handler<state_h, std::size_t*>& h) const
111  {
112  return ::boost::hash_value (reinterpret_cast<std::size_t>(h.value()));
113  }
114 
115  inline std::size_t operator() (const boost::shared_ptr<std::size_t>& h) const
116  {
117  return ::boost::hash_value (reinterpret_cast<std::size_t>(h.get()));
118  }
119 
120  inline std::size_t operator() (const std::size_t* h) const
121  {
122  return ::boost::hash_value (reinterpret_cast<std::size_t>(h));
123  }
124  };
125 
126  }
127 } // End of namespace vcsn
128 
129 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
130 # include <vaucanson/misc/hash.hxx>
131 # endif // ! VCSN_USE_INTERFACE_ONLY || VCSN_USE_LIB
132 
133 #endif // ! VCSN_MISC_HASH_HH_ //