Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_HashUtils.hpp
Go to the documentation of this file.
1 // *******************************************************************
2 // This file contains a copy of hash support code from boost that
3 // didn't make it into the stl. We only needed two lines code so
4 // copied it here. Below is boost copyright.
5 // *******************************************************************
6 
7 // Copyright 2005-2014 Daniel James.
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 
11 // Based on Peter Dimov's proposal
12 // http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf
13 // issue 6.18.
14 //
15 // This also contains public domain code from MurmurHash. From the
16 // MurmurHash header:
17 
18 // MurmurHash3 was written by Austin Appleby, and is placed in the public
19 // domain. The author hereby disclaims copyright to this source code.
20 
21 // *******************************************************************
22 // *******************************************************************
23 
24 #ifndef PANZER_HASH_UTILS_HPP
25 #define PANZER_HASH_UTILS_HPP
26 
27 namespace panzer {
28 
29  template <class T>
30  inline void hash_combine(std::size_t& seed, const T& v)
31  {
32  std::hash<T> hasher;
33  seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
34  }
35 
36  struct pair_hash
37  {
38  template<typename T1, typename T2>
39  std::size_t operator()(const std::pair<T1,T2>& v) const
40  {
41  std::size_t seed = 0;
42  panzer::hash_combine(seed, v.first);
43  panzer::hash_combine(seed, v.second);
44  return seed;
45  }
46  };
47 
48 }
49 
50 namespace std
51 {
52 template <typename T1, typename T2>
53 struct hash<std::pair<T1,T2> >
54 {
55  std::size_t operator()(const std::pair<T1,T2>& v) const
56  {
57  std::size_t seed = 0;
58  panzer::hash_combine(seed, v.first);
59  panzer::hash_combine(seed, v.second);
60  return seed;
61  }
62 };
63 }
64 
65 #endif
std::size_t operator()(const std::pair< T1, T2 > &v) const
std::size_t operator()(const std::pair< T1, T2 > &v) const
void hash_combine(std::size_t &seed, const T &v)