public void testCombineUnordered_differentBitLengths() { try { Hashing.combineUnordered(ImmutableList.of(HashCodes.fromInt(32), HashCodes.fromLong(32L))); fail(); } catch (IllegalArgumentException expected) { } }
public HashCode hash() { this.done = true; if (this.bytes == this.digest.getDigestLength()) return HashCodes.fromBytesNoCopy(this.digest.digest()); byte[] arrayOfByte = new byte[this.bytes]; System.arraycopy(this.digest.digest(), 0, arrayOfByte, 0, this.bytes); return HashCodes.fromBytesNoCopy(arrayOfByte); }
public void testCombineUnordered() { HashCode hash31 = HashCodes.fromInt(31); HashCode hash32 = HashCodes.fromInt(32); assertEquals(hash32, Hashing.combineUnordered(ImmutableList.of(hash32))); assertEquals(HashCodes.fromInt(64), Hashing.combineUnordered(ImmutableList.of(hash32, hash32))); assertEquals( HashCodes.fromInt(96), Hashing.combineUnordered(ImmutableList.of(hash32, hash32, hash32))); assertEquals( Hashing.combineUnordered(ImmutableList.of(hash31, hash32)), Hashing.combineUnordered(ImmutableList.of(hash32, hash31))); }
public void testCombineOrdered() { HashCode hash31 = HashCodes.fromInt(31); HashCode hash32 = HashCodes.fromInt(32); assertEquals(hash32, Hashing.combineOrdered(ImmutableList.of(hash32))); assertEquals( HashCodes.fromBytes(new byte[] {(byte) 0x80, 0, 0, 0}), Hashing.combineOrdered(ImmutableList.of(hash32, hash32))); assertEquals( HashCodes.fromBytes(new byte[] {(byte) 0xa0, 0, 0, 0}), Hashing.combineOrdered(ImmutableList.of(hash32, hash32, hash32))); assertFalse( Hashing.combineOrdered(ImmutableList.of(hash31, hash32)) .equals(Hashing.combineOrdered(ImmutableList.of(hash32, hash31)))); }
public void testCombineUnordered_randomHashCodes() { Random random = new Random(); List<HashCode> hashCodes = Lists.newArrayList(); for (int i = 0; i < 10; i++) { hashCodes.add(HashCodes.fromLong(random.nextLong())); } HashCode hashCode1 = Hashing.combineUnordered(hashCodes); Collections.shuffle(hashCodes); HashCode hashCode2 = Hashing.combineUnordered(hashCodes); assertEquals(hashCode1, hashCode2); }
public void testConsistentHash_ofHashCode() { checkSameResult(HashCodes.fromLong(1), 1); checkSameResult(HashCodes.fromLong(0x9999999999999999L), 0x9999999999999999L); checkSameResult(HashCodes.fromInt(0x99999999), 0x0000000099999999L); }
public void testPadToLong() { assertEquals(0x1111111111111111L, Hashing.padToLong(HashCodes.fromLong(0x1111111111111111L))); assertEquals(0x9999999999999999L, Hashing.padToLong(HashCodes.fromLong(0x9999999999999999L))); assertEquals(0x0000000011111111L, Hashing.padToLong(HashCodes.fromInt(0x11111111))); assertEquals(0x0000000099999999L, Hashing.padToLong(HashCodes.fromInt(0x99999999))); }