IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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__
15IMP_CLANG_PRAGMA(diagnostic push)
16IMP_CLANG_PRAGMA(diagnostic ignored "-Wmismatched-tags")
17#endif
18#include <boost/functional/hash.hpp>
19#include <boost/functional/hash/hash.hpp>
20#ifdef __clang__
21IMP_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
35IMPKERNEL_BEGIN_NAMESPACE
36template <class T>
37inline std::size_t hash_value(const T &t) {
38 return t.__hash__();
39}
40inline std::size_t hash_value(double d) { return boost::hash_value(d); }
41inline std::size_t hash_value(int d) { return boost::hash_value(d); }
42inline std::size_t hash_value(bool d) { return boost::hash_value(d); }
43inline std::size_t hash_value(const std::string &d) {
44 return boost::hash_value(d);
45}
46
47// for RMF
48template <class T>
49inline std::size_t hash_value(const std::vector<T> &t) {
50 return boost::hash_range(t.begin(), t.end());
51}
52
53template <class T>
54inline std::size_t hash_value(const std::set<T> &t) {
55 return boost::hash_range(t.begin(), t.end());
56}
57IMPKERNEL_END_NAMESPACE
58
59#endif /* IMPKERNEL_HASH_H */