bloomfilter
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -8,8 +8,9 @@ (function(exports) { | ||
// Creates a new bloom filter with *m* bits and *k* hashing functions. | ||
function BloomFilter(m, k) { | ||
this.m = m; | ||
this.k = k; | ||
var n = Math.ceil(m / k); | ||
var n = Math.ceil(m / 32); | ||
if (typedArrays) { | ||
var buffer = new ArrayBuffer(4 * n), | ||
var buffer = new ArrayBuffer(32 * n), | ||
kbytes = 1 << Math.ceil(Math.log(Math.ceil(Math.log(m) / Math.LN2 / 8)) / Math.LN2), | ||
@@ -16,0 +17,0 @@ array = kbytes === 1 ? Uint8Array : kbytes === 2 ? Uint16Array : Uint32Array, |
{ | ||
"name": "bloomfilter", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Fast bloom filter in JavaScript.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -7,3 +7,25 @@ Bloom Filter | ||
Although the bloom filter requires *n* hash functions, we can simulate this | ||
Usage | ||
----- | ||
var bloom = new BloomFilter( | ||
32 * 256, // number of bits to allocate. | ||
16 // number of hash functions. | ||
); | ||
// Add some elements to the filter. | ||
bloom.add("foo"); | ||
bloom.add("bar"); | ||
// Test if an item is in our filter. | ||
// Returns true if an item is probably in the set, | ||
// or false if an item is definitely not in the set. | ||
bloom.test("foo"); | ||
bloom.test("bar"); | ||
bloom.test("blah"); | ||
Implementation | ||
-------------- | ||
Although the bloom filter requires *k* hash functions, we can simulate this | ||
using only *two* hash functions. In fact, we cheat and get the second hash | ||
@@ -10,0 +32,0 @@ function almost for free by iterating once more on the first hash using the FNV |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5903
94
39