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

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

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

HashCode.asInt介绍

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

代码示例

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

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

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

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

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

@VisibleForTesting
public static int hash(ObjectMapper jsonMapper, List<Object> objects) throws JsonProcessingException
{
 return hashFunction.hashBytes(jsonMapper.writeValueAsBytes(objects)).asInt();
}

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

/**
 * 对输入字符串进行murmur32散列, 返回值可能是负数
 */
public static int murmur32AsInt(@NotNull byte[] input) {
  return Hashing.murmur3_32(MURMUR_SEED).hashBytes(input).asInt();
}

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

/**
 * Returns a "Java hash code" for this {@code HashCode} instance; this is well-defined (so, for
 * example, you can safely put {@code HashCode} instances into a {@code HashSet}) but is otherwise
 * probably not what you want to use.
 */
@Override
public final int hashCode() {
 // If we have at least 4 bytes (32 bits), just take the first 4 bytes. Since this is
 // already a (presumably) high-quality hash code, any four bytes of it will do.
 if (bits() >= 32) {
  return asInt();
 }
 // If we have less than 4 bytes, use them all.
 byte[] bytes = getBytesInternal();
 int val = (bytes[0] & 0xFF);
 for (int i = 1; i < bytes.length; i++) {
  val |= ((bytes[i] & 0xFF) << (i * 8));
 }
 return val;
}

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

/**
 * 对输入字符串进行murmur32散列, 返回值可能是负数
 */
public static int murmur32AsInt(@NotNull String input) {
  return Hashing.murmur3_32(MURMUR_SEED).hashString(input, Charsets.UTF_8).asInt();
}

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

@Override
 public PartitionId partition(String key, List<PartitionId> partitions) {
  int hash = Math.abs(Hashing.murmur3_32().hashUnencodedChars(key).asInt());
  return partitions.get(Hashing.consistentHash(hash, partitions.size()));
 }
}

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

public DefaultRaftMember(MemberId id, Type type, Instant updated) {
 this.id = checkNotNull(id, "id cannot be null");
 this.hash = Hashing.murmur3_32()
   .hashUnencodedChars(id.id())
   .asInt();
 this.type = checkNotNull(type, "type cannot be null");
 this.updated = checkNotNull(updated, "updated cannot be null");
}

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

/**
 * Verifies that the crc of an array of byte data matches the expected value.
 *
 * @param expectedCrc the expected crc value.
 * @param data the data to run the checksum on.
 */
private static void assertCrc(int expectedCrc, byte[] data) {
 int actualCrc = Hashing.crc32c().hashBytes(data).asInt();
 assertEquals(expectedCrc, actualCrc);
}

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

private void onAccess(long key) {
 sample++;
 if (Math.floorMod(hasher.hashLong(key).asInt(), R) < 1) {
  for (WindowTinyLfuPolicy policy : minis) {
   policy.record(key);
  }
 }
}

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

public void testFromBytesNoCopy_noCopyOccurs() {
 byte[] bytes = new byte[] {(byte) 0xcd, (byte) 0xab, (byte) 0x00, (byte) 0x00};
 HashCode hashCode = HashCode.fromBytesNoCopy(bytes);
 assertEquals(0x0000abcd, hashCode.asInt());
 assertEquals("cdab0000", hashCode.toString());
 bytes[0] = (byte) 0x00;
 assertEquals(0x0000ab00, hashCode.asInt());
 assertEquals("00ab0000", hashCode.toString());
}

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

public void testFromBytes_copyOccurs() {
 byte[] bytes = new byte[] {(byte) 0xcd, (byte) 0xab, (byte) 0x00, (byte) 0x00};
 HashCode hashCode = HashCode.fromBytes(bytes);
 int expectedInt = 0x0000abcd;
 String expectedToString = "cdab0000";
 assertEquals(expectedInt, hashCode.asInt());
 assertEquals(expectedToString, hashCode.toString());
 bytes[0] = (byte) 0x00;
 assertEquals(expectedInt, hashCode.asInt());
 assertEquals(expectedToString, hashCode.toString());
}

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

public void testGetBytesInternal_noCloneOccurs() {
 byte[] bytes = new byte[] {(byte) 0xcd, (byte) 0xab, (byte) 0x00, (byte) 0x00};
 HashCode hashCode = HashCode.fromBytes(bytes);
 assertEquals(0x0000abcd, hashCode.asInt());
 assertEquals("cdab0000", hashCode.toString());
 hashCode.getBytesInternal()[0] = (byte) 0x00;
 assertEquals(0x0000ab00, hashCode.asInt());
 assertEquals("00ab0000", hashCode.toString());
}

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

private static void assertHash32(
   int expected, ImmutableSupplier<Checksum> supplier, String input) {
  byte[] bytes = HashTestUtils.ascii(input);
  String toString = "name";
  HashFunction func = new ChecksumHashFunction(supplier, 32, toString);
  assertEquals(expected, func.hashBytes(bytes).asInt());
  assertEquals(toString, func.toString());
 }
}

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

int hash1 = function.hashInt(key1).asInt();
int hash2 = function.hashInt(key2).asInt();

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

int hash1 = function.hashInt(key1).asInt();
int hash2 = function.hashInt(key2).asInt();
for (int k = 0; k < hashBits; k++) {
 if ((hash1 & (1 << k)) == (hash2 & (1 << k))) {

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

int hash1 = function.hashInt(key1).asInt();
int hash2 = function.hashInt(key2).asInt();
for (int k = 0; k < hashBits; k++) {
 if ((hash1 & (1 << k)) == (hash2 & (1 << k))) {

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

int coercedHash = Hashing.murmur3_32().hashLong(addressAsLong).asInt();

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

int hash1 = function.hashInt(key1).asInt();
int hash2 = function.hashInt(key2).asInt();

代码示例来源: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);
}

相关文章