murmurhash是一种高性能、低碰撞率的非加密hash算法,本测试采用版本为urmurhash2;硬件加速crc32 hash需要CPU支持SSE4.2指令集,市面上绝大部分CPU已支持,具体可检查你所使用的CPUflags
murmurhash2的代码实现
uint32_t MurmurHash2 ( const void * key, int len, uint32_t seed )
{
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
const uint32_t m = 0x5bd1e995;
const int r = 24;
// Initialize the hash to a 'random' value
uint32_t h = seed ^ len;
// Mix 4 bytes at a time into the hash
const unsigned char * data = (const unsigned char *)key;
while(len >= 4)
{
uint32_t k = *(uint32_t*)data;
k *= m;
k ^= k >> r;
k *= m;
h *= m;
h ^= k;
data += 4;
len -= 4;
}
// Handle the last few bytes of th