pbori_routines_hash.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_routines_pbori_routines_hash_h_
#define polybori_routines_pbori_routines_hash_h_
// include basic definitions
#include <polybori/pbori_defs.h>
#include <boost/functional/hash.hpp>
BEGIN_NAMESPACE_PBORI
template <class HashType, class NaviType>
void
stable_hash_range(HashType& seed, NaviType navi) {
if (navi.isConstant()) {
if (navi.terminalValue())
boost::hash_combine(seed, CTypes::max_index());
return;
}
boost::hash_combine(seed, *navi);
stable_hash_range(seed, navi.thenBranch());
stable_hash_range(seed, navi.elseBranch());
}
template <class NaviType>
std::size_t
stable_hash_range(NaviType navi) {
std::size_t seed = 0;
stable_hash_range(seed, navi);
return seed;
}
template <class HashType>
void
finalize_term_hash(HashType& seed) {
boost::hash_combine(seed, CTypes::max_index());
}
template <class HashType, class NaviType>
void
stable_first_hash_range(HashType& seed, NaviType navi) {
while (!navi.isConstant()) {
boost::hash_combine(seed, *navi);
navi.incrementThen();
}
if (navi.terminalValue())
finalize_term_hash(seed);
}
template <class NaviType>
std::size_t
stable_first_hash_range(NaviType navi) {
std::size_t seed = 0;
stable_first_hash_range(seed, navi);
return seed;
}
template <class HashType, class Iterator>
void
stable_term_hash(HashType& seed, Iterator start, Iterator finish) {
boost::hash_range(seed, start, finish);
finalize_term_hash(seed);
}
template <class Iterator>
std::size_t
stable_term_hash(Iterator start, Iterator finish) {
std::size_t seed(0);
stable_term_hash(seed, start, finish);
return seed;
}
END_NAMESPACE_PBORI
#endif
polybori::stable_term_hash
std::size_t stable_term_hash(Iterator start, Iterator finish)
Definition: pbori_routines_hash.h:90
END_NAMESPACE_PBORI
#define END_NAMESPACE_PBORI
Finish project's namespace.
Definition: pbori_defs.h:77
BEGIN_NAMESPACE_PBORI
#define BEGIN_NAMESPACE_PBORI
Start project's namespace.
Definition: pbori_defs.h:74
pbori_defs.h
polybori::stable_hash_range
std::size_t stable_hash_range(NaviType navi)
Definition: pbori_routines_hash.h:44
polybori::stable_first_hash_range
std::size_t stable_first_hash_range(NaviType navi)
Definition: pbori_routines_hash.h:73
polybori::finalize_term_hash
void finalize_term_hash(HashType &seed)
Definition: pbori_routines_hash.h:54