Refine search
public StatisticsHasher putOptionalLong(boolean present, long value) { hasher.putBoolean(present); hasher.putLong(present ? value : 0); return this; }
public StatisticsHasher putOptionalInt(boolean present, int value) { hasher.putBoolean(present); hasher.putInt(present ? value : 0); return this; }
public void putRowKeyToHLLOld(String[] row) { //generate hash for each row key column byte[][] rowHashCodes = new byte[nRowKey][]; for (int i = 0; i < nRowKey; i++) { Hasher hc = hf.newHasher(); String colValue = row[i]; if (colValue != null) { rowHashCodes[i] = hc.putString(colValue).hash().asBytes(); } else { rowHashCodes[i] = hc.putInt(0).hash().asBytes(); } } // use the row key column hash to get a consolidated hash for each cuboid for (int i = 0; i < cuboidIds.length; i++) { Hasher hc = hf.newHasher(); for (int position = 0; position < allCuboidsBitSet[i].length; position++) { hc.putBytes(rowHashCodes[allCuboidsBitSet[i][position]]); } allCuboidsHLL[i].add(hc.hash().asBytes()); } }
private static void assertHashBytesEquivalence(HashFunction hashFunction, Random random) { int size = random.nextInt(2048); byte[] bytes = new byte[size]; random.nextBytes(bytes); assertEquals( hashFunction.hashBytes(bytes), hashFunction.newHasher(size).putBytes(bytes).hash()); int off = random.nextInt(size); int len = random.nextInt(size - off); assertEquals( hashFunction.hashBytes(bytes, off, len), hashFunction.newHasher(size).putBytes(bytes, off, len).hash()); }
public void testPutAfterHash() { Hasher sha1 = Hashing.sha1().newHasher(); assertEquals( "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12", sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8) .hash() .toString()); try { sha1.putInt(42); fail(); } catch (IllegalStateException expected) { } }
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) { } }
@Override public byte[] hash(byte[] input, int seed) { Hasher hasher = murmur3_128(seed).newHasher(); Funnels.byteArrayFunnel().funnel(input, hasher); return hasher.hash().asBytes(); } };
public void testEmptyInputs_mixedAlgorithms() throws Exception { String knownOutput = "8cbf764cbe2e4623d99a41354adfd390"; Mac mac = Mac.getInstance("HmacMD5"); mac.init(SHA1_KEY); assertEquals(knownOutput, HashCode.fromBytes(mac.doFinal()).toString()); assertEquals(knownOutput, Hashing.hmacMd5(SHA1_KEY).newHasher().hash().toString()); }
public ServiceInfo( String name, boolean rootService, String rootType, String containerType, String collectionName, String itemType, List<String> patterns, List<String> collections ) { this.name = name; this.rootService = rootService; this.rootType = rootType; this.containerType = containerType; this.collectionName = collectionName; this.itemType = itemType; this.patterns = patterns; this.collections = collections; Hasher hasher = Hashing.md5().newHasher(); for ( String pattern : patterns ) { hasher.putString( pattern, UTF_8 ); } hashCode = hasher.hash().asInt(); }
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()); }
hashFunction.hashUnencodedChars("abc"), hashFunction.newHasher().putUnencodedChars("abc").hash(), hashFunction.newHasher().putUnencodedChars("ab").putUnencodedChars("c").hash(), hashFunction.newHasher().putUnencodedChars("a").putUnencodedChars("bc").hash(), hashFunction .newHasher() .putUnencodedChars("a") .putUnencodedChars("b") .putUnencodedChars("c") .hash(), hashFunction.newHasher().putChar('a').putUnencodedChars("bc").hash(), hashFunction.newHasher().putUnencodedChars("ab").putChar('c').hash(), hashFunction.newHasher().putChar('a').putChar('b').putChar('c').hash()) .testEquals(); assertEquals( hashFunction.hashUnencodedChars(string), hashFunction.newHasher().putUnencodedChars(string).hash()); for (Charset charset : CHARSETS) { assertEquals( hashFunction.hashString(string, charset), hashFunction.newHasher().putString(string, charset).hash());
public void testInvalidUnicodeHasherPutString() { String str = new String( new char[] {'a', Character.MIN_HIGH_SURROGATE, Character.MIN_HIGH_SURROGATE, 'z'}); assertEquals( murmur3_32().hashBytes(str.getBytes(Charsets.UTF_8)), murmur3_32().newHasher().putString(str, Charsets.UTF_8).hash()); } }
.putBoolean(true) .putBoolean(true) .putBoolean(false) .putBoolean(true) .putBoolean(false) .putBoolean(false) .putBoolean(false) .putBoolean(false); final long hashCode = hasher.hash().asLong(); hasher = HASH_FN.newHasher(); hasher .putByte((byte) 0x01) .putByte((byte) 0x01) .putByte((byte) 0x00) .putByte((byte) 0x01) .putByte((byte) 0x00) .putByte((byte) 0x00) .putByte((byte) 0x00) .putByte((byte) 0x00); assertEquals(hashCode, hasher.hash().asLong()); hasher = HASH_FN.newHasher(); hasher .putChar((char) 0x0101) .putChar((char) 0x0100) .putChar((char) 0x0000) .putChar((char) 0x0000); assertEquals(hashCode, hasher.hash().asLong());
@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!"); }