Class BloomFilterBuilder<T>

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

public final class BloomFilterBuilder<T> extends Object
Builder for bloom filter 布隆过滤器构建器

Provides a fluent API for configuring and building a bloom filter.

提供流畅的API来配置和构建布隆过滤器。

Usage Examples | 使用示例:

BloomFilter<String> filter = BloomFilter.builder(Funnel.STRING_FUNNEL)
    .expectedInsertions(1_000_000)
    .fpp(0.01)
    .hashFunction(OpenHash.murmur3_128())
    .build();

Features | 主要功能:

  • Fluent builder API for BloomFilter construction - 流畅的BloomFilter构建器API
  • Auto-calculates optimal bit size and hash count - 自动计算最优位大小和哈希数量
  • Configurable false positive rate - 可配置的误判率

Performance | 性能特性:

  • Time complexity: O(1) for build() and configuration methods; optimalNumOfBits and optimalNumOfHashFunctions are O(1) math computations - 时间复杂度: build() 和配置方法为 O(1);optimalNumOfBits 和 optimalNumOfHashFunctions 为 O(1) 数学计算
  • Space complexity: O(m) where m=optimal bit array size derived from expectedInsertions and fpp - 空间复杂度: O(m),m 为由 expectedInsertions 和 fpp 推导的最优位数组大小
Since:
JDK 25, opencode-base-hash V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • BloomFilterBuilder

      public BloomFilterBuilder(Funnel<? super T> funnel)
  • Method Details

    • expectedInsertions

      public BloomFilterBuilder<T> expectedInsertions(long expectedInsertions)
      Sets the expected number of insertions 设置预期插入数量
      Parameters:
      expectedInsertions - expected insertions | 预期插入量
      Returns:
      this builder | 此构建器
    • fpp

      public BloomFilterBuilder<T> fpp(double fpp)
      Sets the false positive probability (0.0 - 1.0) 设置误判率(0.0 - 1.0)
      Parameters:
      fpp - false positive probability | 误判率
      Returns:
      this builder | 此构建器
    • hashFunction

      public BloomFilterBuilder<T> hashFunction(HashFunction hashFunction)
      Sets the hash function 设置哈希函数
      Parameters:
      hashFunction - hash function | 哈希函数
      Returns:
      this builder | 此构建器
    • threadSafe

      public BloomFilterBuilder<T> threadSafe(boolean threadSafe)
      Sets whether to use thread-safe bit array 设置是否使用线程安全的位数组
      Parameters:
      threadSafe - whether to be thread-safe | 是否线程安全
      Returns:
      this builder | 此构建器
    • build

      public BloomFilter<T> build()
      Builds the bloom filter 构建布隆过滤器
      Returns:
      bloom filter | 布隆过滤器