Pacote
    Preparing search index...

    Class BloomFilter<T>

    A space-efficient probabilistic set for values with a stable toString().

    Membership checks can produce false positives, but never false negatives. Use CountingBloomFilter when values must be removed. The filter uses seeded XXH64 hashing with enhanced double hashing. This hash is non-cryptographic and should not be used for security-sensitive purposes.

    import { BloomFilter, optimal } from '@pacote/bloom-filter'

    const filter = new BloomFilter(optimal(1000, 0.01))
    filter.add('foo')
    filter.add('bar')
    filter.has('foo') // => true
    filter.has('bar') // => true
    filter.has('baz') // => false

    Type Parameters

    • T extends { toString(): string }

      Values represented by the filter.

    Index
    • Creates a filter from its size, hash count, and optional seed or bit data.

      Type Parameters

      • T extends { toString(): string }

        Values represented by the filter.

      Parameters

      • options: Options

        Filter size, hash count, and optional initial state.

      Returns BloomFilter<T>

      A new Bloom filter.

      Error if size or hashes is not a positive integer, or if filter does not hold size bits.

    filter: Uint32Array
    hashes: number
    seed: number
    size: number
    • Adds an element to the filter.

      Parameters

      • element: T

        Value to add.

      Returns void

    • Checks whether an element may be present in the filter.

      Parameters

      • element: T

        Value to look up.

      Returns boolean

      false guarantees the element is absent; true means it may be present and can be a false positive.