{"id":19494736,"url":"https://github.com/ceejbot/xx-bloom","last_synced_at":"2025-04-25T21:32:01.992Z","repository":{"id":6613640,"uuid":"7857093","full_name":"ceejbot/xx-bloom","owner":"ceejbot","description":"yet another bloom filter implementation for node.js; backed by xxhash","archived":false,"fork":false,"pushed_at":"2017-09-27T19:29:12.000Z","size":98,"stargazers_count":44,"open_issues_count":17,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-18T20:25:38.931Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ceejbot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-27T19:49:22.000Z","updated_at":"2024-09-12T11:59:03.000Z","dependencies_parsed_at":"2022-09-12T07:01:36.325Z","dependency_job_id":null,"html_url":"https://github.com/ceejbot/xx-bloom","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceejbot%2Fxx-bloom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceejbot%2Fxx-bloom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceejbot%2Fxx-bloom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceejbot%2Fxx-bloom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ceejbot","download_url":"https://codeload.github.com/ceejbot/xx-bloom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250899983,"owners_count":21504978,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T21:32:45.214Z","updated_at":"2025-04-25T21:32:01.669Z","avatar_url":"https://github.com/ceejbot.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"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 [node-xxhash](https://github.com/mscdex/node-xxhash). Xxhash is a fast general-purpose hash, which is all a bloom filter needs. Three variations are provided: a straight Bloom filter, a counting filter (from which items can be removed), and a straight Bloom filter backed by redis. The first two have synchronous APIs. The redis one perforce requires callbacks.\n\nTo install: `npm install bloomxx`\n\n[![on npm](https://img.shields.io/npm/v/bloomxx.svg?style=flat)](https://www.npmjs.com/package/bloomxx) [![Build Status](http://img.shields.io/travis/ceejbot/xx-bloom/master.svg?style=flat)](https://travis-ci.org/ceejbot/xx-bloom) [![Coverage Status](https://img.shields.io/coveralls/ceejbot/xx-bloom.svg?style=flat)](https://coveralls.io/github/ceejbot/xx-bloom?branch=master)\n\n## Usage\n\n### BloomFilter\n\nTo create a filter, pass an options hash to the constructor:\n\n```javascript\nvar options =\n{\n\tbits: 1024,\n\thashes: 7,\n\tseeds: [1, 2, 3, 4, 5, 6, 7]\n};\nfilter = new BloomFilter(options);\n```\n\nYou can pass in seeds for the hash functions if you like, or they'll be randomly generated. Seeds must be integers.\n\nYou may also pass in a buffer as generated by `filter.toBuffer()`.\n\n### createOptimal()\n\nTo create a filter optimized for the number of items you'll be storing and a desired error rate:\n\n`filter = BloomFilter.createOptimal(estimatedItemCount, errorRate);`\n\nThe error rate parameter is optional. It defaults to 0.005, or a 0.5% rate.\n\n### add()\n\n`filter.add('cat');`\n\nAdds the given item to the filter. Can also accept buffers and arrays containing strings or buffers:\n\n`filter.add(['cat', 'dog', 'coati', 'red panda']);`\n\n### has()\n\nTo test for membership:\n\n`filter.has('dog');`\n\n### clear()\n\nTo clear the filter:\n\n`filter.clear();`\n\n### toBuffer()\n\nReturns a buffer with seeds and filter data.\n\n### fromBuffer()\n\nReconstitutes a filter from a freeze-dried buffer.\n\n### CountingFilter\n\nUses about 8 times as much space as the regular filter. Basic usage is exactly the same as the plain Bloom filter:\n\n```javascript\nfilter = new CountingFilter({ hashes: 8, bits: 1024 });`\nfilter2 = CountingFilter.createOptimal(estimatedItemCount, optionalErrorRate);\n```\n\nAdd a list, test for membership, then remove:\n\n```javascript\nfilter.add(['cat', 'dog', 'coati', 'red panda']);\nfilter.has('cat'); // returns true\nfilter.remove('cat');\nfilter.has('cat'); // returns false most of the time\n```\n\nThe counting filter tracks its overflow count in `filter.overflow`. Overflow will be non-zero if any bit has been set more than 255 times. Once the filter has overflowed, removing items is no longer reliable.\n\nCheck for overflow:\n\n```javascript\nfilter.hasOverflowed(); // returns boolean\nfilter.overflow; // integer count of number of times overflow occurred\n```\n\n### RedisFilter\n\nThis is a plain vanilla bloom filter backed by redis. Its api is asychronous.\n\n```javascript\nRedisFilter.createOrRead({\n\t\tkey: 'cats', // the key used to store data in redis; will also set 'cats:meta'\n\t\tbits: 1024,  // filter size in bits\n\t\thashes: 8,   // number of hash functions\n\t\tredis: redis.createClient(port, host)  // redis client to use\n\t}, function(err, filter)\n\t{\n\t\tfilter.add(['cat', 'jaguar', 'lion', 'tiger', 'leopard'], function(err)\n\t\t{\n\t\t\tfilter.has('caracal', function(err, result)\n\t\t\t{\n\t\t\t\tassert(result === false);\n\t\t\t});\n\t\t});\n\t});\n```\n\nThe options hash can also specify `host` and `port`, which will be used to create a redis client. `createOrRead()` will attempt to find a filter saved at the given key and create one if it isn't found.\n\n### createOptimal(itemCount, errorRate, options)\n\nReturns a filter sized for the given item count and desired error rate, with other options as specified in the `options` hash.\n\n### clear(function(err) {})\n\nClear all bits.\n\n### del(function(err) {})\n\nDelete the filter from redis.\n\n## Licence\n\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceejbot%2Fxx-bloom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fceejbot%2Fxx-bloom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceejbot%2Fxx-bloom/lists"}