Package org.infinispan.commons.util
Class BloomFilter<E>
- java.lang.Object
-
- org.infinispan.commons.util.BloomFilter<E>
-
- Direct Known Subclasses:
MurmurHash3BloomFilter
public class BloomFilter<E> extends Object
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addToFilter(E value)
Adds a value to the filter setting up to a number of bits equal to the number of hash functions.static <E> BloomFilter<E>
createConcurrentFilter(int bitsToUse, Iterable<ToIntFunction<? super E>> hashFunctions)
Same ascreateFilter(int, Iterable)
except the returned {code BloomFilter} instance may be used concurrently without additional synchronization.static <E> BloomFilter<E>
createFilter(int bitsToUse, Iterable<ToIntFunction<? super E>> hashFunctions)
IntSet
getIntSet()
boolean
possiblyPresent(E value)
Returnstrue
if the element might be present,false
if the value was for sure not present.void
setBits(IntSet intSet)
Clears all current bits and sets them to the values in the providedIntSet
.String
toString()
-
-
-
Method Detail
-
createFilter
public static <E> BloomFilter<E> createFilter(int bitsToUse, Iterable<ToIntFunction<? super E>> hashFunctions)
-
createConcurrentFilter
public static <E> BloomFilter<E> createConcurrentFilter(int bitsToUse, Iterable<ToIntFunction<? super E>> hashFunctions)
Same ascreateFilter(int, Iterable)
except the returned {code BloomFilter} instance may be used concurrently without additional synchronization.The provided function iterable must be able to be iterated upon concurrently.
- Type Parameters:
E
-- Parameters:
bitsToUse
-hashFunctions
-- Returns:
-
addToFilter
public boolean addToFilter(E value)
Adds a value to the filter setting up to a number of bits equal to the number of hash functions. This method will also return {code true} if any of the bits were updated, meaning this value was for sure not present before.- Parameters:
value
- the value to add to the filter- Returns:
- whether the filter was actually updated
-
possiblyPresent
public boolean possiblyPresent(E value)
Returnstrue
if the element might be present,false
if the value was for sure not present.- Parameters:
value
- the value to check for- Returns:
- whether this value may be present or for sure not
-
setBits
public void setBits(IntSet intSet)
Clears all current bits and sets them to the values in the providedIntSet
. Since this method clears and sets the values any other concurrent operations may be ignored.- Parameters:
intSet
-
-
getIntSet
public IntSet getIntSet()
-
-