Codota Logo
com.google.common.hash
Code IndexAdd Codota to your IDE (free)

How to use com.google.common.hash

Best Java code snippets using com.google.common.hash (Showing top 20 results out of 5,067)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Connection c =
  • Codota IconDataSource dataSource;dataSource.getConnection()
  • Codota IconString url;DriverManager.getConnection(url)
  • Codota IconIdentityDatabaseUtil.getDBConnection()
  • Smart code suggestions by Codota
}
origin: google/guava

 @Override
 public byte[] hash(byte[] input, int seed) {
  Hasher hasher = murmur3_32(seed).newHasher();
  Funnels.byteArrayFunnel().funnel(input, hasher);
  return hasher.hash().asBytes();
 }
};
origin: google/guava

@AndroidIncompatible // slow TODO(cpovirk): Maybe just reduce iterations under Android.
public void testGoodFastHash() {
 for (int i = 1; i < 200; i += 17) {
  HashFunction hasher = Hashing.goodFastHash(i);
  assertTrue(hasher.bits() >= i);
  HashTestUtils.assertInvariants(hasher);
 }
}
origin: google/guava

 @Override
 public byte[] hash(byte[] input, int seed) {
  Hasher hasher = murmur3_128(seed).newHasher();
  Funnels.byteArrayFunnel().funnel(input, hasher);
  return hasher.hash().asBytes();
 }
};
origin: google/guava

public void testHashTwice() {
 Hasher hasher = Hashing.hmacMd5(MD5_KEY).newHasher();
 assertEquals(
   "9753980fe94daa8ecaa82216519393a9",
   hasher.putString("The quick brown fox jumps over the lazy dog", UTF_8).hash().toString());
 try {
  hasher.hash();
  fail();
 } catch (IllegalStateException expected) {
 }
}
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 assertHash(int seed, long expected1, long expected2, String stringInput) {
 HashCode expected = toHashCode(expected1, expected2);
 byte[] input = HashTestUtils.ascii(stringInput);
 assertEquals(expected, murmur3_128(seed).hashBytes(input));
 assertEquals(expected, murmur3_128(seed).newHasher().putBytes(input).hash());
}
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 testHashIntVsForLoop() {
 int input = 42;
 HashCode expected = Hashing.md5().hashInt(input);
 Hasher hasher = Hashing.md5().newHasher();
 for (int i = 0; i < 32; i += 8) {
  hasher.putByte((byte) (input >> i));
 }
 HashCode actual = hasher.hash();
 assertEquals(expected, actual);
}
origin: google/guava

public void testRoundTripHashCodeUsingFromString() {
 HashCode hash1 = Hashing.sha1().hashString("foo", Charsets.US_ASCII);
 HashCode hash2 = HashCode.fromString(hash1.toString());
 assertEquals(hash1, hash2);
}
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

public void testHash_hashesCorrectly() throws Exception {
 HashCode expectedHash = Hashing.md5().hashBytes(testBytes);
 HashingInputStream in = new HashingInputStream(Hashing.md5(), buffer);
 byte[] buf = new byte[4];
 int numOfByteRead = in.read(buf, 0, buf.length);
 assertEquals(4, numOfByteRead);
 assertEquals(expectedHash, in.hash());
}
origin: google/guava

public void testHash_hashesCorrectly() throws Exception {
 byte[] buf = new byte[] {'y', 'a', 'm', 's'};
 HashCode expectedHash = Hashing.md5().hashBytes(buf);
 HashingOutputStream out = new HashingOutputStream(Hashing.md5(), buffer);
 out.write(buf);
 assertEquals(expectedHash, out.hash());
}
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: 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 testKnownStringInputs() {
 assertHash(0, murmur3_32().hashUnencodedChars(""));
 assertHash(679745764, murmur3_32().hashUnencodedChars("k"));
 assertHash(1510782915, murmur3_32().hashUnencodedChars("hell"));
 assertHash(-675079799, murmur3_32().hashUnencodedChars("hello"));
 assertHash(1935035788, murmur3_32().hashUnencodedChars("http://www.google.com/"));
 assertHash(
   -528633700, murmur3_32().hashUnencodedChars("The quick brown fox jumps over the lazy dog"));
}
origin: google/guava

public void testPutAllWithSelf() {
 BloomFilter<Integer> bf1 = BloomFilter.create(Funnels.integerFunnel(), 1);
 try {
  assertFalse(bf1.isCompatible(bf1));
  bf1.putAll(bf1);
  fail();
 } catch (IllegalArgumentException expected) {
 }
}
origin: google/guava

public void testFailureWhenMoreThan255HashFunctionsAreNeeded() {
 try {
  int n = 1000;
  double p = 0.00000000000000000000000000000000000000000000000000000000000000000000000000000001;
  BloomFilter.create(Funnels.unencodedCharsFunnel(), n, p);
  fail();
 } catch (IllegalArgumentException expected) {
 }
}
origin: google/guava

public void testPutAfterHash() {
 Hasher hasher = Hashing.hmacMd5(MD5_KEY).newHasher();
 assertEquals(
   "9753980fe94daa8ecaa82216519393a9",
   hasher.putString("The quick brown fox jumps over the lazy dog", UTF_8).hash().toString());
 try {
  hasher.putInt(42);
  fail();
 } catch (IllegalStateException expected) {
 }
}
origin: google/guava

public void testHash_hashesCorrectlyReadOutOfBound() throws Exception {
 HashCode expectedHash = Hashing.md5().hashBytes(testBytes);
 HashingInputStream in = new HashingInputStream(Hashing.md5(), buffer);
 byte[] buf = new byte[100];
 int numOfByteRead = in.read(buf, 0, buf.length);
 assertEquals(-1, in.read()); // additional read
 assertEquals(4, numOfByteRead);
 assertEquals(expectedHash, in.hash());
}
origin: google/guava

public void testHash_hashesCorrectlyForSkipping() throws Exception {
 HashCode expectedHash = Hashing.md5().hashBytes(new byte[] {'m', 's'});
 HashingInputStream in = new HashingInputStream(Hashing.md5(), buffer);
 long numOfByteSkipped = in.skip(2);
 assertEquals(2, numOfByteSkipped);
 byte[] buf = new byte[4];
 int numOfByteRead = in.read(buf, 0, buf.length);
 assertEquals(2, numOfByteRead);
 assertEquals(expectedHash, in.hash());
}
com.google.common.hash

Most used classes

  • HashCode
  • HashFunction
  • Hashing
  • Hasher
    A PrimitiveSink that can compute a hash code after reading the input. Each hasher should translate a
  • BloomFilter
    A Bloom filter for instances of T. A Bloom filter offers an approximate containment test with one-si
  • PrimitiveSink,
  • Funnel,
  • MessageDigestHashFunction,
  • AbstractCompositeHashFunction,
  • AbstractHasher,
  • AbstractNonStreamingHashFunction$BufferingHasher,
  • AbstractNonStreamingHashFunction$ExposedByteArrayOutputStream,
  • AbstractNonStreamingHashFunction,
  • BloomFilter$SerialForm,
  • ChecksumHashFunction,
  • Hashing$ConcatenatedHashFunction,
  • HashingInputStream,
  • MessageDigestHashFunction$MessageDigestHasher,
  • Murmur3_128HashFunction$Murmur3_128Hasher
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now