MCPcopy Create free account
hub / github.com/beefytech/Beef / MurmurHash3_x86_32

Function MurmurHash3_x86_32

BeefySysLib/util/Hash.cpp:1030–1082  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1028//-----------------------------------------------------------------------------
1029
1030void MurmurHash3_x86_32(const void * key, int len,
1031 uint32_t seed, void * out)
1032{
1033 const uint8_t * data = (const uint8_t*) key;
1034 const int nblocks = len / 4;
1035
1036 uint32_t h1 = seed;
1037
1038 const uint32_t c1 = 0xcc9e2d51;
1039 const uint32_t c2 = 0x1b873593;
1040
1041 //----------
1042 // body
1043
1044 const uint32_t * blocks = (const uint32_t *) (data + nblocks * 4);
1045
1046 for (int i = -nblocks; i; i++)
1047 {
1048 uint32_t k1 = getblock32(blocks, i);
1049
1050 k1 *= c1;
1051 k1 = ROTL32(k1, 15);
1052 k1 *= c2;
1053
1054 h1 ^= k1;
1055 h1 = ROTL32(h1, 13);
1056 h1 = h1 * 5 + 0xe6546b64;
1057 }
1058
1059 //----------
1060 // tail
1061
1062 const uint8_t * tail = (const uint8_t*) (data + nblocks * 4);
1063
1064 uint32_t k1 = 0;
1065
1066 switch (len & 3)
1067 {
1068 case 3: k1 ^= tail[2] << 16;
1069 case 2: k1 ^= tail[1] << 8;
1070 case 1: k1 ^= tail[0];
1071 k1 *= c1; k1 = ROTL32(k1, 15); k1 *= c2; h1 ^= k1;
1072 };
1073
1074 //----------
1075 // finalization
1076
1077 h1 ^= len;
1078
1079 h1 = fmix32(h1);
1080
1081 *(uint32_t*) out = h1;
1082}
1083
1084//-----------------------------------------------------------------------------
1085

Callers

nothing calls this directly

Calls 2

getblock32Function · 0.85
fmix32Function · 0.85

Tested by

no test coverage detected