Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_HashUtils.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Panzer: A partial differential equation assembly
4// engine for strongly coupled complex multiphysics systems
5//
6// Copyright 2011 NTESS and the Panzer contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
11// *******************************************************************
12// This file contains a copy of hash support code from boost that
13// didn't make it into the stl. We only needed two lines code so
14// copied it here. Below is boost copyright.
15// *******************************************************************
16
17// Copyright 2005-2014 Daniel James.
18// Distributed under the Boost Software License, Version 1.0. (See accompanying
19// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
20
21// Based on Peter Dimov's proposal
22// http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf
23// issue 6.18.
24//
25// This also contains public domain code from MurmurHash. From the
26// MurmurHash header:
27
28// MurmurHash3 was written by Austin Appleby, and is placed in the public
29// domain. The author hereby disclaims copyright to this source code.
30
31// *******************************************************************
32// *******************************************************************
33
34#ifndef PANZER_HASH_UTILS_HPP
35#define PANZER_HASH_UTILS_HPP
36
37namespace panzer {
38
46 template <class T>
47 inline void hash_combine(std::size_t& seed, const T& v)
48 {
49 std::hash<T> hasher;
50 seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
51 }
52
54 struct pair_hash
55 {
56 template<typename T1, typename T2>
57 std::size_t operator()(const std::pair<T1,T2>& v) const
58 {
59 std::size_t seed = 0;
60 panzer::hash_combine(seed, v.first);
61 panzer::hash_combine(seed, v.second);
62 return seed;
63 }
64 };
65
66}
67
68namespace std
69{
71template <typename T1, typename T2>
72struct hash<std::pair<T1,T2> >
73{
74 std::size_t operator()(const std::pair<T1,T2>& v) const
75 {
76 std::size_t seed = 0;
77 panzer::hash_combine(seed, v.first);
78 panzer::hash_combine(seed, v.second);
79 return seed;
80 }
81};
82}
83
84#endif
void hash_combine(std::size_t &seed, const T &v)
Mixes the hash of v into seed, in place. Used to build a combined hash from multiple values.
A hash functor for std::pair, combining the hashes of both elements via hash_combine()....
std::size_t operator()(const std::pair< T1, T2 > &v) const
std::size_t operator()(const std::pair< T1, T2 > &v) const