Skip to content

Commit

Permalink
no issue at all; update the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
folkvir committed May 16, 2024
1 parent 97b6725 commit 5317a5a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,18 +313,19 @@ The HyperLogLog algorithm is able to estimate cardinalities greather than `10e9`
const {HyperLogLog} = require('bloom-filters')

// create a new HyperLogLog with 100 registers
const sketch = new HyperLogLog(100)

// push some occurrences in the sketch
sketch.update('alice')
sketch.update('alice')
sketch.update('bob')

// count occurrences
console.log(sketch.count())
const sketch = new HyperLogLog(128)
// push 10000 distinct elements
const n = 2 ** 14
for (let i = 0; i<n; i++) {
sketch.update(i.toString())
}

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

### MinHash
Expand Down
13 changes: 13 additions & 0 deletions tests/hyperloglog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,16 @@ test('should create an HyperLogLog from a JSON export', () => {
expect(newFilter._correctionBias).toEqual(sketch._correctionBias)
expect(newFilter._registers).toEqual(sketch._registers)
})

test('issue#(https://github.com/Callidon/bloom-filters/issues/69)', () => {
// create a new HyperLogLog with 100 registers
const sketch = new HyperLogLog(128)
// push 10000 distinct elements
const n = 2 ** 14
for (let i = 0; i<n; i++) {
sketch.update(i.toString())
}
// count occurrences
expect(sketch.relative_error()).toEqual(1.04 / Math.sqrt(128))
expect(n - sketch.count()).toBeLessThan(n * sketch.relative_error() * 3)
})

0 comments on commit 5317a5a

Please sign in to comment.