TypeScript implementation of HyperLogLog algorithm
A TypeScript implementation of the HyperLogLog algorithm for cardinality estimation.
``bash`
npm install @hazemaltakriti/hyperloglog
`typescript
import { HyperLogLog } from '@hazemaltakriti/hyperloglog';
// Create a new HyperLogLog instance with default precision (14)
const hll = new HyperLogLog();
// Add elements
hll.add('item1');
hll.add('item2');
hll.add('item3');
// Get the estimated cardinality
const count = hll.count();
console.log(Estimated unique elements: ${count});`
`typescript`
new HyperLogLog(precision?: number)
- precision: Optional. Number between 4 and 16. Default is 14. Higher precision means better accuracy but more memory usage.
#### add(element: string | number): void
Adds an element to the HyperLogLog counter.
#### count(): number
Returns the estimated cardinality (number of unique elements).
`bashInstall dependencies
npm install
- Hazem Altakriti - Senior Backend Developer
- LinkedIn
- Medium
This implementation is based on the seminal paper:
- Flajolet, P., Fusy, É., Gandouet, O., & Meunier, F. (2007). HyperLogLog: the analysis of a near-optimal cardinality estimation algorithm. In Proceedings of the 2007 International Conference on Analysis of Algorithms.