MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / CityHash32

Function CityHash32

Sources/nCine/Base/HashFunctions.cpp:202–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200 }
201
202 std::uint32_t CityHash32(const char* s, std::size_t len)
203 {
204 if (len <= 24) {
205 return len <= 12
206 ? (len <= 4 ? Hash32Len0to4(s, len) : Hash32Len5to12(s, len))
207 : Hash32Len13to24(s, len);
208 }
209
210 // len > 24
211 std::uint32_t h = static_cast<std::uint32_t>(len), g = c1 * h, f = g;
212
213 std::uint32_t a0 = Rotate32(Fetch32(s + len - 4) * c1, 17) * c2;
214 std::uint32_t a1 = Rotate32(Fetch32(s + len - 8) * c1, 17) * c2;
215 std::uint32_t a2 = Rotate32(Fetch32(s + len - 16) * c1, 17) * c2;
216 std::uint32_t a3 = Rotate32(Fetch32(s + len - 12) * c1, 17) * c2;
217 std::uint32_t a4 = Rotate32(Fetch32(s + len - 20) * c1, 17) * c2;
218 h ^= a0;
219 h = Rotate32(h, 19);
220 h = h * 5 + 0xe6546b64;
221 h ^= a2;
222 h = Rotate32(h, 19);
223 h = h * 5 + 0xe6546b64;
224 g ^= a1;
225 g = Rotate32(g, 19);
226 g = g * 5 + 0xe6546b64;
227 g ^= a3;
228 g = Rotate32(g, 19);
229 g = g * 5 + 0xe6546b64;
230 f += a4;
231 f = Rotate32(f, 19);
232 f = f * 5 + 0xe6546b64;
233 std::size_t iters = (len - 1) / 20;
234 do {
235 std::uint32_t b0 = Rotate32(Fetch32(s) * c1, 17) * c2;
236 std::uint32_t b1 = Fetch32(s + 4);
237 std::uint32_t b2 = Rotate32(Fetch32(s + 8) * c1, 17) * c2;
238 std::uint32_t b3 = Rotate32(Fetch32(s + 12) * c1, 17) * c2;
239 std::uint32_t b4 = Fetch32(s + 16);
240 h ^= b0;
241 h = Rotate32(h, 18);
242 h = h * 5 + 0xe6546b64;
243 f += b1;
244 f = Rotate32(f, 19);
245 f = f * c1;
246 g += b2;
247 g = Rotate32(g, 18);
248 g = g * 5 + 0xe6546b64;
249 h ^= b3 + b1;
250 h = Rotate32(h, 19);
251 h = h * 5 + 0xe6546b64;
252 g ^= b4;
253 g = ByteSwap32(g) * 5;
254 h += b4 * 5;
255 h = ByteSwap32(h);
256 f += b0;
257 PERMUTE3(f, h, g);
258 s += 20;
259 } while (--iters != 0);

Callers

nothing calls this directly

Calls 6

Hash32Len0to4Function · 0.85
Hash32Len5to12Function · 0.85
Hash32Len13to24Function · 0.85
Rotate32Function · 0.85
Fetch32Function · 0.85
ByteSwap32Function · 0.85

Tested by

no test coverage detected