www.mooseframework.org
Typedefs | Functions
hashing Namespace Reference

This namespace provides efficient algorithms for quickly hashing different types for checking identity with a very low collision probability. More...

Typedefs

typedef std::size_t HashValue
 

Functions

void hashCombine (HashValue &)
 Final iteration of the variadic template with no additional arguments. More...
 
template<class T , class... Rest>
void hashCombine (HashValue &seed, const T &value, Rest... rest)
 Variadic template to hashing a combination with finite size see: https://stackoverflow.com/a/38140932. More...
 
template<class Container >
HashValue hashLargeContainer (Container const &container)
 Hash function for sampling 10 points from a large container and hashing see: https://stackoverflow.com/a/37007715. More...
 
HashValue hashCombine (const libMesh::Point &point)
 Hashing for Point. More...
 
HashValue hashCombine (Real time, const libMesh::Point &point)
 Hashing for Point and time, useful for Functions. More...
 

Detailed Description

This namespace provides efficient algorithms for quickly hashing different types for checking identity with a very low collision probability.

Typedef Documentation

◆ HashValue

typedef std::size_t hashing::HashValue

Definition at line 22 of file Hashing.h.

Function Documentation

◆ hashCombine() [1/4]

void hashing::hashCombine ( HashValue )
inline

Final iteration of the variadic template with no additional arguments.

Definition at line 28 of file Hashing.h.

Referenced by hashCombine(), hashLargeContainer(), TEST(), and MemoizedFunctionInterface::value().

29 {
30 }

◆ hashCombine() [2/4]

template<class T , class... Rest>
void hashing::hashCombine ( HashValue seed,
const T &  value,
Rest...  rest 
)
inline

Variadic template to hashing a combination with finite size see: https://stackoverflow.com/a/38140932.

Definition at line 38 of file Hashing.h.

39 {
40  std::hash<T> hasher;
41 
42  seed ^= hasher(value) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
43  hashCombine(seed, rest...);
44 }
HashValue hashCombine(Real time, const libMesh::Point &point)
Hashing for Point and time, useful for Functions.
Definition: Hashing.h:84

◆ hashCombine() [3/4]

HashValue hashing::hashCombine ( const libMesh::Point point)
inline

Hashing for Point.

Definition at line 70 of file Hashing.h.

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 }
HashValue hashCombine(Real time, const libMesh::Point &point)
Hashing for Point and time, useful for Functions.
Definition: Hashing.h:84
std::size_t HashValue
Definition: Hashing.h:22

◆ hashCombine() [4/4]

HashValue hashing::hashCombine ( Real  time,
const libMesh::Point point 
)
inline

Hashing for Point and time, useful for Functions.

Definition at line 84 of file Hashing.h.

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 }
HashValue hashCombine(Real time, const libMesh::Point &point)
Hashing for Point and time, useful for Functions.
Definition: Hashing.h:84
std::size_t HashValue
Definition: Hashing.h:22

◆ hashLargeContainer()

template<class Container >
HashValue hashing::hashLargeContainer ( Container const &  container)

Hash function for sampling 10 points from a large container and hashing see: https://stackoverflow.com/a/37007715.

Definition at line 52 of file Hashing.h.

Referenced by TEST().

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 }
HashValue hashCombine(Real time, const libMesh::Point &point)
Hashing for Point and time, useful for Functions.
Definition: Hashing.h:84
std::size_t HashValue
Definition: Hashing.h:22