MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / CityHash32

Function CityHash32

extern/libcds/test/stress/framework/city.cpp:172–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170}
171
172uint32 CityHash32(const char *s, size_t len) {
173 if (len <= 24) {
174 return len <= 12 ?
175 (len <= 4 ? Hash32Len0to4(s, len) : Hash32Len5to12(s, len)) :
176 Hash32Len13to24(s, len);
177 }
178
179 // len > 24
180 uint32 h = static_cast<uint32>( len ), g = static_cast<uint32>( c1 * len ), f = g;
181 uint32 a0 = Rotate32(Fetch32(s + len - 4) * c1, 17) * c2;
182 uint32 a1 = Rotate32(Fetch32(s + len - 8) * c1, 17) * c2;
183 uint32 a2 = Rotate32(Fetch32(s + len - 16) * c1, 17) * c2;
184 uint32 a3 = Rotate32(Fetch32(s + len - 12) * c1, 17) * c2;
185 uint32 a4 = Rotate32(Fetch32(s + len - 20) * c1, 17) * c2;
186 h ^= a0;
187 h = Rotate32(h, 19);
188 h = h * 5 + 0xe6546b64;
189 h ^= a2;
190 h = Rotate32(h, 19);
191 h = h * 5 + 0xe6546b64;
192 g ^= a1;
193 g = Rotate32(g, 19);
194 g = g * 5 + 0xe6546b64;
195 g ^= a3;
196 g = Rotate32(g, 19);
197 g = g * 5 + 0xe6546b64;
198 f += a4;
199 f = Rotate32(f, 19);
200 f = f * 5 + 0xe6546b64;
201 size_t iters = (len - 1) / 20;
202 do {
203 a0 = Rotate32(Fetch32(s) * c1, 17) * c2;
204 a1 = Fetch32(s + 4);
205 a2 = Rotate32(Fetch32(s + 8) * c1, 17) * c2;
206 a3 = Rotate32(Fetch32(s + 12) * c1, 17) * c2;
207 a4 = Fetch32(s + 16);
208 h ^= a0;
209 h = Rotate32(h, 18);
210 h = h * 5 + 0xe6546b64;
211 f += a1;
212 f = Rotate32(f, 19);
213 f = f * c1;
214 g += a2;
215 g = Rotate32(g, 18);
216 g = g * 5 + 0xe6546b64;
217 h ^= a3 + a1;
218 h = Rotate32(h, 19);
219 h = h * 5 + 0xe6546b64;
220 g ^= a4;
221 g = bswap_32(g) * 5;
222 h += a4 * 5;
223 h = bswap_32(h);
224 f += a0;
225 PERMUTE3(f, h, g);
226 s += 20;
227 } while (--iters != 0);
228 g = Rotate32(g, 11) * c1;
229 g = Rotate32(g, 17) * c1;

Callers 1

operator()Method · 0.85

Calls 5

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

Tested by

no test coverage detected