Class BloomFilter
java.lang.Object
org.infinispan.server.resp.commands.bloom.BloomFilter
A Bloom filter implementation compatible with Redis BF commands.
Supports:
- Configurable error rate and capacity
- Scaling with multiple sub-filters
- Non-scaling mode
- Since:
- 16.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA sub-filter in a scalable Bloom filter. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longstatic final doubleDefault values used when creating a filter with BF.ADD without BF.RESERVE.static final int -
Constructor Summary
ConstructorsConstructorDescriptionBloomFilter(double errorRate, long capacity, int expansion, boolean nonScaling) -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(byte[] item) Adds an item to the Bloom filter.longdoubleintintReturns the number of sub-filters.longlonggetSize()Returns the total size in bytes.longReturns the total capacity across all sub-filters.booleanbooleanmightContain(byte[] item) Checks if an item might be contained in the Bloom filter.
-
Field Details
-
DEFAULT_ERROR_RATE
public static final double DEFAULT_ERROR_RATEDefault values used when creating a filter with BF.ADD without BF.RESERVE.- See Also:
-
DEFAULT_CAPACITY
public static final long DEFAULT_CAPACITY- See Also:
-
DEFAULT_EXPANSION
public static final int DEFAULT_EXPANSION- See Also:
-
-
Constructor Details
-
BloomFilter
public BloomFilter(double errorRate, long capacity, int expansion, boolean nonScaling)
-
-
Method Details
-
getErrorRate
@ProtoField(number=1, defaultValue="0.01") public double getErrorRate() -
getCapacity
@ProtoField(number=2, defaultValue="100") public long getCapacity() -
getExpansion
@ProtoField(number=3, defaultValue="2") public int getExpansion() -
isNonScaling
@ProtoField(number=4, defaultValue="false") public boolean isNonScaling() -
getSubFilters
-
getItemCount
@ProtoField(number=6, defaultValue="0") public long getItemCount() -
add
public boolean add(byte[] item) Adds an item to the Bloom filter.- Parameters:
item- the item to add- Returns:
- true if the item was newly added, false if it probably already existed
- Throws:
IllegalStateException- if the filter is full and non-scaling
-
mightContain
public boolean mightContain(byte[] item) Checks if an item might be contained in the Bloom filter.- Parameters:
item- the item to check- Returns:
- true if the item might be in the filter (with false positive probability), false if the item is definitely not in the filter
-
getTotalCapacity
public long getTotalCapacity()Returns the total capacity across all sub-filters. -
getSize
public long getSize()Returns the total size in bytes. -
getFilterCount
public int getFilterCount()Returns the number of sub-filters.
-