https://github.com/ceejbot/xxbloom
https://github.com/ceejbot/xxbloom
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ceejbot/xxbloom
- Owner: ceejbot
- License: other
- Created: 2017-09-28T00:19:12.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-28T04:15:33.000Z (almost 9 years ago)
- Last Synced: 2025-02-24T03:56:40.777Z (over 1 year ago)
- Language: JavaScript
- Size: 44.9 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Yet another Bloom filter implementation for node.js. Everybody has to write one, as you know. Backed by [Xxhash](https://code.google.com/p/xxhash/) via [xxhashjs](https://github.com/pierrec/js-xxhash). Xxhash is a fast general-purpose hash, which is all a bloom filter needs.
To install: `npm install xxbloom`
[](https://www.npmjs.com/package/xxbloom) [](https://travis-ci.org/ceejbot/xxbloom) [](https://coveralls.io/github/ceejbot/xxbloom?branch=master)
## Usage
### BloomFilter
To create a filter, pass an options hash to the constructor:
```javascript
var options =
{
bits: 1024,
hashes: 7,
seeds: [1, 2, 3, 4, 5, 6, 7]
};
filter = new BloomFilter(options);
```
You can pass in seeds for the hash functions if you like, or they'll be randomly generated. Seeds must be integers.
You may also pass in a buffer as generated by `filter.toBuffer()`.
### createOptimal()
To create a filter optimized for the number of items you'll be storing and a desired error rate:
`filter = BloomFilter.createOptimal(estimatedItemCount, errorRate);`
The error rate parameter is optional. It defaults to 0.005, or a 0.5% rate.
### add()
`filter.add('cat');`
Adds the given item to the filter. Can also accept buffers and arrays containing strings or buffers:
`filter.add(['cat', 'dog', 'coati', 'red panda']);`
### has()
To test for membership:
`filter.has('dog');`
### clear()
To clear the filter:
`filter.clear();`
### toBuffer()
Returns a buffer with seeds and filter data.
### fromBuffer()
Reconstitutes a filter from a freeze-dried buffer.
## Licence
ISC.