@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 makeHash() { // End with a byte encoding the positive integer b mod 256. finalM ^= b << 56; processM(finalM); // Finalization v2 ^= 0xFFL; sipRound(d); return HashCode.fromLong(v0 ^ v1 ^ v2 ^ v3); }
@Override public HashCode hashBytes(byte[] input, int off, int len) { checkPositionIndexes(off, off + len, input.length); return HashCode.fromLong(fingerprint(input, off, len)); }
@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 testFromLong() { for (ExpectedHashCode expected : expectedHashCodes) { if (expected.bytes.length == 8) { HashCode fromLong = HashCode.fromLong(expected.asLong); assertExpectedHashCode(expected, fromLong); } } }
@Override public HashCode makeHash() { // End with a byte encoding the positive integer b mod 256. finalM ^= b << 56; processM(finalM); // Finalization v2 ^= 0xFFL; sipRound(d); return HashCode.fromLong(v0 ^ v1 ^ v2 ^ v3); }
@Override public HashCode hashBytes(byte[] input, int off, int len) { checkPositionIndexes(off, off + len, input.length); return HashCode.fromLong(fingerprint(input, off, len)); }
@Override public HashCode makeHash() { // End with a byte encoding the positive integer b mod 256. finalM ^= b << 56; processM(finalM); // Finalization v2 ^= 0xFFL; sipRound(d); return HashCode.fromLong(v0 ^ v1 ^ v2 ^ v3); }
@Override public HashCode hashBytes(byte[] input, int off, int len) { checkPositionIndexes(off, off + len, input.length); return HashCode.fromLong(fingerprint(input, off, len)); }
public void testCombineUnordered_randomHashCodes() { Random random = new Random(RANDOM_SEED); List<HashCode> hashCodes = Lists.newArrayList(); for (int i = 0; i < 10; i++) { hashCodes.add(HashCode.fromLong(random.nextLong())); } HashCode hashCode1 = Hashing.combineUnordered(hashCodes); Collections.shuffle(hashCodes); HashCode hashCode2 = Hashing.combineUnordered(hashCodes); assertEquals(hashCode1, hashCode2); }
public void testCombineOrdered_randomHashCodes() { Random random = new Random(7); List<HashCode> hashCodes = Lists.newArrayList(); for (int i = 0; i < 10; i++) { hashCodes.add(HashCode.fromLong(random.nextLong())); } HashCode hashCode1 = Hashing.combineOrdered(hashCodes); Collections.shuffle(hashCodes, random); HashCode hashCode2 = Hashing.combineOrdered(hashCodes); assertFalse(hashCode1.equals(hashCode2)); }
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 testNullPointers() { NullPointerTester tester = new NullPointerTester() .setDefault(byte[].class, "secret key".getBytes(UTF_8)) .setDefault(HashCode.class, HashCode.fromLong(0)); tester.testAllPublicStaticMethods(Hashing.class); }
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()); }
@Override public byte[] checksumAsBytes() { isChecksumCalculated = true; /* use Guava hash code to match the other algorithms */ return HashCode.fromLong(size).asBytes(); }
@Override public HashCode makeHash() { // End with a byte encoding the positive integer b mod 256. finalM ^= b << 56; processM(finalM); // Finalization v2 ^= 0xFFL; sipRound(d); return HashCode.fromLong(v0 ^ v1 ^ v2 ^ v3); }