Class CountingBloomFilter<T>

java.lang.Object
cloud.opencode.base.hash.bloom.CountingBloomFilter<T>
Type Parameters:
T - element type | 元素类型

public final class CountingBloomFilter<T> extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static final class 
    Builder for counting bloom filter 计数布隆过滤器构建器
  • Method Summary

    Modifier and Type
    Method
    Description
    builder(Funnel<? super T> funnel)
    Creates a builder 创建构建器
    void
    Clears all counters 清除所有计数器
    int
    count(T element)
    Gets the minimum count for an element 获取元素的最小计数
    boolean
    mightContain(T element)
    Tests if an element might be in the filter 测试元素是否可能在过滤器中
    boolean
    put(T element)
    Adds an element to the filter 向过滤器添加元素
    boolean
    remove(T element)
    Removes an element from the filter 从过滤器移除元素

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • put

      public boolean put(T element)
      Adds an element to the filter 向过滤器添加元素
      Parameters:
      element - the element | 元素
      Returns:
      true if successful | 如果成功返回true
    • remove

      public boolean remove(T element)
      Removes an element from the filter 从过滤器移除元素
      Parameters:
      element - the element | 元素
      Returns:
      true if successful | 如果成功返回true
    • mightContain

      public boolean mightContain(T element)
      Tests if an element might be in the filter 测试元素是否可能在过滤器中
      Parameters:
      element - the element | 元素
      Returns:
      true if might contain | 如果可能包含返回true
    • count

      public int count(T element)
      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

      public static <T> CountingBloomFilter.Builder<T> builder(Funnel<? super T> funnel)
      Creates a builder 创建构建器
      Type Parameters:
      T - element type | 元素类型
      Parameters:
      funnel - element funnel | 元素funnel
      Returns:
      builder | 构建器