libMesh
Loading...
Searching...
No Matches
hashing.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18#ifndef LIBMESH_HASHING_H
19#define LIBMESH_HASHING_H
20
21#include <functional>
22
23namespace libMesh
24{
25namespace boostcopy
26{
27
28inline void hash_combine_impl(std::size_t & seed, std::size_t value)
29{
30 seed ^= value + 0x9e3779b9 + (seed<<6) + (seed>>2);
31}
32
33template <typename T>
34inline void hash_combine(std::size_t & seed, const T & value)
35{
36 using std::hash;
38}
39
40}
41
42
43// Fix for STL laziness
44struct hash {
45public:
46 template <typename T1, typename T2>
47 std::size_t operator()(const std::pair<T1, T2> & x) const
48 {
49 // Hopefully argument-based lookup lets us recurse with this
50 using std::hash;
51
52 std::size_t returnval = hash<T1>()(x.first);
53 boostcopy::hash_combine(returnval, x.second);
54
55 return returnval;
56 }
57
58 template <typename T, std::size_t N>
59 std::size_t operator()(const std::array<T, N> & x) const
60 {
61 // Hopefully argument-based lookup lets us recurse with this
62 using std::hash;
63
64 std::size_t returnval = 0;
65 for (std::size_t i = 0; i != N; ++i)
66 boostcopy::hash_combine(returnval, x[i]);
67
68 return returnval;
69 }
70};
71
72
73}
74
75#endif // LIBMESH_HASHING_H
void hash_combine(std::size_t &seed, const T &value)
Definition hashing.h:34
void hash_combine_impl(std::size_t &seed, std::size_t value)
Definition hashing.h:28
The libMesh namespace provides an interface to certain functionality in the library.
std::size_t operator()(const std::array< T, N > &x) const
Definition hashing.h:59
std::size_t operator()(const std::pair< T1, T2 > &x) const
Definition hashing.h:47
static const bool value
Definition xdr_io.C:55