bloom-filter-ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Bloom Filter in Typescript

The goal would be to provide users an extendable sdk to create and manipulate bloom filters

This package uses decimal.js to handle precision arithmetic

Usage

There are multiple ways you can create the bloom filter according to your requirements.

Using the helper functions

  1. getKandM(n: number, permittedError: Decimal): {k: number, m: number}

    k: number of hashing functions

    m: bitCount

    Use this if you know n and permittedError

    Javascript/Typescript:

    const { k, m } = getKandM(12, new Decimal("0.001"));
  2. getK(m: number, n: number): number

    k: number of hashing functions

    Use this if you know m and n

    Javascript/Typescript:

    const k = getK(256, 12);
  3. getError(k: number, m: number: n: number): Decimal

    error: % of false positives returned

    Use this to check if your k, m, n values are OK

    Javascript/Typescript:

    const error = getError(14, 256, 12);
  4. generateHashingFunction<Type>() : HashingFunction

    The hashing function returned works on the murmur algorithm

    It is recommended to bring other algorithms as well to improve robustness

    Javascript:

    const hashingFunction = generateHashingFunction();

    Typescript:

    // the function takes a generic value type - as long as String(Type) // supports the type you're passing in, it will work
    const hashingFunction = generateHashingFunction<string>();
  5. generateBloomFilter<Type>(n: number, permittedError: Decimal, step: number = 1): BloomFilter<Type>

    Use this when you have n and permittedError

    Javascript:

    const bf = generateBloomFilter(25, new Decimal("0.0001"));

    Typescript:

    const bf = generateBloomFilter<string>(25, new Decimal("0.001"));

Note: For more detailed documentation - checkout the docs/ directory


Readme

Keywords

none

Package Sidebar

Install

npm i bloom-filter-ts

Weekly Downloads

4

Version

1.0.5

License

MIT

Unpacked Size

10.7 kB

Total Files

8

Last publish

Collaborators

  • aaryamannchallani