MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / MurmurHash3

Function MurmurHash3

src/hash.cpp:16–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector<unsigned char>& vDataToHash)
17{
18 // The following is MurmurHash3 (x86_32), see http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp
19 uint32_t h1 = nHashSeed;
20 if (vDataToHash.size() > 0)
21 {
22 const uint32_t c1 = 0xcc9e2d51;
23 const uint32_t c2 = 0x1b873593;
24
25 const int nblocks = vDataToHash.size() / 4;
26
27 //----------
28 // body
29 const uint8_t* blocks = &vDataToHash[0] + nblocks * 4;
30
31 for (int i = -nblocks; i; i++) {
32 uint32_t k1 = ReadLE32(blocks + i*4);
33
34 k1 *= c1;
35 k1 = ROTL32(k1, 15);
36 k1 *= c2;
37
38 h1 ^= k1;
39 h1 = ROTL32(h1, 13);
40 h1 = h1 * 5 + 0xe6546b64;
41 }
42
43 //----------
44 // tail
45 const uint8_t* tail = (const uint8_t*)(&vDataToHash[0] + nblocks * 4);
46
47 uint32_t k1 = 0;
48
49 switch (vDataToHash.size() & 3) {
50 case 3:
51 k1 ^= tail[2] << 16;
52 case 2:
53 k1 ^= tail[1] << 8;
54 case 1:
55 k1 ^= tail[0];
56 k1 *= c1;
57 k1 = ROTL32(k1, 15);
58 k1 *= c2;
59 h1 ^= k1;
60 };
61 }
62
63 //----------
64 // finalization
65 h1 ^= vDataToHash.size();
66 h1 ^= h1 >> 16;
67 h1 *= 0x85ebca6b;
68 h1 ^= h1 >> 13;
69 h1 *= 0xc2b2ae35;
70 h1 ^= h1 >> 16;
71
72 return h1;
73}

Callers 1

HashMethod · 0.70

Calls 3

ReadLE32Function · 0.85
ROTL32Function · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected