private static HashCode fmix(int h1, int length) { h1 ^= length; h1 ^= h1 >>> 16; h1 *= 0x85ebca6b; h1 ^= h1 >>> 13; h1 *= 0xc2b2ae35; h1 ^= h1 >>> 16; return HashCode.fromInt(h1); }
@Override public HashCode hash() { return HashCode.fromInt(crc); } }
private static HashCode fmix(int h1, int length) { h1 ^= length; h1 ^= h1 >>> 16; h1 *= 0x85ebca6b; h1 ^= h1 >>> 13; h1 *= 0xc2b2ae35; h1 ^= h1 >>> 16; return HashCode.fromInt(h1); }
@Override public HashCode hash() { return HashCode.fromInt(crc); } }
@Override public HashCode hash() { return HashCode.fromInt(crc); } }
private static HashCode fmix(int h1, int length) { h1 ^= length; h1 ^= h1 >>> 16; h1 *= 0x85ebca6b; h1 ^= h1 >>> 13; h1 *= 0xc2b2ae35; h1 ^= h1 >>> 16; return HashCode.fromInt(h1); }
@Override public HashCode hash() { long value = checksum.getValue(); if (bits == 32) { /* * The long returned from a 32-bit Checksum will have all 0s for its second word, so the * cast won't lose any information and is necessary to return a HashCode of the correct * size. */ return HashCode.fromInt((int) value); } else { return HashCode.fromLong(value); } } }
@Override public HashCode hash() { long value = checksum.getValue(); if (bits == 32) { /* * The long returned from a 32-bit Checksum will have all 0s for its second word, so the * cast won't lose any information and is necessary to return a HashCode of the correct * size. */ return HashCode.fromInt((int) value); } else { return HashCode.fromLong(value); } } }
@Override public HashCode hash() { long value = checksum.getValue(); if (bits == 32) { /* * The long returned from a 32-bit Checksum will have all 0s for its second word, so the * cast won't lose any information and is necessary to return a HashCode of the correct * size. */ return HashCode.fromInt((int) value); } else { return HashCode.fromLong(value); } } }
public void testFromInt() { for (ExpectedHashCode expected : expectedHashCodes) { if (expected.bytes.length == 4) { HashCode fromInt = HashCode.fromInt(expected.asInt); assertExpectedHashCode(expected, fromInt); } } }
private static void assertHash(int expected, HashCode actual) { assertEquals(HashCode.fromInt(expected), actual); }
public void testCombineUnordered() { HashCode hash31 = HashCode.fromInt(31); HashCode hash32 = HashCode.fromInt(32); assertEquals(hash32, Hashing.combineUnordered(ImmutableList.of(hash32))); assertEquals(HashCode.fromInt(64), Hashing.combineUnordered(ImmutableList.of(hash32, hash32))); assertEquals( HashCode.fromInt(96), Hashing.combineUnordered(ImmutableList.of(hash32, hash32, hash32))); assertEquals( Hashing.combineUnordered(ImmutableList.of(hash31, hash32)), Hashing.combineUnordered(ImmutableList.of(hash32, hash31))); }
public void testObjectHashCode() { HashCode hashCode42 = HashCode.fromInt(42); assertEquals(42, hashCode42.hashCode()); }
public void testCombineUnordered_differentBitLengths() { try { HashCode unused = Hashing.combineUnordered(ImmutableList.of(HashCode.fromInt(32), HashCode.fromLong(32L))); fail(); } catch (IllegalArgumentException expected) { } }
public void testCombineOrdered_differentBitLengths() { try { HashCode unused = Hashing.combineOrdered(ImmutableList.of(HashCode.fromInt(32), HashCode.fromLong(32L))); fail(); } catch (IllegalArgumentException expected) { } }
public void testCombineOrdered() { HashCode hash31 = HashCode.fromInt(31); HashCode hash32 = HashCode.fromInt(32); assertEquals(hash32, Hashing.combineOrdered(ImmutableList.of(hash32))); assertEquals( HashCode.fromBytes(new byte[] {(byte) 0x80, 0, 0, 0}), Hashing.combineOrdered(ImmutableList.of(hash32, hash32))); assertEquals( HashCode.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 PackageSanityTests() { setDefault(LockFreeBitArray.class, new LockFreeBitArray(1)); setDefault(HashCode.class, HashCode.fromInt(1)); setDefault(String.class, "MD5"); setDefault(int.class, 32); } }
public void testConsistentHash_ofHashCode() { checkSameResult(HashCode.fromLong(1), 1); checkSameResult(HashCode.fromLong(0x9999999999999999L), 0x9999999999999999L); checkSameResult(HashCode.fromInt(0x99999999), 0x0000000099999999L); }
public void testPadToLong() { assertEquals(0x1111111111111111L, HashCode.fromLong(0x1111111111111111L).padToLong()); assertEquals(0x9999999999999999L, HashCode.fromLong(0x9999999999999999L).padToLong()); assertEquals(0x0000000011111111L, HashCode.fromInt(0x11111111).padToLong()); assertEquals(0x0000000099999999L, HashCode.fromInt(0x99999999).padToLong()); }