List of usage examples for com.google.common.hash Hashing goodFastHash
public static HashFunction goodFastHash(int minimumBits)
From source file:org.apache.niolex.common.guava.GuavaHashing.java
/** * @param args//from w ww . ja va 2 s . c o m */ public static void main(String[] args) { // Common Hash HashFunction hf = Hashing.goodFastHash(32); HashCode code = hf.hashObject(new Person(1, "Jiyun", "Xie", 1984), PersonFunnel.INSTANCE); System.out.println("Code1 => " + code.asInt()); code = hf.hashObject(new Person(1, "Jiyun", "Xie", 1985), PersonFunnel.INSTANCE); System.out.println("Code2 => " + code.asInt()); // Consistent Hashing HashFunction hf2 = Hashing.goodFastHash(64); code = hf2.hashObject(new Person(1, "Jiyun", "Xie", 1984), PersonFunnel.INSTANCE); System.out.println("Code3 => " + code.asLong()); long hash = code.asLong(); int bucket = Hashing.consistentHash(code, 100); System.out.println("Bucket1 => " + bucket); bucket = Hashing.consistentHash(hash, 101); System.out.println("Bucket2 => " + bucket); for (int i = 0; i < 10; ++i) { System.out.println("HashTo5 => " + Hashing.consistentHash(i, 5)); System.out.println("HashTo6 => " + Hashing.consistentHash(i, 6)); } // BloomFilter BloomFilter<Person> friends = BloomFilter.create(PersonFunnel.INSTANCE, 500, 0.02); for (int i = 0; i < 500; ++i) { friends.put(new Person(i, "Jiyun", "Xie", 1984 + i)); } int k = 0; for (int i = 0; i < 500; ++i) { if (!friends.mightContain(new Person(i, "Jiyun", "Xie", 1984 + i))) { System.out.println("Error1 => " + i); ++k; } } System.out.println("fnp => (should be 0)" + ((double) k / 500)); k = 0; for (int i = 0; i < 1000; i += 2) { if (friends.mightContain(new Person(i, "Jiyun", "Xie", 1984 + i))) { //System.out.println("Error2 => " + i); ++k; } } System.out.println("fpp => " + ((double) k / 500)); }
From source file:org.apache.streams.util.GuidUtils.java
/** * generateGuid from list of parts./* ww w. j a v a 2 s . c om*/ * @param parts list of parts * @return guid */ public static String generateGuid(String... parts) { StringBuilder seed = new StringBuilder(); for (String part : parts) { Objects.requireNonNull(part); if (StringUtils.isNotBlank(part)) { seed.append(part); } } return Arrays.toString(Hashing.goodFastHash(24).hashString(seed, UTF8_CHARSET).asBytes()); }
From source file:com.wadpam.guja.oauth2.provider.DefaultTokenGenerator.java
@Override public String generate() { byte[] randomBytes = new byte[24]; random.nextBytes(randomBytes);// ww w .ja v a2s. c o m HashCode hashCode = Hashing.goodFastHash(256).newHasher().putBytes(randomBytes).putLong(System.nanoTime()) .hash(); return BaseEncoding.base64Url().omitPadding().encode(hashCode.asBytes()); }
From source file:com.example.cachedmodel.BaseArrayAdapter.java
public BaseArrayAdapter() { mHashFunction = Hashing.goodFastHash(Long.SIZE); }
From source file:com.android.tools.idea.run.ApkUploaderService.java
/** Returns true if the apk was uploaded to the device, and false if it was already present on the device. */ public boolean uploadApk(@NotNull IDevice device, @NotNull String localPath, @NotNull String remotePath) throws AdbCommandRejectedException, IOException, TimeoutException, SyncException { HashCode hash = Files.hash(new File(localPath), Hashing.goodFastHash(32)); String serial = device.getSerialNumber(); Map<String, HashCode> cache = myCache.get(serial); if (cache != null) { HashCode got = cache.get(remotePath); if (hash.equals(got)) { return false; } else {/* www.j a v a 2s . co m*/ // Remove it in case there is an error uploading the apk. cache.remove(remotePath); } } else { cache = Maps.newHashMap(); myCache.put(serial, cache); } device.pushFile(localPath, remotePath); cache.put(remotePath, hash); return true; }
From source file:models.RandomProjection.java
public static double deterministicRandom(String value) { // obtain a hash function that will generate a 32-bit long hash code HashFunction hf = Hashing.goodFastHash(32); long i = Hashing.padToLong(hf.hashString(value)); return 1.0 * i / MAX_HASH_VALUE; }
From source file:com.torodb.kvdocument.values.KvArray.java
@Override public int hashCode() { return Hashing.goodFastHash(32).newHasher().putInt(size()).putInt(getElementType().hashCode()).hash() .asInt(); }
From source file:com.android.tools.idea.run.InstalledApkCache.java
@NotNull private static HashCode hash(@NotNull File apk) throws IOException { return Files.hash(apk, Hashing.goodFastHash(32)); }
From source file:com.torodb.kvdocument.values.KvBinary.java
@Override public int hashCode() { return Hashing.goodFastHash(32).newHasher().putInt(getSubtype().hashCode()).putLong(size()).hash().asInt(); }
From source file:com.torodb.torod.core.subdocument.values.ScalarArray.java
/** * @return/*from www.ja v a 2 s .c o m*/ * {@linkplain Hashing#goodFastHash(int) Hashing.goodFastHash(32).newHasher().putInt(size()).putInt(getElementType().hashCode()).hash().asInt();} */ @Override public int hashCode() { return Hashing.goodFastHash(32).hashInt(size()).asInt(); }