Collection Kit

BloomFilter

Probabilistic

A BloomFilter is a space-efficient probabilistic data structure used to test whether an element is a member of a set, allowing for false positives but no false negatives.

Import Statement
import { BloomFilter } from "collection-kit";

Key Features

  • Space Efficiency: Uses multiple hash functions to minimize space usage.
  • Probabilistic Membership: Can indicate that an element is possibly in the set or definitely not in the set.

Common Operations

Add
Insert an element into the Bloom filter.
Contains
Check if an element is possibly in the set.

Example Code

import { BloomFilter } from "collection-kit";

const bloom = new BloomFilter(100, 3); // size, hash functions
bloom.add("apple");
bloom.add("banana");

console.log("Contains apple:", bloom.contains("apple"));   // true
console.log("Contains orange:", bloom.contains("orange")); // false (probably)