5 constexpr plUInt32 PRIME32_1 = 0x9E3779B1U;
6 constexpr plUInt32 PRIME32_2 = 0x85EBCA77U;
7 constexpr plUInt32 PRIME32_3 = 0xC2B2AE3DU;
8 constexpr plUInt32 PRIME32_4 = 0x27D4EB2FU;
9 constexpr plUInt32 PRIME32_5 = 0x165667B1U;
11 constexpr plUInt64 PRIME64_1 = 0x9E3779B185EBCA87ULL;
12 constexpr plUInt64 PRIME64_2 = 0xC2B2AE3D27D4EB4FULL;
13 constexpr plUInt64 PRIME64_3 = 0x165667B19E3779F9ULL;
14 constexpr plUInt64 PRIME64_4 = 0x85EBCA77C2B2AE63ULL;
15 constexpr plUInt64 PRIME64_5 = 0x27D4EB2F165667C5ULL;
17 constexpr plUInt32 plRotLeft(plUInt32 value, plUInt32 uiAmount)
19 return (value << uiAmount) | (value >> (32 - uiAmount));
21 constexpr plUInt64 plRotLeft(plUInt64 value, plUInt64 uiAmount)
23 return (value << uiAmount) | (value >> (64 - uiAmount));
27 constexpr plUInt32 CompileTimeXxHash32(
const char (&str)[N], plUInt32 uiSeed)
30 constexpr plUInt32 length =
static_cast<plUInt32
>(N - 1);
31 if constexpr (length == 0)
40 if constexpr (length < 16)
42 acc = uiSeed + PRIME32_5;
46 plUInt32 accs[4] = {uiSeed + PRIME32_1 + PRIME32_2, uiSeed + PRIME32_2, uiSeed, uiSeed - PRIME32_1};
47 for (; length - index >= 16; index += 16)
49 for (
int i = 0; i < 4; i++)
51 plUInt32 laneN = (
static_cast<plUInt32
>(str[index + i * 4 + 0]) << 0) | (
static_cast<plUInt32
>(str[index + i * 4 + 1]) << 8) |
52 (
static_cast<plUInt32
>(str[index + i * 4 + 2]) << 16) | (
static_cast<plUInt32
>(str[index + i * 4 + 3]) << 24);
53 accs[i] = accs[i] + (laneN * PRIME32_2);
54 accs[i] = plRotLeft(accs[i], 13);
55 accs[i] = accs[i] * PRIME32_1;
58 acc = plRotLeft(accs[0], 1) + plRotLeft(accs[1], 7) + plRotLeft(accs[2], 12) + plRotLeft(accs[3], 18);
65 for (; length - index >= 4; index += 4)
67 plUInt32 lane = (
static_cast<plUInt32
>(str[index + 0]) << 0) | (
static_cast<plUInt32
>(str[index + 1]) << 8) |
68 (
static_cast<plUInt32
>(str[index + 2]) << 16) | (
static_cast<plUInt32
>(str[index + 3]) << 24);
69 acc = acc + lane * PRIME32_3;
70 acc = plRotLeft(acc, 17) * PRIME32_4;
73 for (; length - index >= 1; index++)
75 plUInt32 lane =
static_cast<plUInt32
>(str[index]);
76 acc = acc + lane * PRIME32_5;
77 acc = plRotLeft(acc, 11) * PRIME32_1;
81 acc = acc ^ (acc >> 15);
82 acc = acc * PRIME32_2;
83 acc = acc ^ (acc >> 13);
84 acc = acc * PRIME32_3;
85 acc = acc ^ (acc >> 16);
92 constexpr plUInt64 CompileTimeXxHash64(
const char (&str)[N], plUInt64 uiSeed)
95 constexpr plUInt32 length =
static_cast<plUInt32
>(N - 1);
96 if constexpr (length == 0)
98 return 17241709254077376921llu;
106 if constexpr (length < 32)
109 acc = uiSeed + PRIME64_5;
113 plUInt64 accs[] = {uiSeed + PRIME64_1 + PRIME64_2, uiSeed + PRIME64_2, uiSeed + 0, uiSeed - PRIME64_1};
115 for (; length - index >= 32; index += 32)
117 for (
int i = 0; i < 4; i++)
119 plUInt64 laneN = (
static_cast<plUInt64
>(str[index + i * 8 + 0]) << 0) | (
static_cast<plUInt64
>(str[index + i * 8 + 1]) << 8) |
120 (
static_cast<plUInt64
>(str[index + i * 8 + 2]) << 16) | (
static_cast<plUInt64
>(str[index + i * 8 + 3]) << 24) |
121 (
static_cast<plUInt64
>(str[index + i * 8 + 4]) << 32) | (
static_cast<plUInt64
>(str[index + i * 8 + 5]) << 40) |
122 (
static_cast<plUInt64
>(str[index + i * 8 + 6]) << 48) | (
static_cast<plUInt64
>(str[index + i * 8 + 7]) << 56);
123 accs[i] = accs[i] + (laneN * PRIME64_2);
124 accs[i] = plRotLeft(accs[i], 31ULL);
125 accs[i] = accs[i] * PRIME64_1;
130 acc = plRotLeft(accs[0], 1ULL) + plRotLeft(accs[1], 7ULL) + plRotLeft(accs[2], 12ULL) + plRotLeft(accs[3], 18ULL);
131 for (
int i = 0; i < 4; i++)
133 acc = (acc ^ (plRotLeft(accs[i] * PRIME64_2, 31ULL) * PRIME64_1)) * PRIME64_1 + PRIME64_4;
140 for (; length - index >= 8; index += 8)
142 plUInt64 lane = (
static_cast<plUInt64
>(str[index + 0]) << 0) | (
static_cast<plUInt64
>(str[index + 1]) << 8) |
143 (
static_cast<plUInt64
>(str[index + 2]) << 16) | (
static_cast<plUInt64
>(str[index + 3]) << 24) |
144 (
static_cast<plUInt64
>(str[index + 4]) << 32) | (
static_cast<plUInt64
>(str[index + 5]) << 40) |
145 (
static_cast<plUInt64
>(str[index + 6]) << 48) | (
static_cast<plUInt64
>(str[index + 7]) << 56);
146 acc = acc ^ (plRotLeft(lane * PRIME64_2, 31ULL) * PRIME64_1);
147 acc = plRotLeft(acc, 27ULL) * PRIME64_1;
151 for (; length - index >= 4; index += 4)
153 plUInt64 lane = (
static_cast<plUInt64
>(str[index + 0]) << 0) | (
static_cast<plUInt64
>(str[index + 1]) << 8) |
154 (
static_cast<plUInt64
>(str[index + 2]) << 16) | (
static_cast<plUInt64
>(str[index + 3]) << 24);
155 acc = acc ^ (lane * PRIME64_1);
156 acc = plRotLeft(acc, 23ULL) * PRIME64_2;
160 for (; length - index >= 1; index++)
162 plUInt64 lane =
static_cast<plUInt64
>(str[index]);
163 acc = acc ^ (lane * PRIME64_5);
164 acc = plRotLeft(acc, 11ULL) * PRIME64_1;
168 acc = acc ^ (acc >> 33);
169 acc = acc * PRIME64_2;
170 acc = acc ^ (acc >> 29);
171 acc = acc * PRIME64_3;
172 acc = acc ^ (acc >> 32);
182 return plInternal::CompileTimeXxHash32(str, uiSeed);
188 return plInternal::CompileTimeXxHash64(str, uiSeed);
static constexpr plUInt64 xxHash64String(const char(&str)[N], plUInt64 uiSeed=0)
Calculates the 64bit xxHash of the given string literal at compile time.
static plUInt32 xxHash32(const void *pKey, size_t uiSizeInByte, plUInt32 uiSeed=0)
Calculates the 32bit xxHash of the given key.
Definition HashingUtils.cpp:209
static constexpr plUInt32 xxHash32String(const char(&str)[N], plUInt32 uiSeed=0)
Calculates the 32bit xxHash of the given string literal at compile time.
static plUInt64 xxHash64(const void *pKey, size_t uiSizeInByte, plUInt64 uiSeed=0)
Calculates the 64bit xxHash of the given key.
Definition HashingUtils.cpp:215
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
plUInt32 GetElementCount() const
Returns the number of bytes from the start position up to its end.
Definition StringView.h:93
const char * GetStartPointer() const
Returns the start of the view range.
Definition StringView.h:102