00001
00002
00013
00014
00015 #ifndef polybori_routines_pbori_routines_hash_h_
00016 #define polybori_routines_pbori_routines_hash_h_
00017
00018 #include <polybori/pbori_defs.h>
00019 #include <boost/functional/hash.hpp>
00020
00021
00022 BEGIN_NAMESPACE_PBORI
00023
00024
00025
00026 template <class HashType, class NaviType>
00027 void
00028 stable_hash_range(HashType& seed, NaviType navi) {
00029
00030 if (navi.isConstant()) {
00031 if (navi.terminalValue())
00032 boost::hash_combine(seed, CTypes::max_index());
00033 return;
00034 }
00035
00036 boost::hash_combine(seed, *navi);
00037
00038 stable_hash_range(seed, navi.thenBranch());
00039 stable_hash_range(seed, navi.elseBranch());
00040 }
00041
00042 template <class NaviType>
00043 std::size_t
00044 stable_hash_range(NaviType navi) {
00045
00046 std::size_t seed = 0;
00047 stable_hash_range(seed, navi);
00048
00049 return seed;
00050 }
00051
00052 template <class HashType>
00053 void
00054 finalize_term_hash(HashType& seed) {
00055 boost::hash_combine(seed, CTypes::max_index());
00056 }
00057
00058 template <class HashType, class NaviType>
00059 void
00060 stable_first_hash_range(HashType& seed, NaviType navi) {
00061
00062 while (!navi.isConstant()) {
00063 boost::hash_combine(seed, *navi);
00064 navi.incrementThen();
00065 }
00066 if (navi.terminalValue())
00067 finalize_term_hash(seed);
00068
00069 }
00070
00071 template <class NaviType>
00072 std::size_t
00073 stable_first_hash_range(NaviType navi) {
00074
00075 std::size_t seed = 0;
00076 stable_first_hash_range(seed, navi);
00077
00078 return seed;
00079 }
00080
00081 template <class HashType, class Iterator>
00082 void
00083 stable_term_hash(HashType& seed, Iterator start, Iterator finish) {
00084 boost::hash_range(seed, start, finish);
00085 finalize_term_hash(seed);
00086 }
00087
00088 template <class Iterator>
00089 std::size_t
00090 stable_term_hash(Iterator start, Iterator finish) {
00091
00092 std::size_t seed(0);
00093 stable_term_hash(seed, start, finish);
00094
00095 return seed;
00096 }
00097
00098 END_NAMESPACE_PBORI
00099
00100 #endif