return consistentHash(hashCode.padToLong(), buckets);
HashCode md5 = Files.hash(file, Hashing.md5()); byte[] md5Bytes = md5.asBytes(); String md5Hex = md5.toString(); HashCode crc32 = Files.hash(file, Hashing.crc32()); int crc32Int = crc32.asInt(); // the Checksum API returns a long, but it's padded with 0s for 32-bit CRC // this is the value you would get if using that API directly long checksumResult = crc32.padToLong();
return consistentHash(hashCode.padToLong(), buckets);
return consistentHash(hashCode.padToLong(), buckets);
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()); }
private static void assertChecksum(ImmutableSupplier<Checksum> supplier, String input) { byte[] bytes = HashTestUtils.ascii(input); Checksum checksum = supplier.get(); checksum.update(bytes, 0, bytes.length); long value = checksum.getValue(); String toString = "name"; HashFunction func = new ChecksumHashFunction(supplier, 32, toString); assertEquals(toString, func.toString()); assertEquals(value, func.hashBytes(bytes).padToLong()); }
public void testPadToLongWith8Bytes() { assertEquals(0x9999999999999999L, HashCode.fromBytesNoCopy(byteArrayWith9s(8)).padToLong()); }
public void testPadToLongWith6Bytes() { assertEquals(0x0000999999999999L, HashCode.fromBytesNoCopy(byteArrayWith9s(6)).padToLong()); }
public void testPadToLongWith4Bytes() { assertEquals(0x0000000099999999L, HashCode.fromBytesNoCopy(byteArrayWith9s(4)).padToLong()); }
/** * If {@code hashCode} has enough bits, returns {@code hashCode.asLong()}, otherwise * returns a {@code long} value with {@code hashCode.asInt()} as the least-significant * four bytes and {@code 0x00} as each of the most-significant four bytes. * * @deprecated Use {@code HashCode.padToLong()} instead. This method is scheduled to be * removed in Guava 15.0. */ @Deprecated public static long padToLong(HashCode hashCode) { return hashCode.padToLong(); }
public long getLongHashCode(String name) { return this.hashFunc.hashString(name, Charsets.UTF_8).padToLong(); }
private static void encode(String segmentId, byte[] data, ByteBuf out) { UUID id = UUID.fromString(segmentId); Hasher hasher = Hashing.murmur3_32().newHasher(); long hash = hasher.putBytes(data).hash().padToLong(); int len = data.length + EXTRA_HEADERS_WO_SIZE; out.writeInt(len); out.writeByte(Messages.HEADER_SEGMENT); out.writeLong(id.getMostSignificantBits()); out.writeLong(id.getLeastSignificantBits()); out.writeLong(hash); out.writeBytes(data); }
private static long hash(byte[] data) { return Hashing.murmur3_32().newHasher().putBytes(data).hash().padToLong(); }
public static long computeFileChecksum(@Nonnull final File file, @Nonnull final Checksum checksum) throws IOException { return ByteStreams.hash(com.google.common.io.Files.newInputStreamSupplier(file), Hashing.crc32()) .padToLong(); }
public static long hash(byte[] data) { return Hashing.murmur3_32().newHasher().putBytes(data).hash().padToLong(); }
private static void assertChecksum(Supplier<Checksum> supplier, String input) { byte[] bytes = HashTestUtils.ascii(input); Checksum checksum = supplier.get(); checksum.update(bytes, 0, bytes.length); long value = checksum.getValue(); String toString = "name"; HashFunction func = new ChecksumHashFunction(supplier, 32, toString); assertEquals(toString, func.toString()); assertEquals(value, func.hashBytes(bytes).padToLong()); }
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()); }
private static void configureStoredEntry(JarEntry entry, File inputFile) throws IOException { ByteSource byteSource = Files.asByteSource(inputFile); long size = inputFile.length(); entry.setMethod(ZipEntry.STORED); entry.setSize(size); entry.setCompressedSize(size); entry.setCrc(byteSource.hash(Hashing.crc32()).padToLong()); }
public static long hash(byte mask, long blobLength, byte[] data) { return Hashing.murmur3_32().newHasher().putByte(mask).putLong(blobLength).putBytes(data).hash().padToLong(); }
public void testPadToLongWith8Bytes() { assertEquals(0x9999999999999999L, HashCode.fromBytesNoCopy(byteArrayWith9s(8)).padToLong()); }