1.0.1 • Published 5 months ago

@hazemaltakriti/hyperloglog v1.0.1

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
5 months ago

HyperLogLog

A TypeScript implementation of the HyperLogLog algorithm for cardinality estimation.

Installation

npm install @hazemaltakriti/hyperloglog

Usage

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}`);

API

Constructor

new HyperLogLog(precision?: number)
  • precision: Optional. Number between 4 and 16. Default is 14. Higher precision means better accuracy but more memory usage.

Methods

add(element: string | number): void

Adds an element to the HyperLogLog counter.

count(): number

Returns the estimated cardinality (number of unique elements).

Development

# Install dependencies
npm install

# Run tests
npm test

# Build the project
npm run build

Authors

Acknowledgments

This implementation is based on the seminal paper: