Skip to content

Latest commit

Β 

History

History
95 lines (60 loc) Β· 2.33 KB

File metadata and controls

95 lines (60 loc) Β· 2.33 KB

HLL.NET – HyperLogLog for .NET

NuGet Tests

A fast and memory-efficient implementation of the HyperLogLog algorithm in .NET for approximate cardinality estimation of large data sets.


πŸš€ Features

  • ⚑ Efficient cardinality estimation with HyperLogLog algorithm
  • 🧠 Built-in support for multiple types: string, int, Guid, and more via custom hashers
  • πŸ”§ Easy to extend with your own IHasher implementations for any data type
  • πŸ§ͺ Optional multiple-run estimation for improved accuracy and reduced variance
  • 🧱 Configurable precision (4–16) with built-in validation
  • πŸ’Ό Fully compatible with .NET Standard for broad platform support

βœ… Accuracy Highlights (based on benchmark tests)

  • Precision 10: < 3% average error up to 100,000 unique items
  • Precision 12: < 1.5% average error up to 100,000 items
  • Precision 14: < 0.7% average error at 100,000 cardinality

πŸ” Duplicate Safety

Handles duplicate values correctly, estimating only unique cardinality. Example:

  • Input: 10,000 identical values
  • Estimated: ~10,000 (error: <1%)

πŸ“¦ Installation

dotnet add package HLL.NET

πŸ§‘β€πŸ’» Usage

using HLL.NET;

var items = new List<string>();
for (int i = 0; i < 10_000; i++)
    items.Add($"user_{i}");

double estimate = HyperLogLog.EstimateWithMultipleRuns(items, runs: 5, precision: 14);

Console.WriteLine($"Estimated unique count: {estimate:F2}");

For more fine-grained control:

var hll = new HyperLogLog<string>(precision: 14);

hll.Add("apple");
hll.Add("banana");
hll.Add("apple");

double estimate = hll.Estimate();
Console.WriteLine($"Estimated: {estimate:F2}");

βœ… Running Tests

dotnet test

Tests are located in the tests/HLL.NET.Tests/ project and cover various edge cases and expected behaviors.


🀝 Contributing

PRs and suggestions welcome! Please:

  1. Fork the repo
  2. Create a feature branch
  3. Add tests if needed
  4. Submit a PR πŸš€

πŸ“„ License

MIT Β© 2025 β€” MCUnderground