Murmur2 - Website

Ludicrous speed hashing v2.0. This time it's closer to the mark, but not quite. Corners were cut for the remaining 1-3 bytes, leading to biased mixing and, worst of all, zero seed avalanching for keys that are 5-7 bytes long. Some light bias on the BIC tests, even on keys that are multiples of 4 bytes.

Tests

Performance

Implementation

finline u32 fastcall Murmur2( const u8 *key, u32 len, u32 seed ) {
	const u32 m = 0x5bd1e995;
	const u8 r = 24;
	u32 h = len + seed;
	const u8 * data = (const u8 *)key;
	
	for ( ; len >= 4; len -= 4, data += 4 ) {
		u32 k = *(u32 *)data * m;
		k ^= k >> r; 
		k *= m;
		h = ( h * m ) ^ k;
	}

	switch ( len ) {
		case 3: h ^= data[2] << 16;
		case 2: h ^= data[1] << 8;
		case 1: h ^= data[0];
				h *= m;
		default:;
	}

	h ^= h >> 13;
	h *= m;
	h ^= h >> 15;
	return h;
}