Class CountingBloomFilter<T>
java.lang.Object
cloud.opencode.base.hash.bloom.CountingBloomFilter<T>
- Type Parameters:
T- element type | 元素类型
Counting bloom filter implementation
计数布隆过滤器实现
A variant of bloom filter that supports deletion by using counters instead of single bits. Each position has a counter that is incremented on insert and decremented on delete.
布隆过滤器的变体,通过使用计数器而不是单个位来支持删除。 每个位置都有一个计数器,在插入时递增,在删除时递减。
Features | 主要功能:
- Supports deletion - 支持删除
- Configurable counter bits - 可配置的计数器位数
- Count estimation - 计数估计
Usage Examples | 使用示例:
CountingBloomFilter<String> filter = CountingBloomFilter.builder(Funnel.STRING_FUNNEL)
.expectedInsertions(100_000)
.fpp(0.01)
.counterBits(4)
.build();
filter.put("item1");
filter.put("item1"); // Count = 2
filter.remove("item1"); // Count = 1
Security | 安全性:
- Thread-safe: No (use external synchronization) - 线程安全: 否(使用外部同步)
- Since:
- JDK 25, opencode-base-hash V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for counting bloom filter 计数布隆过滤器构建器 -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> CountingBloomFilter.Builder<T> Creates a builder 创建构建器voidclear()Clears all counters 清除所有计数器intGets the minimum count for an element 获取元素的最小计数booleanmightContain(T element) Tests if an element might be in the filter 测试元素是否可能在过滤器中booleanAdds an element to the filter 向过滤器添加元素booleanRemoves an element from the filter 从过滤器移除元素
-
Method Details
-
put
Adds an element to the filter 向过滤器添加元素- Parameters:
element- the element | 元素- Returns:
- true if successful | 如果成功返回true
-
remove
Removes an element from the filter 从过滤器移除元素- Parameters:
element- the element | 元素- Returns:
- true if successful | 如果成功返回true
-
mightContain
Tests if an element might be in the filter 测试元素是否可能在过滤器中- Parameters:
element- the element | 元素- Returns:
- true if might contain | 如果可能包含返回true
-
count
Gets the minimum count for an element 获取元素的最小计数- Parameters:
element- the element | 元素- Returns:
- minimum count across all positions | 所有位置的最小计数
-
clear
public void clear()Clears all counters 清除所有计数器 -
builder
Creates a builder 创建构建器- Type Parameters:
T- element type | 元素类型- Parameters:
funnel- element funnel | 元素funnel- Returns:
- builder | 构建器
-