00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef VCSN_MISC_HASH_HXX_
00019 # define VCSN_MISC_HASH_HXX_
00020
00021 # include <utility>
00022 # include <boost/functional/hash/hash.hpp>
00023 # include <vaucanson/algebra/implementation/series/rat/hash_visitor.hh>
00024
00025 namespace vcsn
00026 {
00027 namespace misc
00028 {
00029
00030 inline
00031 std::size_t hash_label<char>::operator()(const char c) const
00032 {
00033 return c;
00034 };
00035
00036 template <typename Word, typename Weight>
00037 std::size_t
00038 hash_label<algebra::polynom<Word, Weight> >::operator() (const algebra::polynom<Word, Weight>& l) const
00039 {
00040 std::size_t seed (0);
00041
00042 for (typename algebra::polynom<Word, Weight>::const_iterator i = l.begin ();
00043 i != l.end ();
00044 ++i)
00045 {
00046 ::boost::hash_combine (seed, i->first);
00047 ::boost::hash_combine (seed, i->second);
00048 }
00049 return seed;
00050 }
00051
00052 template <typename Word, typename LetterT, typename WeightT>
00053 std::size_t
00054 hash_label<algebra::polynom<Word, rat::exp<LetterT, WeightT> > >::operator() (
00055 const algebra::polynom<Word, rat::exp<LetterT, WeightT> >& l) const
00056 {
00057 std::size_t seed (0);
00058 hash_label hash;
00059
00060 for (typename algebra::polynom<Word, rat::exp<LetterT,
00061 WeightT> >::const_iterator i = l.begin ();
00062 i != l.end ();
00063 ++i)
00064 {
00065 ::boost::hash_combine (seed, hash(i->first));
00066 ::boost::hash_combine (seed, i->second);
00067 }
00068 return seed;
00069 }
00070
00071 template <typename Word, typename WeightT>
00072 std::size_t
00073 hash_label<algebra::polynom<Word, rat::exp<std::string, WeightT> > >::operator() (
00074 const rat::exp<std::string, WeightT>& l) const
00075 {
00076 rat::HashVisitor<std::string, WeightT> visitor;
00077 l.accept(visitor);
00078 return visitor.hash_value();
00079 }
00080
00081
00082 template <typename Word, typename WeightT>
00083 std::size_t
00084 hash_label<algebra::polynom<Word, rat::exp<std::string, WeightT> > >::operator() (
00085 const algebra::polynom<Word, rat::exp<std::string, WeightT> >& l) const
00086 {
00087 std::size_t seed (0);
00088 hash_label hash;
00089
00090 for (typename algebra::polynom<Word, rat::exp<std::string,
00091 WeightT> >::const_iterator i = l.begin ();
00092 i != l.end ();
00093 ++i)
00094 {
00095 ::boost::hash_combine (seed, i->first);
00096 ::boost::hash_combine (seed, hash(i->second));
00097 }
00098 return seed;
00099 }
00100
00101 template <typename Weight, typename T, typename U>
00102 std::size_t
00103 hash_label<algebra::polynom<std::pair<T, U>, Weight> >::operator() (
00104 const algebra::polynom<std::pair<T, U>, Weight >& l) const
00105 {
00106 std::size_t seed (0);
00107
00108 for (typename algebra::polynom<std::pair<T, U>, Weight>::const_iterator i = l.begin ();
00109 i != l.end ();
00110 ++i)
00111 {
00112 ::boost::hash_combine (seed, i->first.first);
00113 ::boost::hash_combine (seed, i->first.second);
00114 ::boost::hash_combine (seed, i->second);
00115 }
00116 return seed;
00117 }
00118
00119 template <typename Word, typename Weight>
00120 std::size_t
00121 hash_label<rat::exp<Word, Weight> >::operator() (const rat::exp<Word, Weight>& l) const
00122 {
00123 rat::HashVisitor<Word, Weight> visitor;
00124 l.accept(visitor);
00125 return visitor.hash_value();
00126 }
00127
00128 template <typename Kind, typename Type>
00129 std::size_t
00130 hash_handler<handler<Kind, Type> >::operator() (const handler<Kind, Type>& h) const
00131 {
00132 return ::boost::hash_value (h.value());
00133 }
00134
00135 inline
00136 std::size_t
00137 hash_handler<char>::operator() (const char c) const
00138 {
00139 return ::boost::hash_value (c);
00140 }
00141
00142 }
00143 }
00144
00145 #endif // ! VCSN_MISC_HASH_HXX_ //