Download the PHP package hichxm/hyperloglog without Composer
On this page you can find all versions of the php package hichxm/hyperloglog. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hichxm/hyperloglog
More information about hichxm/hyperloglog
Files in hichxm/hyperloglog
Package hyperloglog
Short Description A PHP implementation of the HyperLogLog algorithm.
License MIT
Informations about the package hyperloglog
HyperLogLog for PHP
A lightweight and dependency-free PHP implementation of the HyperLogLog probabilistic data structure for approximate cardinality estimation.
HyperLogLog allows you to estimate the number of distinct elements in very large datasets while using only a small, fixed amount of memory.
View on Packagist: hichxm/hyperloglog
Features
- 🚀 Fast approximate distinct counting
- 📦 Zero dependencies
- 🔧 Configurable number of registers (
counterBits) - 🔐 Configurable hashing algorithm (
xxh3,sha256,md5, etc.) - 📊 Theoretical error rate calculation
- 🧮 Small and large cardinality bias corrections
- ✅ Strict types and fully documented source code
When to Use HyperLogLog
HyperLogLog is well suited for:
- Counting unique visitors
- Counting unique IP addresses
- Analytics pipelines
- Large log processing
- Stream processing
- Database statistics
- Big data applications
It is not appropriate when an exact distinct count is required.
Requirements
- PHP 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 and 8.5
- No external dependencies
Note: The
xxh3andxxh128hash algorithms are available only when supported by your PHP version and build. If unavailable, you can use any other algorithm returned byhash_algos(), such assha256,sha512, ormd5.
Installation
Install via Composer:
Basic Usage
The returned value is an approximation of the number of unique elements.
Constructor
Parameters
| Parameter | Description |
|---|---|
counterBits |
Number of bits used to select registers. The number of registers is 2^counterBits. |
hashAlgorithm |
Any hashing algorithm supported by PHP's hash() function. |
Increasing
counterBitsimproves accuracy while increasing memory usage.
Example:
Accuracy
The theoretical standard error is:
where:
Example:
Supported Hash Algorithms
Any algorithm supported by PHP can be used.
Examples include:
xxh3(recommended when available)xxh128sha256sha512md5sha1
You can list available algorithms using:
Public API
Add an element
Estimate the number of distinct values
Calculate the theoretical error
Measure estimation error
References
License
MIT