VTK  9.4.20241016
vtkHashCombiner.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
18#ifndef vtkHashCombiner_h
19#define vtkHashCombiner_h
20
21#include "vtkCommonCoreModule.h" // For export macro
22
23#include <cstdint> // For uint32_t.
24
25VTK_ABI_NAMESPACE_BEGIN
26
27class VTKCOMMONCORE_EXPORT VTK_WRAPEXCLUDE vtkHashCombiner
28{
29public:
31 template <typename T>
32 void operator()(T& h, typename std::enable_if<sizeof(T) == 8, std::size_t>::type k)
33 {
34 constexpr T m = 0xc6a4a7935bd1e995ull;
35 constexpr int r = 47;
36
37 k *= m;
38 k ^= k >> r;
39 k *= m;
40
41 h ^= k;
42 h *= m;
43
44 // Completely arbitrary number, to prevent 0's
45 // from hashing to 0.
46 h += 0xe6546b64;
47 }
48
50 template <typename T>
51 void operator()(T& h, typename std::enable_if<sizeof(T) == 4, std::size_t>::type k)
52 {
53 constexpr std::uint32_t c1 = 0xcc9e2d51;
54 constexpr std::uint32_t c2 = 0x1b873593;
55 constexpr std::uint32_t r1 = 15;
56 constexpr std::uint32_t r2 = 13;
57
58 k *= c1;
59 k = (k << r1) | (k >> (32 - r1));
60 k *= c2;
61
62 h ^= k;
63 h = (h << r2) | (h >> (32 - r2));
64 h = h * 5 + 0xe6546b64;
65 }
66};
67
68VTK_ABI_NAMESPACE_END
69#endif // vtkHashCombiner_h
RealT r2
Definition PyrC2Basis.h:20
Combine 4- and 8-byte integers into a single hash value.
void operator()(T &h, typename std::enable_if< sizeof(T)==4, std::size_t >::type k)
Combine an integer k with the 32-bit hash h (which is modified on exit).
void operator()(T &h, typename std::enable_if< sizeof(T)==8, std::size_t >::type k)
Combine an integer k with the 64-bit hash h (which is modified on exit).
Computes the portion of a dataset which is inside a selection.
#define VTK_WRAPEXCLUDE