https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Hashing.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 "MooseTypes.h"
13
14#include "libmesh/point.h"
15
20namespace hashing
21{
22typedef std::size_t HashValue;
23
27inline void
29{
30}
31
36template <class T, class... Rest>
37inline void
38hashCombine(HashValue & seed, const T & value, Rest... rest)
39{
40 std::hash<T> hasher;
41
42 seed ^= hasher(value) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
43 hashCombine(seed, rest...);
44}
45
50template <class Container>
52hashLargeContainer(Container const & container)
53{
54 std::size_t size = container.size();
55 std::size_t stride = 1 + size / 10;
56 HashValue seed = size;
57
58 for (std::size_t i = 0; i < size; i += stride)
59 {
60 hashCombine(seed, container.data()[i]);
61 }
62
63 return seed;
64}
65
69inline HashValue
71{
72 // 'Magic seed' seed that provides entropy against the other hashCombine() seed
73 HashValue seed = 3;
74
75 hashCombine(seed, point(0), point(1), point(2));
76
77 return seed;
78}
79
83inline HashValue
84hashCombine(Real time, const libMesh::Point & point)
85{
86 // 'Magic seed' seed that provides entropy against the other hashCombine() seed
87 HashValue seed = 42;
88
89 hashCombine(seed, time, point(0), point(1), point(2));
90
91 return seed;
92}
93}
const double T
This namespace provides efficient algorithms for quickly hashing different types for checking identit...
Definition Hashing.h:21
std::size_t HashValue
Definition Hashing.h:22
void hashCombine(HashValue &)
Final iteration of the variadic template with no additional arguments.
Definition Hashing.h:28
HashValue hashLargeContainer(Container const &container)
Hash function for sampling 10 points from a large container and hashing see: https://stackoverflow....
Definition Hashing.h:52