21 #ifndef _HASH_SUPPORT_HH_
22 #define _HASH_SUPPORT_HH_
32 #include <unordered_map>
35 namespace d3 {
namespace util {
66 if (e == NULL)
return 0;
78 if (e1 == NULL)
return e2==NULL;
79 if (e2 == NULL)
return false;
80 return (
typeid(*e1)==
typeid(*e2)?(*e1)==(*e2):
false);
93 template <
typename T1,
typename T2>
102 template <
typename T1>
106 typename std::set<T1>::const_iterator it;
107 for ( it = p.begin() ; it != p.end() ; ++it )
117 std::vector<int>::const_iterator it;
118 for ( it = p.begin() ; it != p.end() ; ++it )
136 std::vector<short>::const_iterator it;
137 for ( it = p.begin() ; it != p.end() ; ++it )
165 template<
typename T1,
typename T2>
169 operator()(
const std::pair<T1,T2> & e1,
const std::pair<T1,T2>& e2)
const
180 return std::hash<std::string>() (string);
186 bool operator()(
const std::string & g1,
const std::string & g2)
const{
193 struct hash_stat_get_type
196 operator() (
const T & t)
const
198 return typeid (t).name ();
203 struct hash_stat_get_type<T*>
206 operator() (
const T * t)
const
208 return typeid (*t).name ();
212 template<
class T1,
class T2>
213 struct hash_stat_get_type<
std::pair<T1,T2> >
216 operator() (
const std::pair<T1, T2> & p)
const
218 return std::string (
"pair ").append (hash_stat_get_type<T1> () (p.first)).append (
",").append (hash_stat_get_type<T2> () (p.second));
245 return new std::vector<int>(e1);
259 print_hash_stats(std::map<std::string, size_t> hits,
260 std::map<std::string, size_t> misses,
261 std::map<std::string, size_t> bounces)
265 for (std::map<std::string, size_t>::const_iterator it = misses.begin() ; it != misses.end() ; ++it) {
266 std::cout << it->first <<
" : ";
267 std::cout << hits[it->first] <<
" hits, ";
268 std::cout << misses[it->first] <<
" misses, ";
269 std::cout << bounces[it->first] <<
" bounces, ";
270 std::cout <<
"hit ratio " << (hits[it->first]*100 / (hits[it->first] + misses[it->first] + 1)) <<
" %, ";
271 std::cout << (bounces[it->first]*100 / (hits[it->first] + misses[it->first] + 1)) <<
" b. per h.(%)";
272 std::cout << std::endl;
273 h += hits[it->first];
274 m += misses[it->first];
275 b += bounces[it->first];
277 std::cout <<
"Hits : " << h <<
" , Misses : " << m <<
" , Bounces : " << b << std::endl;
278 std::cout << std::endl;
size_t wang32_hash(size_t key)
Thomas Wang's 32 bit hash function.
Definition: hashfunc.hh:42
Definition: hash_support.hh:226
bool operator()(const T *e1, const T *e2) const
Definition: hash_support.hh:76
bool operator()(const std::pair< T1, T2 > &e1, const std::pair< T1, T2 > &e2) const
Definition: hash_support.hh:169
bool operator()(const std::string &g1, const std::string &g2) const
Definition: hash_support.hh:186
Definition: hash_support.hh:51
bool operator()(const T &e1, const T &e2) const
Definition: hash_support.hh:53
size_t operator()(const T *e) const
Definition: hash_support.hh:64
size_t operator()(int i) const
Definition: hash_support.hh:87
size_t operator()(const std::string &string) const
Definition: hash_support.hh:179
Definition: hash_support.hh:40
size_t operator()(const T &e) const
Definition: hash_support.hh:42
std::vector< int > * operator()(const std::vector< int > &e1) const
Definition: hash_support.hh:243
Definition: hash_support.hh:230
T * operator()(const T &e1) const
Definition: hash_support.hh:232