IMP logo
IMP Reference Guide  develop.0f377ab234,2022/10/02
The Integrative Modeling Platform
hash.h
Go to the documentation of this file.
1 /**
2  * \file IMP/hash.h
3  * \brief Helper functions for implementing hashes.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_HASH_H
10 #define IMPKERNEL_HASH_H
11 
12 #include <IMP/kernel_config.h>
13 
14 #ifdef __clang__
15 IMP_CLANG_PRAGMA(diagnostic push)
16 IMP_CLANG_PRAGMA(diagnostic ignored "-Wmismatched-tags")
17 #endif
18 #include <boost/functional/hash.hpp>
19 #include <boost/functional/hash/hash.hpp>
20 #ifdef __clang__
21 IMP_CLANG_PRAGMA(diagnostic pop)
22 #endif
23 
24 // evil hack to suppress warning on cluster
25 // the expected pragmas don't work
26 #ifdef __GNUC__
27 #undef __DEPRECATED
28 #endif
29 // this specializes some hash methods
30 #include <boost/graph/adjacency_list.hpp>
31 #ifdef __GNUC__
32 #define __DEPRECATED
33 #endif
34 
35 IMPKERNEL_BEGIN_NAMESPACE
36 template <class T>
37 inline std::size_t hash_value(const T &t) {
38  return t.__hash__();
39 }
40 inline std::size_t hash_value(double d) { return boost::hash_value(d); }
41 inline std::size_t hash_value(int d) { return boost::hash_value(d); }
42 inline std::size_t hash_value(bool d) { return boost::hash_value(d); }
43 inline std::size_t hash_value(const std::string &d) {
44  return boost::hash_value(d);
45 }
46 
47 // for RMF
48 template <class T>
49 inline std::size_t hash_value(const std::vector<T> &t) {
50  return boost::hash_range(t.begin(), t.end());
51 }
52 IMPKERNEL_END_NAMESPACE
53 
54 #endif /* IMPKERNEL_HASH_H */