List of usage examples for com.google.common.hash HashCode asLong
@CheckReturnValue public abstract long asLong();
From source file:org.apache.niolex.common.guava.GuavaHashing.java
/** * @param args//from w ww . jav a 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.janusgraph.diskstorage.util.HashingUtil.java
public static final StaticBuffer hashPrefixKey(final HashLength hashPrefixLen, final StaticBuffer key) { final int prefixLen = hashPrefixLen.length(); final StaticBuffer.Factory<HashCode> hashFactory; switch (hashPrefixLen) { case SHORT:/*w w w .j av a2 s . com*/ hashFactory = SHORT_HASH_FACTORY; break; case LONG: hashFactory = LONG_HASH_FACTORY; break; default: throw new IllegalArgumentException("Unknown hash prefix: " + hashPrefixLen); } HashCode hashcode = key.as(hashFactory); WriteByteBuffer newKey = new WriteByteBuffer(prefixLen + key.length()); assert prefixLen == 4 || prefixLen == 8; if (prefixLen == 4) newKey.putInt(hashcode.asInt()); else newKey.putLong(hashcode.asLong()); newKey.putBytes(key); return newKey.getStaticBuffer(); }
From source file:edu.umd.marbl.mhap.sketch.HashUtils.java
public final static long[][] computeNGramHashesExact(final String seq, final int nGramSize, final int numWords, final int seed) { HashFunction hf = Hashing.murmur3_128(seed); long[][] hashes = new long[seq.length() - nGramSize + 1][numWords]; for (int iter = 0; iter < hashes.length; iter++) { String subStr = seq.substring(iter, iter + nGramSize); for (int word = 0; word < numWords; word++) { HashCode hc = hf.newHasher().putUnencodedChars(subStr).putInt(word).hash(); hashes[iter][word] = hc.asLong(); }/*from w w w. j a v a 2 s. co m*/ } return hashes; }
From source file:edu.umd.marbl.mhap.sketch.HashUtils.java
public final static long[] computeSequenceHashesLong(final String seq, final int nGramSize, final int seed) { HashFunction hf = Hashing.murmur3_128(seed); long[] hashes = new long[seq.length() - nGramSize + 1]; for (int iter = 0; iter < hashes.length; iter++) { HashCode hc = hf.newHasher().putUnencodedChars(seq.substring(iter, iter + nGramSize)).hash(); hashes[iter] = hc.asLong(); }// w w w .ja v a 2 s . co m return hashes; }
From source file:edu.umd.marbl.mhap.utils.Utils.java
public final static long[] computeSequenceHashesLongValidKmers(final String seq, final int kmerSize, final int seed) { HashFunction hf = Hashing.murmur3_128(seed); long[] hashes = new long[seq.length() - kmerSize + 1]; for (int iter = 0; iter < hashes.length; iter++) { String subSeq = seq.substring(iter, iter + kmerSize); long hashYGS; hashes[iter] = Long.MAX_VALUE; if (!subSeq.contains("N")) { hashYGS = computeHashYGS(subSeq); //if(MhapMain.getValidKmersHashes().get(hashYGS)) //Bernardo if (MhapMain.getValidKmersHashes().fastGet(hashYGS)) { HashCode hc = hf.newHasher().putUnencodedChars(subSeq).hash(); hashes[iter] = hc.asLong(); }//from w w w .jav a 2s .c o m } } return hashes; }
From source file:edu.umd.marbl.mhap.utils.Utils.java
public final static long[][] computeKmerHashesExact(final String seq, final int kmerSize, final int numWords, final int seed) { HashFunction hf = Hashing.murmur3_128(seed); long[][] hashes = new long[seq.length() - kmerSize + 1][numWords]; for (int iter = 0; iter < hashes.length; iter++) { String subStr = seq.substring(iter, iter + kmerSize); for (int word = 0; word < numWords; word++) { HashCode hc = hf.newHasher().putUnencodedChars(subStr).putInt(word).hash(); hashes[iter][word] = hc.asLong(); }/* ww w. j av a 2 s . c o m*/ } return hashes; }
From source file:edu.umd.marbl.mhap.utils.Utils.java
public final static long[] computeSequenceHashesLong(final String seq, final int kmerSize, final int seed) { HashFunction hf = Hashing.murmur3_128(seed); long[] hashes = new long[seq.length() - kmerSize + 1]; for (int iter = 0; iter < hashes.length; iter++) { HashCode hc = hf.newHasher().putUnencodedChars(seq.substring(iter, iter + kmerSize)).hash(); hashes[iter] = hc.asLong(); }/* w w w .j a va2 s .c om*/ return hashes; }
From source file:poke.server.hash.MurmurHash128.java
public Long hash(String value) { HashFunction hf = Hashing.murmur3_128(seed); HashCode hc = hf.newHasher().putString(value, Charsets.UTF_8).hash(); return new Long(hc.asLong()); }
From source file:com.facebook.util.digest.MurmurHash.java
public long hashToLong(byte[] data) { HashCode hashCode = byteArrayHasher.hashBytes(data); return hashCode.asLong(); }
From source file:brickhouse.analytics.uniques.SketchSet.java
public void addItem(String str) { HashCode hc = HASH.hashUnencodedChars(str); this.addHashItem(hc.asLong(), str); }