https://mooseframework.inl.gov
MooseHashing.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include <functional>
13 #include <vector>
14 #include <utility>
15 #include <set>
16 
17 namespace Moose
18 {
19 
21 inline void
22 hash_combine(std::size_t & /*seed*/)
23 {
24 }
25 
28 template <typename T, typename... Rest>
29 inline void
30 hash_combine(std::size_t & seed, const T & v, Rest &&... rest)
31 {
32  std::hash<T> hasher;
33  seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
34  hash_combine(seed, std::forward<Rest>(rest)...);
35 }
36 
38 template <typename T, typename... Rest>
39 inline void
40 hash_combine(std::size_t & seed, const std::vector<T> & v, Rest &&... rest)
41 {
42  for (auto & val : v)
43  hash_combine(seed, val);
44  hash_combine(seed, std::forward<Rest>(rest)...);
45 }
46 
48 template <typename T, typename... Rest>
49 inline void
50 hash_combine(std::size_t & seed, const std::set<T> & v, Rest &&... rest)
51 {
52  for (auto & val : v)
53  hash_combine(seed, val);
54  hash_combine(seed, std::forward<Rest>(rest)...);
55 }
56 }
57 
58 namespace std
59 {
60 
61 template <typename S, typename T>
62 struct hash<std::pair<S, T>>
63 {
64  inline size_t operator()(const std::pair<S, T> & val) const
65  {
66  size_t seed = 0;
67  Moose::hash_combine(seed, val.first, val.second);
68  return seed;
69  }
70 };
71 }
void hash_combine(std::size_t &)
Used for hash function specialization for Attribute objects.
Definition: MooseHashing.h:22
size_t operator()(const std::pair< S, T > &val) const
Definition: MooseHashing.h:64
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...