Pacote
    Preparing search index...

    Class RibbonFilter<T>

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

    A Ribbon filter is built once from its complete set of elements and cannot be changed afterwards. Membership checks can produce false positives, at a rate of 2^-fingerprintBits, but never false negatives.

    This is a Standard Ribbon filter (Dillinger and Walzer, 2021) with a ribbon width of at most 32 bits. The filter uses seeded XXH64 hashing with enhanced double hashing by default. This hash is non-cryptographic and should not be used for security-sensitive purposes.

    import { optimal, RibbonFilter } from '@pacote/ribbon-filter'

    const filter = new RibbonFilter({
    ...optimal(0.01),
    elements: ['foo', '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
    • Builds a filter from its elements, or restores a serialised filter.

      Type Parameters

      • T extends { toString(): string }

        Values represented by the filter.

      Parameters

      • options: Options<T>

        Fingerprint bits, and either the elements to build from or the filter data to restore.

      Returns RibbonFilter<T>

      A new Ribbon filter.

      Error if fingerprintBits is not an integer between 1 and 32, if both elements and filter are provided, if filter is empty, or if the elements cannot be stored.

    filter: Uint32Array

    Solution table, one fingerprintBits-wide row after another.

    fingerprintBits: number

    Bits per fingerprint; the false positive rate is 2^-fingerprintBits.

    seed: number

    Seed for the default hash function.

    size: number

    Number of rows in the solution table, after any growth during the build.

    • 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.