MCPcopy Create free account
hub / github.com/baidu/tera / GetHashNumber

Function GetHashNumber

src/utils/crypt.cc:27–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27int32_t GetHashNumber(const std::string& str, uint32_t seed, uint32_t* result) {
28 const char* data = str.c_str();
29 size_t n = str.length();
30 if (result == NULL) {
31 return -1;
32 }
33 // Similar to murmur hash
34 const uint32_t m = 0xc6a4a793;
35 const uint32_t r = 24;
36 const char* limit = data + n;
37 uint32_t h = seed ^ (n * m);
38
39 // Pick up four bytes at a time
40 while (data + 4 <= limit) {
41 uint32_t w = *(uint32_t*)data;
42 data += 4;
43 h += w;
44 h *= m;
45 h ^= (h >> 16);
46 }
47
48 // Pick up remaining bytes
49 switch (limit - data) {
50 case 3:
51 h += data[2] << 16;
52 case 2:
53 h += data[1] << 8;
54 case 1:
55 h += data[0];
56 h *= m;
57 h ^= (h >> r);
58 break;
59 }
60 *result = h;
61 return 0;
62}
63
64} // namespace tera

Callers 2

GetHashStringFunction · 0.85
GetCookieFileNameMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected