https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
17namespace Moose
18{
19
21inline void
22hash_combine(std::size_t & /*seed*/)
23{
24}
25
28template <typename T, typename... Rest>
29inline void
30hash_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
38template <typename T, typename... Rest>
39inline void
40hash_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
48template <typename T, typename... Rest>
49inline void
50hash_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
58namespace std
59{
60
61template <typename S, typename T>
62struct 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}
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
void hash_combine(std::size_t &)
Used for hash function specialization for Attribute objects.
size_t operator()(const std::pair< S, T > &val) const