stream-lib icon indicating copy to clipboard operation
stream-lib copied to clipboard

BloomFilter doesn't work when amount of bits > 2^32

Open ajtkulov opened this issue 4 years ago • 4 comments

In my live case, we need BloomFilter for a bigger amount (about 4-5Gb ram, >32B bits)

The code is dependent on java.util.BitSet with .ctor

public BitSet(int nbits) with a lot of getter/setter by int index.

ajtkulov avatar May 07 '20 20:05 ajtkulov

Can you partition your data in some way so that you can than use a list of n smaller BloomFilters to hold each chunk of data?

abramsm avatar May 08 '20 20:05 abramsm

it would work, but as a drawback, you have to query each chunk for contains method. So, complexity increases by N (chunk amount). Add method also becomes more sophisticated.

Actually, I have a "solution" (I'm not a java native, so excuse me in advance). There is a fork, there is a lot of copy-paste code: own BitSet with long type and BloomFilter hierarchy. https://github.com/ajtkulov/stream-lib It works, but I'm not sure that this is idiomatic for java and enough for PR.

ajtkulov avatar May 08 '20 22:05 ajtkulov

why complexity increase by N chunks? you need partition your data by hash, index_of_bloom = long_hash % number_of_chunks, complexity is same, memory complexity is num_chunks * bloomfilter_memory

vitusya avatar May 09 '20 15:05 vitusya

@vitusya agree, thank you, it's much much easier.

The only theoretical issue is that (in case you build Bloom from dynamic data) some malicious person could generate items related to the same bucket. But it's related to all hashes structures, and it's a theory, not a practical thing.

ajtkulov avatar May 09 '20 17:05 ajtkulov