Skip to content

Commit 5317a5a

Browse files
committed
no issue at all; update the readme
1 parent 97b6725 commit 5317a5a

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,18 +313,19 @@ The HyperLogLog algorithm is able to estimate cardinalities greather than `10e9`
313313
const {HyperLogLog} = require('bloom-filters')
314314

315315
// create a new HyperLogLog with 100 registers
316-
const sketch = new HyperLogLog(100)
317-
318-
// push some occurrences in the sketch
319-
sketch.update('alice')
320-
sketch.update('alice')
321-
sketch.update('bob')
322-
323-
// count occurrences
324-
console.log(sketch.count())
316+
const sketch = new HyperLogLog(128)
317+
// push 10000 distinct elements
318+
const n = 2 ** 14
319+
for (let i = 0; i<n; i++) {
320+
sketch.update(i.toString())
321+
}
325322

326-
// print accuracy
327-
console.log(sketch.accuracy())
323+
// print the relative error
324+
console.log(sketch.relative_error()) // 1.04 / Math.sqrt(128)
325+
// print the approximated number of distinct elements
326+
console.log(sket.count())
327+
// print the real error; should always be less than n * sketch.relative_error() * 3
328+
console.log(n - sketch.count())
328329
```
329330

330331
### MinHash

tests/hyperloglog.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,16 @@ test('should create an HyperLogLog from a JSON export', () => {
109109
expect(newFilter._correctionBias).toEqual(sketch._correctionBias)
110110
expect(newFilter._registers).toEqual(sketch._registers)
111111
})
112+
113+
test('issue#(https://github.com/Callidon/bloom-filters/issues/69)', () => {
114+
// create a new HyperLogLog with 100 registers
115+
const sketch = new HyperLogLog(128)
116+
// push 10000 distinct elements
117+
const n = 2 ** 14
118+
for (let i = 0; i<n; i++) {
119+
sketch.update(i.toString())
120+
}
121+
// count occurrences
122+
expect(sketch.relative_error()).toEqual(1.04 / Math.sqrt(128))
123+
expect(n - sketch.count()).toBeLessThan(n * sketch.relative_error() * 3)
124+
})

0 commit comments

Comments
 (0)