Exemplo n.º 1
0
 public void testHashCodesM3_128_longs()
 {
     int seed = 123;
     Random rand = new Random(seed);
     HashFunction hf = Hashing.murmur3_128(seed);
     for (int i = 0; i < 1000; i++)
     {
         long val = rand.nextLong();
         byte[] data = ByteBuffer.allocate(8).putLong(val).array();
         // guava stores the hashcodes in little endian order
         ByteBuffer buf = ByteBuffer.allocate(16).order(ByteOrder.LITTLE_ENDIAN);
         buf.put(hf.hashBytes(data).asBytes());
         buf.flip();
         long gl1 = buf.getLong();
         long gl2 = buf.getLong(8);
         long[] hc = Murmur3.hash128(data, 0, data.length, seed);
         long m1 = hc[0];
         long m2 = hc[1];
         Assert.Equal(gl1, m1);
         Assert.Equal(gl2, m2);
     }
 }
Exemplo n.º 2
0
 public void testHashCodesM3_32_longs()
 {
     int seed = 123;
     Random rand = new Random(seed);
     HashFunction hf = Hashing.murmur3_32(seed);
     for (int i = 0; i < 1000; i++)
     {
         long val = rand.nextLong();
         byte[] data = ByteBuffer.allocate(8).putLong(val).array();
         int hc1 = hf.hashBytes(data).asInt();
         int hc2 = Murmur3.hash32(data, data.length, seed);
         Assert.Equal(hc1, hc2);
     }
 }