Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bloom-filters

Package Overview
Dependencies
Maintainers
0
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bloom-filters

JS implementation of probabilistic data structures: Bloom Filter (and its derived), HyperLogLog, Count-Min Sketch, Top-K and MinHash

  • 3.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
204K
decreased by-3.73%
Maintainers
0
Weekly downloads
 
Created

What is bloom-filters?

The 'bloom-filters' npm package provides data structures and algorithms for probabilistic data structures, specifically Bloom filters, which are used to test whether an element is a member of a set. These structures are highly space-efficient and are useful for applications where a small rate of false positives is acceptable.

What are bloom-filters's main functionalities?

Creating a Bloom Filter

This feature allows you to create a Bloom filter with a specified size and number of hash functions. You can add elements to the filter and check for their existence. Note that false positives are possible, but false negatives are not.

const { BloomFilter } = require('bloom-filters');
const filter = new BloomFilter(10, 4);
filter.add('apple');
console.log(filter.has('apple')); // true
console.log(filter.has('banana')); // false

Serializing and Deserializing a Bloom Filter

This feature allows you to serialize a Bloom filter to JSON and later deserialize it. This is useful for saving the state of a filter and reloading it later.

const { BloomFilter } = require('bloom-filters');
const filter = new BloomFilter(10, 4);
filter.add('apple');
const json = JSON.stringify(filter.save());
const loadedFilter = BloomFilter.fromJSON(JSON.parse(json));
console.log(loadedFilter.has('apple')); // true

Counting Bloom Filter

This feature provides a Counting Bloom Filter, which allows for the removal of elements. This is achieved by maintaining a count of the number of times an element has been added.

const { CountingBloomFilter } = require('bloom-filters');
const filter = new CountingBloomFilter(10, 4);
filter.add('apple');
filter.add('apple');
console.log(filter.has('apple')); // true
filter.remove('apple');
console.log(filter.has('apple')); // true
filter.remove('apple');
console.log(filter.has('apple')); // false

Other packages similar to bloom-filters

Keywords

FAQs

Package last updated on 21 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc