6#include <Common/assertion.h>
18template<
typename Integer>
23 const std::size_t hashTableSize)
25 static_assert(std::is_integral_v<Integer>);
27 PH_ASSERT_GT(hashTableSize, 0);
29 return ((
static_cast<std::size_t
>(x) * 73856093) ^
30 (
static_cast<std::size_t
>(y) * 19349663) ^
31 (
static_cast<std::size_t
>(z) * 83492791)) % hashTableSize;
34template<
typename Integer>
38 const std::size_t hashTableSize)
40 static_assert(std::is_integral_v<Integer>);
42 PH_ASSERT_GT(hashTableSize, 0);
44 return ((
static_cast<std::size_t
>(x) * 73856093) ^
45 (
static_cast<std::size_t
>(y) * 83492791)) % hashTableSize;
48template<std::
integral T>
54template<std::
floating_po
int T>
58 const std::size_t hashTableSize)
60 PH_ASSERT_GT(cellSize.
x, 0);
61 PH_ASSERT_GT(cellSize.
y, 0);
62 PH_ASSERT_GT(cellSize.
z, 0);
65 static_cast<std::size_t
>(std::floor(point.
x / cellSize.
x)),
66 static_cast<std::size_t
>(std::floor(point.
y / cellSize.
y)),
67 static_cast<std::size_t
>(std::floor(point.
z / cellSize.
z)),
85 v *= 0xFF51AFD7ED558CCDULL;
87 v *= 0xC4CEB9FE1A85EC53ULL;
96 v *= 0xBF58476D1CE4E5B9ULL;
98 v *= 0x94D049BB133111EBULL;
110 v *= 0x3C79AC492BA7B653ULL;
112 v *= 0x1C69B3F74AC4AE35ULL;
118template<
typename T,
typename BitMixerType>
121 return murmur3_32(&data, 1, BitMixerType{}, seed);
124template<
typename T,
typename BitMixerType>
127 const std::size_t dataSize,
128 BitMixerType&& bitMixer,
137 static_assert(CHAR_BIT == 8);
138 static_assert(std::is_trivially_copyable_v<T>,
139 "`T` should be trivially copyable to be able to interpret it as bytes.");
141 constexpr uint32 c1 = 0xCC9E2D51UL;
142 constexpr uint32 c2 = 0x1B873593UL;
143 constexpr int r1 = 15;
144 constexpr int r2 = 13;
145 constexpr uint32 m = 5;
146 constexpr uint32 n = 0xE6546B64UL;
148 auto const bytes =
reinterpret_cast<const uint8*
>(data);
149 const std::size_t numBytes = dataSize *
sizeof(T);
150 const std::size_t numBlocks = numBytes / 4;
157 for(uint32 bi = 0; bi < numBlocks; ++bi)
159 const auto byteIndex = bi * 4;
160 PH_ASSERT_LT(byteIndex, numBytes);
163 std::copy_n(bytes + byteIndex, 4,
reinterpret_cast<uint8*
>(&block32));
167 if constexpr(std::endian::native == std::endian::big)
169 block32 = std::byteswap(block32);
175 k1 = std::rotl(k1, r1);
179 h1 = std::rotl(h1, r2);
185 auto const tailBytes = bytes + numBlocks * 4;
191 case 3: k1 ^= tailBytes[2] << 16UL;
193 case 2: k1 ^= tailBytes[1] << 8UL;
195 case 1: k1 ^= tailBytes[0];
196 k1 *= c1; k1 = std::rotl(k1, r1); k1 *= c2; h1 ^= k1;
201 h1 ^=
static_cast<uint32
>(dataSize);
202 h1 = std::forward<BitMixerType>(bitMixer)(h1);
Represents a 3-D vector.
Definition TVector3.h:17
T & y()
Definition TVector3.ipp:189
T & z()
Definition TVector3.ipp:195
T & x()
Definition TVector3.ipp:183
Math functions and utilities.
Definition TransformInfo.h:10
uint64 murmur3_bit_mix_64(uint64 v)
MurmurHash3's bit mixer. 64-bit version.
Definition hash.ipp:82
uint32 permuted_index(uint32 i, uint32 l, uint32 p)
Get the permuted index or value in O(1) space and O(1) time.
Definition hash.ipp:206
uint64 moremur_bit_mix_64(uint64 v)
A MurmurHash3-style bit mixer that outperforms the original by quite some margin. 64-bit version.
Definition hash.ipp:104
uint32 murmur3_bit_mix_32(uint32 v)
MurmurHash3's bit mixer. 32-bit version.
Definition hash.ipp:71
uint64 murmur3_v13_bit_mix_64(uint64 v)
MurmurHash3's bit mixer. 64-bit version.
Definition hash.ipp:93
uint32 murmur3_32(const T &data, uint32 seed)
Generate 32-bit hash values using MurmurHash3. Note that there are no collisions when T has <= 32 bit...
Definition hash.ipp:119
std::size_t discrete_spatial_hash(Integer x, Integer y, Integer z, std::size_t hashTableSize)
Definition hash.ipp:19