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

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

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

HashCode.asLong介绍

[英]Returns the first eight bytes of #asBytes(), converted to a long value in little-endian order.
[中]返回#asBytes()的前八个字节,按小尾数顺序转换为长值。

代码示例

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

@Override
boolean equalsSameBits(HashCode that) {
 return hash == that.asLong();
}

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

@Override
boolean equalsSameBits(HashCode that) {
 return hash == that.asLong();
}

代码示例来源:origin: apache/incubator-druid

@Override
public long hash(String k)
{
 return fn.hashString(k, StandardCharsets.UTF_8).asLong();
}

代码示例来源:origin: prestodb/presto

public long hash()
{
  return hasher.hash().asLong();
}

代码示例来源:origin: apache/incubator-druid

private void addNodeKeyHashes(String key)
{
 long[] hashes = new long[REPLICATION_FACTOR];
 for (int i = 0; i < REPLICATION_FACTOR; i++) {
  String vnode = key + "-" + i;
  hashes[i] = hashFn.hashString(vnode, StandardCharsets.UTF_8).asLong();
 }
 nodeKeyHashes.put(key, hashes);
}

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

/** Convenience method to compute a fingerprint on a subset of a byte array. */
private static long fingerprint(byte[] bytes, int length) {
 return HASH_FN.hashBytes(bytes, 0, length).asLong();
}

代码示例来源:origin: ben-manes/caffeine

@Override
 public LongStream events() throws IOException {
  return lines()
    .map(line -> line.split(" "))
    .filter(array -> array[3].equals("GETVIDEO"))
    .mapToLong(array -> Hashing.murmur3_128().hashUnencodedChars(array[4]).asLong());
 }
}

代码示例来源:origin: springside/springside4

/**
 * 对输入字符串进行murmur128散列, 返回值可能是负数
 */
public static long murmur128AsLong(@NotNull byte[] input) {
  return Hashing.murmur3_128(MURMUR_SEED).hashBytes(input).asLong();
}

代码示例来源:origin: springside/springside4

/**
   * 对输入字符串进行murmur128散列, 返回值可能是负数
   */
  public static long murmur128AsLong(@NotNull String input) {
    return Hashing.murmur3_128(MURMUR_SEED).hashString(input, Charsets.UTF_8).asLong();
  }
}

代码示例来源:origin: ben-manes/caffeine

@Override
public LongStream events() throws IOException {
 return lines()
   .map(this::parseRequest)
   .filter(Objects::nonNull)
   .mapToLong(path -> Hashing.murmur3_128().hashUnencodedChars(path).asLong());
}

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

private static void assertSip(String input, long expected) {
 assertEquals(expected, SIP_WITH_KEY.hashString(input, UTF_8).asLong());
 assertEquals(expected, SIP_WITH_KEY.newHasher().putString(input, UTF_8).hash().asLong());
 assertEquals(expected, SIP_WITHOUT_KEY.hashString(input, UTF_8).asLong());
 assertEquals(expected, SIP_WITHOUT_KEY.newHasher().putString(input, UTF_8).hash().asLong());
}

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

private static void assertSip(byte[] input, long expected) {
  assertEquals(expected, SIP_WITH_KEY.hashBytes(input).asLong());
  assertEquals(expected, SIP_WITH_KEY.newHasher().putBytes(input).hash().asLong());
  assertEquals(expected, SIP_WITHOUT_KEY.hashBytes(input).asLong());
  assertEquals(expected, SIP_WITHOUT_KEY.newHasher().putBytes(input).hash().asLong());
 }
}

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

public void test15ByteStringFromSipHashPaper() {
 byte[] message =
   new byte[] {
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e
   };
 long k0 = 0x0706050403020100L;
 long k1 = 0x0f0e0d0c0b0a0908L;
 assertEquals(0xa129ca6149be45e5L, Hashing.sipHash24(k0, k1).hashBytes(message).asLong());
}

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

public void testHashFloatIsStable() {
 // Just a spot check.  Better than nothing.
 Hasher hasher = HASH_FN.newHasher();
 hasher.putFloat(0x01000101f).putFloat(0f);
 assertEquals(0x49f9d18ee8ae1b28L, hasher.hash().asLong());
 hasher = HASH_FN.newHasher();
 hasher.putDouble(0x0000000001000101d);
 assertEquals(0x388ee898bad75cbfL, hasher.hash().asLong());
}

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

