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

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

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

HashCode.fromInt介绍

[英]Creates a 32-bit HashCode representation of the given int value. The underlying bytes are interpreted in little endian order.
[中]创建给定int值的32位哈希代码表示形式。底层字节以小的尾数顺序进行解释。

代码示例

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

private static HashCode fmix(int h1, int length) {
 h1 ^= length;
 h1 ^= h1 >>> 16;
 h1 *= 0x85ebca6b;
 h1 ^= h1 >>> 13;
 h1 *= 0xc2b2ae35;
 h1 ^= h1 >>> 16;
 return HashCode.fromInt(h1);
}

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

@Override
 public HashCode hash() {
  return HashCode.fromInt(crc);
 }
}

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

private static HashCode fmix(int h1, int length) {
 h1 ^= length;
 h1 ^= h1 >>> 16;
 h1 *= 0x85ebca6b;
 h1 ^= h1 >>> 13;
 h1 *= 0xc2b2ae35;
 h1 ^= h1 >>> 16;
 return HashCode.fromInt(h1);
}

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

@Override
 public HashCode hash() {
  return HashCode.fromInt(crc);
 }
}

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

@Override
 public HashCode hash() {
  return HashCode.fromInt(crc);
 }
}

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

private static HashCode fmix(int h1, int length) {
 h1 ^= length;
 h1 ^= h1 >>> 16;
 h1 *= 0x85ebca6b;
 h1 ^= h1 >>> 13;
 h1 *= 0xc2b2ae35;
 h1 ^= h1 >>> 16;
 return HashCode.fromInt(h1);
}

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

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

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

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

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

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

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

public void testFromInt() {
 for (ExpectedHashCode expected : expectedHashCodes) {
  if (expected.bytes.length == 4) {
   HashCode fromInt = HashCode.fromInt(expected.asInt);
   assertExpectedHashCode(expected, fromInt);
  }
 }
}

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

public void testIntWriteBytesTo() {
 byte[] dest = new byte[4];
 HashCode.fromInt(42).writeBytesTo(dest, 0, 4);
 assertTrue(Arrays.equals(HashCode.fromInt(42).asBytes(), dest));
}

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

private static void assertHash(int expected, HashCode actual) {
 assertEquals(HashCode.fromInt(expected), actual);
}

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

public void testCombineUnordered() {
 HashCode hash31 = HashCode.fromInt(31);
 HashCode hash32 = HashCode.fromInt(32);
 assertEquals(hash32, Hashing.combineUnordered(ImmutableList.of(hash32)));
 assertEquals(HashCode.fromInt(64), Hashing.combineUnordered(ImmutableList.of(hash32, hash32)));
 assertEquals(
   HashCode.fromInt(96), Hashing.combineUnordered(ImmutableList.of(hash32, hash32, hash32)));
 assertEquals(
   Hashing.combineUnordered(ImmutableList.of(hash31, hash32)),
   Hashing.combineUnordered(ImmutableList.of(hash32, hash31)));
}

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

public void testObjectHashCode() {
 HashCode hashCode42 = HashCode.fromInt(42);
 assertEquals(42, hashCode42.hashCode());
}

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

public void testCombineUnordered_differentBitLengths() {
 try {
  HashCode unused =
    Hashing.combineUnordered(ImmutableList.of(HashCode.fromInt(32), HashCode.fromLong(32L)));
  fail();
 } catch (IllegalArgumentException expected) {
 }
}

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

public void testCombineOrdered_differentBitLengths() {
 try {
  HashCode unused =
    Hashing.combineOrdered(ImmutableList.of(HashCode.fromInt(32), HashCode.fromLong(32L)));
  fail();
 } catch (IllegalArgumentException expected) {
 }
}

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

public void testCombineOrdered() {
 HashCode hash31 = HashCode.fromInt(31);
 HashCode hash32 = HashCode.fromInt(32);
 assertEquals(hash32, Hashing.combineOrdered(ImmutableList.of(hash32)));
 assertEquals(
   HashCode.fromBytes(new byte[] {(byte) 0x80, 0, 0, 0}),
   Hashing.combineOrdered(ImmutableList.of(hash32, hash32)));
 assertEquals(
   HashCode.fromBytes(new byte[] {(byte) 0xa0, 0, 0, 0}),
   Hashing.combineOrdered(ImmutableList.of(hash32, hash32, hash32)));
 assertFalse(
   Hashing.combineOrdered(ImmutableList.of(hash31, hash32))
     .equals(Hashing.combineOrdered(ImmutableList.of(hash32, hash31))));
}

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

public PackageSanityTests() {
  setDefault(LockFreeBitArray.class, new LockFreeBitArray(1));
  setDefault(HashCode.class, HashCode.fromInt(1));
  setDefault(String.class, "MD5");
  setDefault(int.class, 32);
 }
}

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

public void testConsistentHash_ofHashCode() {
 checkSameResult(HashCode.fromLong(1), 1);
 checkSameResult(HashCode.fromLong(0x9999999999999999L), 0x9999999999999999L);
 checkSameResult(HashCode.fromInt(0x99999999), 0x0000000099999999L);
}

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

相关文章