Fix a serious bug with bucket indexing.

This commit is contained in:
Jason Davies 2011-12-07 21:56:28 +00:00
parent cbff8e23cd
commit 66cd9f577a
2 changed files with 6 additions and 5 deletions

View File

@ -44,20 +44,21 @@
var l = this.locations(v),
i = -1,
k = this.k,
m = this.m,
buckets = this.buckets;
while (++i < k) buckets[Math.floor(l[i] / k)] |= 1 << (l[i] % k)
while (++i < k) buckets[Math.floor(l[i] / m)] |= 1 << (l[i] % m);
};
BloomFilter.prototype.test = function(v) {
var l = this.locations(v),
n = l.length,
i = -1,
k = this.k,
m = this.m,
b,
buckets = this.buckets;
while (++i < n) {
while (++i < k) {
b = l[i];
if ((buckets[Math.floor(b / k)] & (1 << (b % k))) === 0) {
if ((buckets[Math.floor(b / m)] & (1 << (b % m))) === 0) {
return false;
}
}

View File

@ -1,6 +1,6 @@
{
"name": "bloomfilter",
"version": "0.0.5",
"version": "0.0.6",
"description": "Fast bloom filter in JavaScript.",
"keywords": [
"bloom filter",