MyraMath
hashes.h
Go to the documentation of this file.
1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
6 #ifndef MYRAMATH_UTILITY_HASHES_H
7 #define MYRAMATH_UTILITY_HASHES_H
8 
14 #include <vector>
15 #include <functional>
16 
17 #ifdef MYRAMATH_ENABLE_CPP11
18 
19 namespace myra {
20 
22 template <class T> void hash_combine(size_t& seed, const T& t)
23  {
24  std::hash<T> hasher;
25  seed ^= hasher(t) + 0x9e3779b9 + (seed<<6) + (seed>>2);
26  }
27 
28 } // namespace myra
29 
30 namespace std {
31 
33 template <class First, class Second> struct hash < std::pair<First,Second> >
34  {
35 
36  public:
37 
38  size_t operator() (const std::pair<First,Second>& p) const
39  {
40  size_t seed = 0;
41  myra::hash_combine(seed,p.first);
42  myra::hash_combine(seed,p.second);
43  return seed;
44  }
45 
46  };
47 
49 template <class T> struct hash < std::vector<T> >
50  {
51 
52  public:
53 
54  size_t operator() (const std::vector<T>& v) const
55  {
56  size_t seed = 0;
57  for (const T& t : v)
58  myra::hash_combine(seed,t);
59  return seed;
60  }
61 
62  };
63 
64 } // namespace std
65 
66 #endif
67 
68 #endif
A std::hash for JobID, so it can be in a std::unordered_set / std::unordered_map. ...
Definition: hashes.h:30
void hash_combine(size_t &seed, const T &t)
Combines two existing hashes.
Definition: hashes.h:22
Definition: syntax.dox:1