java - Logic of code Guava's mightContain -


i going through code of guava library, interested understand probabilistic match code of mightcontain. 1 explain doing in code specially bit wise operator. here code....

public <t> boolean mightcontain(t object, funnel<? super t> funnel,         int numhashfunctions, bitarray bits) {       long hash64 = hashing.murmur3_128().newhasher().putobject(object, funnel).hash().aslong();       int hash1 = (int) hash64;       int hash2 = (int) (hash64 >>> 32);       (int = 1; <= numhashfunctions; i++) {         int nexthash = hash1 + * hash2;         if (nexthash < 0) {           nexthash = ~nexthash;         }         // here, code identical previous method         if (!bits.get(nexthash % bits.size())) {           return false;         } 

assuming code bloomfilter class, logic goes this:

given key, perform of chosen hashes on key. use each hash pick bit number , check if bit set. if bits not set in filter @ position key cannot have been added.

if of bits found set can filter might have had key added. because possible different key (or combination of number of different keys) result in of checked bits being set.

note adding of key filter same function except **set**s of bits generated.

a bloom filter object operates follows.

  1. a number of hash functions chosen, each calculate location of bit in filter. (see optimal number of hash functions discussion on how many).
  2. hold arbitrary length bit pattern - length unimportant should big enough (see probability of false positives discussion on big enough means).
  3. each time key added filter, configured hash functions performed on key resulting in number of bits being set in pattern.
  4. to check if key has been added, perform of hash functions , check bit found there. if found 0 key certainly has not been added filter.
  5. if bits found set then may be key has been added. need perform further checks confirm.

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -