@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()); } }
@Override public LongStream events() throws IOException { return lines() .map(this::parseRequest) .filter(Objects::nonNull) .mapToLong(path -> Hashing.murmur3_128().hashUnencodedChars(path).asLong()); }
public void testStringsConsistency() { for (String s : Arrays.asList("", "some", "test", "strings", "to", "try")) { assertEquals(HASH_FN.newHasher().putUnencodedChars(s).hash(), HASH_FN.hashUnencodedChars(s)); } }
@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())); } }
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"); }
partitions.stream() .filter(partition -> !result.contains(partition)) .map(partition -> immutableEntry(partition, hashFunction.hashUnencodedChars(partition.getPartitionId()).asLong())) .sorted(hashComparator) .limit(samplesLeft)
public SocketAddress get(String key, RoutingContext rContext) { long hash = hashFunction.hashUnencodedChars(key).asLong(); return find(hash, rContext); }
private Long replicaHash(int shardId, int replica, String address) { return hashFunction.hashUnencodedChars(replicaName(shardId, replica, address)).asLong(); }
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")); }
String s = streams.next(); if (null == streamRegex || s.matches(streamRegex)) { if (Math.abs(hashFunction.hashUnencodedChars(s).asInt()) % totalInstances == instanceId) { newSet.add(s);
/** * This verifies that putUnencodedChars(String) and hashUnencodedChars(String) are equivalent, * even for funny strings composed by (possibly unmatched, and mostly illegal) surrogate * characters. (But doesn't test that they do the right thing - just their consistency). */ private static void assertHashStringWithSurrogatesEquivalence( HashFunction hashFunction, Random random) { int size = random.nextInt(8) + 1; char[] chars = new char[size]; for (int i = 0; i < chars.length; i++) { chars[i] = random.nextBoolean() ? randomLowSurrogate(random) : randomHighSurrogate(random); } String string = new String(chars); assertEquals( hashFunction.hashUnencodedChars(string), hashFunction.newHasher().putUnencodedChars(string).hash()); }
synchronized (hostSet) { if (0 != hostList.size()) { int hashCode = hasher.hashUnencodedChars(key).asInt(); int hostId = signSafeMod(hashCode, hostList.size()); address = hostList.get(hostId);
public void testUtf8() { char[] charsA = new char[128]; char[] charsB = new char[128]; for (int i = 0; i < charsA.length; i++) { if (i < 100) { charsA[i] = 'a'; charsB[i] = 'a'; } else { // Both two-byte characters, but must be different charsA[i] = (char) (0x0180 + i); charsB[i] = (char) (0x0280 + i); } } String stringA = new String(charsA); String stringB = new String(charsB); assertThat(stringA).isNotEqualTo(stringB); assertThat(HASH_FN.hashUnencodedChars(stringA)) .isNotEqualTo(HASH_FN.hashUnencodedChars(stringB)); assertThat(fingerprint(stringA.getBytes(UTF_8))) .isNotEqualTo(fingerprint(stringB.getBytes(UTF_8))); // ISO 8859-1 only has 0-255 (ubyte) representation so throws away UTF-8 characters // greater than 127 (ie with their top bit set). // Don't attempt to do this in real code. assertEquals( fingerprint(stringA.getBytes(ISO_8859_1)), fingerprint(stringB.getBytes(ISO_8859_1))); }
@Override public void hashValues(DimensionSelector dimSelector, HyperLogLogCollector collector) { IndexedInts row = dimSelector.getRow(); for (int i = 0, rowSize = row.size(); i < rowSize; i++) { int index = row.get(i); final String value = dimSelector.lookupName(index); // SQL standard spec does not count null values, // Skip counting null values when we are not replacing null with default value. // A special value for null in case null handling is configured to use empty string for null. if (NullHandling.replaceWithDefault() || value != null) { collector.add(CardinalityAggregator.hashFn.hashUnencodedChars(nullToSpecial(value)).asBytes()); } } }
hashFunction.hashUnencodedChars("abc"), hashFunction.newHasher().putUnencodedChars("abc").hash(), hashFunction.newHasher().putUnencodedChars("ab").putUnencodedChars("c").hash(), String string = new String(bytes, Charsets.US_ASCII); assertEquals( hashFunction.hashUnencodedChars(string), hashFunction.newHasher().putUnencodedChars(string).hash()); for (Charset charset : CHARSETS) {
public Long evaluate(String str) { HashCode hc = hash.hashUnencodedChars(str); return hc.asLong(); } }
protected byte[] getHash() { return Hashing.murmur3_128().hashUnencodedChars(builder).asBytes(); } }
public int uniquePageLineCount() { Set<Long> hashes = new HashSet<>(100000); for (WebDocument page : pages) { for (String line : page.lines) { hashes.add(Hashing.murmur3_128().hashUnencodedChars(line).asLong()); } } return hashes.size(); }
private long contentHash() { String contentNoSpaces = String.join(" ", lines).replaceAll("\\s+", ""); return com.google.common.hash.Hashing.murmur3_128().hashUnencodedChars(contentNoSpaces) .asLong(); }
static public double EstimatedReach(String lastItem, int maxItems) { long maxHash = HASH.hashUnencodedChars(lastItem).asLong(); return EstimatedReach(maxHash, maxItems); }