Comparing version 0.2.1 to 1.0.0
var FNV = require('fnv').FNV | ||
var Blomma = function (bytes, rounds) { | ||
var Blomma = function (size, rounds) { | ||
var indicies = function (value) { | ||
@@ -10,3 +10,3 @@ var hash = new FNV() | ||
hash.update(value) | ||
idx.push(parseInt(hash.digest('hex'), 16) % (bytes * 8)) | ||
idx.push(parseInt(hash.digest('hex'), 16) % (size * 8)) | ||
value = '\0' | ||
@@ -17,15 +17,20 @@ } | ||
var extend = function (buffer) { | ||
buffer.add = function (value) { | ||
var Filter = function (data) { | ||
this.buffer = new Buffer(size) | ||
this.buffer.fill(0) | ||
} | ||
Filter.prototype = { | ||
add: function (value) { | ||
var idx = indicies(value) | ||
for (var i = 0 ; i < rounds ; i++) { | ||
var bit = idx[i] | ||
buffer[bit >> 3] |= (1 << (bit % 8)) | ||
this.buffer[bit >> 3] |= (1 << (bit % 8)) | ||
} | ||
} | ||
buffer.has = function (value) { | ||
}, | ||
has: function (value) { | ||
var idx = indicies(value) | ||
for (var i = 0 ; i < rounds ; i++) { | ||
var bit = idx[i] | ||
if (!(buffer[bit >> 3] & (1 << (bit % 8)))) { | ||
if (!(this.buffer[bit >> 3] & (1 << (bit % 8)))) { | ||
return false | ||
@@ -35,6 +40,6 @@ } | ||
return true | ||
} | ||
buffer.contains = function (subset) { | ||
for (var i = 0 ; i < bytes ; i++) { | ||
if ((this[i] & subset[i]) !== subset[i]) { | ||
}, | ||
contains: function (subset) { | ||
for (var i = 0 ; i < size ; i++) { | ||
if ((this.buffer[i] & subset.buffer[i]) !== subset.buffer[i]) { | ||
return false | ||
@@ -45,3 +50,2 @@ } | ||
} | ||
return buffer | ||
} | ||
@@ -51,15 +55,17 @@ | ||
empty: function () { | ||
var buf = new Buffer(bytes) | ||
buf.fill(0) | ||
return extend(buf) | ||
return new Filter(size) | ||
}, | ||
merge: function (a, b) { | ||
var buf = new Buffer(bytes) | ||
for (var i = 0 ; i < bytes ; i++) { | ||
buf[i] = a[i] | b[i] | ||
var filter = new Filter() | ||
for (var i = 0 ; i < size ; i++) { | ||
filter.buffer[i] = a.buffer[i] | b.buffer[i] | ||
} | ||
return extend(buf) | ||
return filter | ||
}, | ||
clone: function (filter) { | ||
return extend(new Buffer(filter)) | ||
clone: function (toclone) { | ||
var filter = new Filter() | ||
for (var i = 0 ; i < size ; i++) { | ||
filter.buffer[i] = toclone.buffer[i] | ||
} | ||
return filter | ||
} | ||
@@ -66,0 +72,0 @@ } |
{ | ||
"name": "blomma", | ||
"version": "0.2.1", | ||
"version": "1.0.0", | ||
"description": "Bloom filters yet again", | ||
@@ -5,0 +5,0 @@ "main": "blomma.js", |
@@ -104,2 +104,14 @@ 'use strict' | ||
}) | ||
it('f12 should not contain 3', function () { | ||
assert(!f12.contains(f3)) | ||
}) | ||
it('f13 should not contain 2', function () { | ||
assert(!f13.contains(f2)) | ||
}) | ||
it('f23 should not contain 1', function () { | ||
assert(!f23.contains(f1)) | ||
}) | ||
}) | ||
@@ -106,0 +118,0 @@ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6793
169
1