Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blomma

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blomma - npm Package Compare versions

Comparing version 0.2.1 to 1.0.0

50

blomma.js
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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc