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     inline
00037     std::size_t hash_label<int>::operator()(const int c) const
00038     {
00039       return c;
00040     }
00041 
00042     template <typename Word, typename Weight>
00043     std::size_t
00044     hash_label<algebra::polynom<Word, Weight> >::operator() (const algebra::polynom<Word, Weight>& l) const
00045     {
00046       std::size_t seed (0);
00047 
00048       for (typename algebra::polynom<Word, Weight>::const_iterator i = l.begin ();
00049            i != l.end ();
00050            ++i)
00051       {
00052         
00053         ::boost::hash_combine (seed, i->first); 
00054 
00055       }
00056       return seed;
00057     }
00058 
00059 # if 0
00060     template <typename Word, typename LetterT, typename WeightT>
00061     std::size_t
00062     hash_label<algebra::polynom<Word, rat::exp<LetterT, WeightT> > >::operator() (
00063           const algebra::polynom<Word, rat::exp<LetterT, WeightT> >& l) const
00064     {
00065       std::size_t seed (0);
00066       hash_label hash;
00067 
00068       for (typename algebra::polynom<Word, rat::exp<LetterT,
00069             WeightT> >::const_iterator i = l.begin ();
00070            i != l.end ();
00071            ++i)
00072       {
00073         ::boost::hash_combine (seed, hash(i->first));
00074         ::boost::hash_combine (seed, i->second);
00075       }
00076       return seed;
00077     }
00078 #endif
00079     template <typename Word, typename Word2, typename WeightT>
00080     std::size_t
00081     hash_label<algebra::polynom<Word, rat::exp<Word2, WeightT> > >::operator() (
00082         const rat::exp<Word2, WeightT>& l) const
00083     {
00084       rat::HashVisitor<Word2, WeightT> visitor;
00085       l.accept(visitor);
00086       return visitor.hash_value();
00087     }
00088 
00089 
00090     template <typename Word, typename Word2, typename WeightT>
00091     std::size_t
00092     hash_label<algebra::polynom<Word, rat::exp<Word2, WeightT> > >::operator() (
00093           const algebra::polynom<Word, rat::exp<Word2, WeightT> >& l) const
00094     {
00095       std::size_t seed (0);
00096       hash_label hash;
00097 
00098       for (typename algebra::polynom<Word, rat::exp<Word2,
00099             WeightT> >::const_iterator i = l.begin ();
00100            i != l.end ();
00101            ++i)
00102       {
00103         ::boost::hash_combine (seed, i->first);
00104         ::boost::hash_combine (seed, hash(i->second));
00105       }
00106       return seed;
00107     }
00108 
00109     template <typename Weight, typename T, typename U>
00110     std::size_t
00111     hash_label<algebra::polynom<std::pair<T, U>, Weight> >::operator() (
00112         const algebra::polynom<std::pair<T, U>, Weight >& l) const
00113     {
00114       std::size_t seed (0);
00115 
00116       for (typename algebra::polynom<std::pair<T, U>, Weight>::const_iterator i = l.begin ();
00117            i != l.end ();
00118            ++i)
00119       {
00120         ::boost::hash_combine (seed, i->first.first);
00121         ::boost::hash_combine (seed, i->first.second);
00122         ::boost::hash_combine (seed, i->second);
00123       }
00124       return seed;
00125     }
00126 
00127     template <typename Word, typename Weight>
00128     std::size_t
00129     hash_label<rat::exp<Word, Weight> >::operator() (const rat::exp<Word, Weight>& l) const
00130     {
00131       rat::HashVisitor<Word, Weight> visitor;
00132       l.accept(visitor);
00133       return visitor.hash_value();
00134     }
00135 
00136     template <typename Kind, typename Type>
00137     std::size_t
00138     hash_handler<handler<Kind, Type> >::operator() (const handler<Kind, Type>& h) const
00139     {
00140       return ::boost::hash_value (h.value());
00141     }
00142 
00143     inline
00144     std::size_t
00145     hash_handler<char>::operator() (const char c) const
00146     {
00147       return ::boost::hash_value (c);
00148     }
00149 
00150   }
00151 }
00152 
00153 #endif // ! VCSN_MISC_HASH_HXX_ //