@Override
public <T> boolean put(
  T object, Funnel<? super T> funnel, int numHashFunctions, LockFreeBitArray bits) {
 long bitSize = bits.bitSize();
 long hash64 = Hashing.murmur3_128().hashObject(object, funnel).asLong();
 int hash1 = (int) hash64;
 int hash2 = (int) (hash64 >>> 32);
 boolean bitsChanged = false;
 for (int i = 1; i <= numHashFunctions; i++) {
  int combinedHash = hash1 + (i * hash2);
  // Flip all the bits if it's negative (guaranteed positive number)
  if (combinedHash < 0) {
   combinedHash = ~combinedHash;
  }
  bitsChanged |= bits.set(combinedHash % bitSize);
 }
 return bitsChanged;
}

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

@Override
 public <T> boolean mightContain(
   T object, Funnel<? super T> funnel, int numHashFunctions, LockFreeBitArray bits) {
  long bitSize = bits.bitSize();
  long hash64 = Hashing.murmur3_128().hashObject(object, funnel).asLong();
  int hash1 = (int) hash64;
  int hash2 = (int) (hash64 >>> 32);
  for (int i = 1; i <= numHashFunctions; i++) {
   int combinedHash = hash1 + (i * hash2);
   // Flip all the bits if it's negative (guaranteed positive number)
   if (combinedHash < 0) {
    combinedHash = ~combinedHash;
   }
   if (!bits.get(combinedHash % bitSize)) {
    return false;
   }
  }
  return true;
 }
},

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

private static void assertExpectedHashCode(ExpectedHashCode expectedHashCode, HashCode hash) {
 assertTrue(Arrays.equals(expectedHashCode.bytes, hash.asBytes()));
 byte[] bb = new byte[hash.bits() / 8];
 hash.writeBytesTo(bb, 0, bb.length);
 assertTrue(Arrays.equals(expectedHashCode.bytes, bb));
 assertEquals(expectedHashCode.asInt, hash.asInt());
 if (expectedHashCode.asLong == null) {
  try {
   hash.asLong();
   fail();
  } catch (IllegalStateException expected) {
  }
 } else {
  assertEquals(expectedHashCode.asLong.longValue(), hash.asLong());
 }
 assertEquals(expectedHashCode.toString, hash.toString());
 assertSideEffectFree(hash);
 assertReadableBytes(hash);
}

代码示例来源:origin: apache/incubator-druid

public String findKey(byte[] obj)
{
 if (nodeKeySlots.size() == 0) {
  return null;
 }
 long objHash = hashFn.hashBytes(obj).asLong();
 Long2ObjectSortedMap<String> subMap = nodeKeySlots.tailMap(objHash);
 if (subMap.isEmpty()) {
  return nodeKeySlots.long2ObjectEntrySet().first().getValue();
 }
 Long2ObjectMap.Entry<String> firstEntry = subMap.long2ObjectEntrySet().first();
 return firstEntry.getValue();
}

代码示例来源:origin: prestodb/presto

@Test
public void testZoneKeyData()
{
  Hasher hasher = Hashing.murmur3_128().newHasher();
  SortedSet<TimeZoneKey> timeZoneKeysSortedByKey = ImmutableSortedSet.copyOf(new Comparator<TimeZoneKey>()
  {
    @Override
    public int compare(TimeZoneKey left, TimeZoneKey right)
    {
      return Short.compare(left.getKey(), right.getKey());
    }
  }, TimeZoneKey.getTimeZoneKeys());
  for (TimeZoneKey timeZoneKey : timeZoneKeysSortedByKey) {
    hasher.putShort(timeZoneKey.getKey());
    hasher.putString(timeZoneKey.getId(), StandardCharsets.UTF_8);
  }
  // Zone file should not (normally) be changed, so let's make this more difficult
  assertEquals(hasher.hash().asLong(), -4582158485614614451L, "zone-index.properties file contents changed!");
}

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

.putBoolean(false)
  .putBoolean(false);
final long hashCode = hasher.hash().asLong();
  .putByte((byte) 0x00)
  .putByte((byte) 0x00);
assertEquals(hashCode, hasher.hash().asLong());
  .putChar((char) 0x0000)
  .putChar((char) 0x0000);
assertEquals(hashCode, hasher.hash().asLong());
assertEquals(hashCode, hasher.hash().asLong());
assertEquals(hashCode, hasher.hash().asLong());
  .putShort((short) 0x0000)
  .putShort((short) 0x0000);
assertEquals(hashCode, hasher.hash().asLong());

相关文章