@hazemaltakriti/hyperloglog
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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:

Package Sidebar

Install

npm i @hazemaltakriti/hyperloglog

Weekly Downloads

21

Version

1.0.1

License

MIT

Unpacked Size

6.98 kB

Total Files

6

Last publish

Collaborators

  • hazemaltakriti