com.google.common.hash.HashCode.padToLong()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(186)

本文整理了Java中com.google.common.hash.HashCode.padToLong()方法的一些代码示例,展示了HashCode.padToLong()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashCode.padToLong()方法的具体详情如下:
包路径:com.google.common.hash.HashCode
类名称:HashCode
方法名:padToLong

HashCode.padToLong介绍

[英]If this hashcode has enough bits, returns asLong(), otherwise returns a longvalue with asBytes() as the least-significant bytes and 0x00 as the remaining most-significant bytes.
[中]如果此哈希代码有足够的位,则返回asLong(),否则返回一个longvalue,其中asBytes()为最低有效字节,0x00为剩余最高有效字节。

代码示例

代码示例来源:origin: google/guava

return consistentHash(hashCode.padToLong(), buckets);

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: google/j2objc

return consistentHash(hashCode.padToLong(), buckets);

代码示例来源:origin: wildfly/wildfly

return consistentHash(hashCode.padToLong(), buckets);

代码示例来源:origin: google/guava

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());
}

代码示例来源:origin: google/guava

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());
}

代码示例来源:origin: google/guava

public void testPadToLongWith8Bytes() {
 assertEquals(0x9999999999999999L, HashCode.fromBytesNoCopy(byteArrayWith9s(8)).padToLong());
}

代码示例来源:origin: google/guava

public void testPadToLongWith6Bytes() {
 assertEquals(0x0000999999999999L, HashCode.fromBytesNoCopy(byteArrayWith9s(6)).padToLong());
}

代码示例来源:origin: google/guava

public void testPadToLongWith4Bytes() {
 assertEquals(0x0000000099999999L, HashCode.fromBytesNoCopy(byteArrayWith9s(4)).padToLong());
}

代码示例来源:origin: org.hudsonci.lib.guava/guava

/**
 * 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();
}

代码示例来源:origin: org.apache.pulsar/pulsar-broker

public long getLongHashCode(String name) {
  return this.hashFunc.hashString(name, Charsets.UTF_8).padToLong();
}

代码示例来源:origin: apache/jackrabbit-oak

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);
}

代码示例来源:origin: apache/jackrabbit-oak

private static long hash(byte[] data) {
  return Hashing.murmur3_32().newHasher().putBytes(data).hash().padToLong();
}

代码示例来源:origin: indeedeng/util

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();
}

代码示例来源:origin: apache/jackrabbit-oak

public static long hash(byte[] data) {
  return Hashing.murmur3_32().newHasher().putBytes(data).hash().padToLong();
}

代码示例来源:origin: com.google.guava/guava-tests

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());
}

代码示例来源:origin: com.google.guava/guava-tests

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());
}

代码示例来源:origin: com.android.tools.build/builder

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());
}

代码示例来源:origin: apache/jackrabbit-oak

public static long hash(byte mask, long blobLength, byte[] data) {
  return Hashing.murmur3_32().newHasher().putByte(mask).putLong(blobLength).putBytes(data).hash().padToLong();
}

代码示例来源:origin: com.google.guava/guava-tests

public void testPadToLongWith8Bytes() {
 assertEquals(0x9999999999999999L, HashCode.fromBytesNoCopy(byteArrayWith9s(8)).padToLong());
}

相关文章