MurmurHash { public static int hash32( final byte[] data, int length, int seed) { final int m = 0x5bd1e995; final int r = 24; int h = seed^length; int length4 = length/4; for (int i=0; i<length4; i++) { final int i4 = i*4; int k = (data[i4+0]&0xff) +((data[i4+1]&0xff)<<8) +((data[i4+2]&0xff)<<16) +((data[i4+3]&0xff)<<24); k *= m; k ^= k >>> r; k *= m; h *= m; h ^= k; } switch (length%4) { case 3: h ^= (data[(length&~3) +2]&0xff) << 16; case 2: h ^= (data[(length&~3) +1]&0xff) << 8; case 1: h ^= (data[length&~3]&0xff); h *= m; } h ^= h >>> 13; h *= m; h ^= h >>> 15; return h; }  static int hash32( final byte[] data, int length, int seed); static int hash32( final byte[] data, int length); static int hash32( final String text); static int hash32( final String text, int from, int length); static long hash64( final byte[] data, int length, int seed); static long hash64( final byte[] data, int length); static long hash64( final String text); static long hash64( final String text, int from, int length);  }
@Test public void testHash32ByteArrayIntInt() { for (int i=0; i<input.length; i++) { int hash = MurmurHash.hash32( input[i], input[i].length, 0x71b4954d); if (hash != results32_seed[ i]) fail( String.format( "Unexpected hash32 result for example %d: 0x%08x instead of 0x%08x", i, hash, results32_seed[i])); } }
@Test public void testHash32ByteArrayInt() { for (int i=0; i<input.length; i++) { int hash = MurmurHash.hash32( input[i], input[i].length); if (hash != results32_standard[ i]) fail( String.format( "Unexpected hash32 result for example %d: 0x%08x instead of 0x%08x", i, hash, results32_standard[i])); } }
@Test public void testHash32String() { int hash = MurmurHash.hash32( text); assertTrue( hash == 0xb3bf597e); }
@Test public void testHash32StringIntInt() { int hash = MurmurHash.hash32( text, 2, text.length()-4); assertTrue( hash == 0x4d666d90); }