bloom-filters
Advanced tools
Comparing version 1.3.2 to 1.3.4
@@ -27,3 +27,3 @@ /** | ||
*/ | ||
saveAsJSON(): void; | ||
saveAsJSON(): Object; | ||
/** | ||
@@ -34,3 +34,3 @@ * Load an Object from a provided JSON object | ||
*/ | ||
static fromJSON(json: any): void; | ||
static fromJSON(json: any): any; | ||
} |
@@ -81,3 +81,3 @@ /* file : base-filter.ts | ||
BaseFilter.prototype.saveAsJSON = function () { | ||
throw new Error('Not Implemented'); | ||
throw new Error('not-implemented'); | ||
}; | ||
@@ -90,3 +90,3 @@ /** | ||
BaseFilter.fromJSON = function (json) { | ||
throw new Error('Not Implemented'); | ||
throw new Error('not-implemented'); | ||
}; | ||
@@ -93,0 +93,0 @@ return BaseFilter; |
@@ -227,3 +227,3 @@ "use strict"; | ||
var res = []; | ||
for (var i = this._heap.length - 1; i > 0; i--) { | ||
for (var i = this._heap.length - 1; i >= 0; i--) { | ||
var elt = this._heap.get(i); | ||
@@ -254,3 +254,3 @@ res.push({ | ||
case 1: | ||
if (!(i > 0)) return [3 /*break*/, 4]; | ||
if (!(i >= 0)) return [3 /*break*/, 4]; | ||
elt = heap.get(i); | ||
@@ -257,0 +257,0 @@ return [4 /*yield*/, { |
{ | ||
"name": "bloom-filters", | ||
"version": "1.3.2", | ||
"version": "1.3.4", | ||
"description": "JS implementation of probabilistic data structures: Bloom Filter (and its derived), HyperLogLog, Count-Min Sketch, Top-K and MinHash", | ||
@@ -28,3 +28,4 @@ "main": "dist/api.js", | ||
"contributors": [ | ||
"Arnaud Grall <dev.arnaudgrall@gmail.com>" | ||
"Arnaud Grall <dev.arnaudgrall@gmail.com>", | ||
"Jonah H. Harris <jonah.harris@gmail.com>" | ||
], | ||
@@ -31,0 +32,0 @@ "license": "MIT", |
@@ -71,4 +71,4 @@ /* file : base-filter.ts | ||
*/ | ||
saveAsJSON() { | ||
throw new Error('Not Implemented') | ||
saveAsJSON(): Object { | ||
throw new Error('not-implemented') | ||
} | ||
@@ -81,5 +81,5 @@ | ||
*/ | ||
static fromJSON(json: any) { | ||
throw new Error('Not Implemented') | ||
static fromJSON(json: any): any { | ||
throw new Error('not-implemented') | ||
} | ||
} |
@@ -214,3 +214,3 @@ /* file: topk.ts | ||
const res = [] | ||
for (let i = this._heap.length - 1; i > 0; i--) { | ||
for (let i = this._heap.length - 1; i >= 0; i--) { | ||
const elt = this._heap.get(i)! | ||
@@ -235,3 +235,3 @@ res.push({ | ||
return function *() { | ||
for (let i = heap.length - 1; i > 0; i--) { | ||
for (let i = heap.length - 1; i >= 0; i--) { | ||
const elt = heap.get(i)! | ||
@@ -238,0 +238,0 @@ yield { |
@@ -27,2 +27,3 @@ /* file : topk-test.js | ||
require('chai').should() | ||
@@ -32,17 +33,46 @@ const { TopK } = require('../dist/api.js') | ||
describe('TopK', () => { | ||
const lessThanOrEqualTestCaseItems = [ | ||
'alice', 'bob', 'alice', 'carol', | ||
'bob', 'alice' | ||
] | ||
const moreThanTestCaseItems = [ | ||
'alice', 'daniel', 'esther', 'bob', | ||
'alice', 'bob', 'alice', 'carol', | ||
'carol', 'alice', 'bob' | ||
] | ||
const expectedTop = ['alice', 'bob', 'carol'] | ||
describe('#values', () => { | ||
it('should produce valid TopK estimations', () => { | ||
it('should produce valid TopK estimations when there are fewer than K items', () => { | ||
const topk = new TopK(10, 0.001, 0.999) | ||
for (let item of lessThanOrEqualTestCaseItems) { | ||
topk.add(item) | ||
} | ||
let i = 0 | ||
let prev = { frequency: Infinity } | ||
for (let current of topk.values()) { | ||
current.should.have.all.keys('value', 'rank', 'frequency') | ||
current.value.should.equal(expectedTop[i]) | ||
current.frequency.should.be.below(prev.frequency) | ||
current.rank.should.equal(i + 1) | ||
prev = current | ||
i++ | ||
} | ||
i.should.equal(expectedTop.length) | ||
}) | ||
it('should produce valid TopK estimations when there are exactly K items', () => { | ||
const topk = new TopK(3, 0.001, 0.999) | ||
topk.add('alice') | ||
topk.add('bob') | ||
topk.add('alice') | ||
topk.add('carol') | ||
topk.add('bob') | ||
topk.add('alice') | ||
for (let item of lessThanOrEqualTestCaseItems) { | ||
topk.add(item) | ||
} | ||
let i = 0 | ||
let prev = { frequency: Infinity } | ||
for (let current of topk.iterator()) { | ||
for (let current of topk.values()) { | ||
current.should.have.all.keys('value', 'rank', 'frequency') | ||
current.value.should.equal(expectedTop[i]) | ||
@@ -54,19 +84,14 @@ current.frequency.should.be.below(prev.frequency) | ||
} | ||
i.should.equal(expectedTop.length) | ||
}) | ||
it('should produce valid estimations when there are more than K items', () => { | ||
it('should produce valid TopK estimations when there are more than K items', () => { | ||
const topk = new TopK(3, 0.001, 0.999) | ||
topk.add('alice') | ||
topk.add('daniel') | ||
topk.add('esther') | ||
topk.add('bob') | ||
topk.add('alice') | ||
topk.add('bob') | ||
topk.add('alice') | ||
topk.add('carol') | ||
topk.add('carol') | ||
topk.add('alice') | ||
for (let item of moreThanTestCaseItems) { | ||
topk.add(item) | ||
} | ||
let i = 0 | ||
let prev = { frequency: Infinity } | ||
let i = 0 | ||
for (let current of topk.values()) { | ||
@@ -80,2 +105,4 @@ current.should.have.all.keys('value', 'rank', 'frequency') | ||
} | ||
i.should.equal(expectedTop.length) | ||
}) | ||
@@ -85,10 +112,27 @@ }) | ||
describe('#iterator', () => { | ||
it('should produce valid TopK estimations', () => { | ||
it('should produce valid TopK estimations when there are fewer than K items', () => { | ||
const topk = new TopK(10, 0.001, 0.999) | ||
for (let item of lessThanOrEqualTestCaseItems) { | ||
topk.add(item) | ||
} | ||
let i = 0 | ||
let prev = { frequency: Infinity } | ||
for (let current of topk.iterator()) { | ||
current.should.have.all.keys('value', 'rank', 'frequency') | ||
current.value.should.equal(expectedTop[i]) | ||
current.frequency.should.be.below(prev.frequency) | ||
current.rank.should.equal(i + 1) | ||
prev = current | ||
i++ | ||
} | ||
i.should.equal(expectedTop.length) | ||
}) | ||
it('should produce valid TopK estimations when there are exactly K items', () => { | ||
const topk = new TopK(3, 0.001, 0.999) | ||
topk.add('alice') | ||
topk.add('bob') | ||
topk.add('alice') | ||
topk.add('carol') | ||
topk.add('bob') | ||
topk.add('alice') | ||
for (let item of lessThanOrEqualTestCaseItems) { | ||
topk.add(item) | ||
} | ||
@@ -105,2 +149,4 @@ let i = 0 | ||
} | ||
i.should.equal(expectedTop.length) | ||
}) | ||
@@ -110,12 +156,5 @@ | ||
const topk = new TopK(3, 0.001, 0.999) | ||
topk.add('alice') | ||
topk.add('daniel') | ||
topk.add('esther') | ||
topk.add('bob') | ||
topk.add('alice') | ||
topk.add('bob') | ||
topk.add('alice') | ||
topk.add('carol') | ||
topk.add('carol') | ||
topk.add('alice') | ||
for (let item of moreThanTestCaseItems) { | ||
topk.add(item) | ||
} | ||
@@ -132,2 +171,4 @@ let i = 0 | ||
} | ||
i.should.equal(expectedTop.length) | ||
}) | ||
@@ -134,0 +175,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
440879
9982