Celerity.Cardinality 2.4.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Celerity.Cardinality --version 2.4.0
                    
NuGet\Install-Package Celerity.Cardinality -Version 2.4.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Celerity.Cardinality" Version="2.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Celerity.Cardinality" Version="2.4.0" />
                    
Directory.Packages.props
<PackageReference Include="Celerity.Cardinality" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Celerity.Cardinality --version 2.4.0
                    
#r "nuget: Celerity.Cardinality, 2.4.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Celerity.Cardinality@2.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Celerity.Cardinality&version=2.4.0
                    
Install as a Cake Addin
#tool nuget:?package=Celerity.Cardinality&version=2.4.0
                    
Install as a Cake Tool

Celerity.Cardinality

Mergeable, deterministic distinct-count (approximate COUNT(DISTINCT)) over managed streams — plus a removable dedup filter for sliding windows. Built on Celerity's HyperLogLog, CeleritySet, and CuckooFilter, generic over your key type and a zero-cost inlined hasher.

dotnet add package Celerity.Cardinality

Distinct — exact when small, fixed-memory when large

Counting distinct values with a HashSet<T> stores every value — tens of GB and an eventual OOM at high cardinality. Distinct holds an exact CeleritySet while the count is small (so you get a precise answer for free), then promotes to a fixed ~16 KB HyperLogLog once it crosses a threshold — a run-vs-cannot-run difference: it estimates a billion distinct keys from the same 16 KB it uses for a thousand.

using Celerity.Cardinality;

var uniques = new StringDistinct();
foreach (var e in events)
    uniques.Add(e.UserId);

long n = uniques.Count();          // exact while small, ~0.8% error once large
bool exact = uniques.IsExact;      // true until it promotes

Mergeable for cross-shard / cross-window roll-ups — exact when both stay small, otherwise a HyperLogLog union that is byte-identical across runtimes given a deterministic hasher, so shard sub-totals combine to the same global estimate everywhere:

shardA.Merge(shardB);              // COUNT(DISTINCT) across shards, from ~16 KB each
long global = shardA.Count();

Generic over any key type:

var byId = new Distinct<long, Int64WangNaiveHasher>();

DedupFilter — windowed, removable dedup

When HyperLogLog's error is unacceptable and you need a per-key "have I seen this?" that can also expire, DedupFilter (a Cuckoo filter) gives fixed-memory dedup with no false negatives and — unlike a Bloom filter — removal, so it fits a sliding window:

var dedup = new StringDedupFilter(expectedItems: 100_000);

if (dedup.TryMarkSeen(evt.Id))     // true the first time, false for a repeat
    Process(evt);

dedup.Remove(agedOutId);           // keep the fill bounded to the live window

Why managed (and not a native binding / Redis)

The hot loop is per-element hashing of a managed key through an inlined struct hasher — tens of millions of events/sec that a native HyperLogLog would have to marshal one at a time, and that Redis PFADD would send over the wire per element. Cross-shard merge requires byte-identical register computation, so a fixed managed hasher that hashes identically on every RID is a genuine correctness feature. These run in trimmed / AOT / WASM sidecars where a per-RID native .so is pure tax.

Part of the Celerity family.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.4.1-beta.4 30 7/26/2026
2.4.0 90 7/26/2026
2.3.1-beta.15 45 7/25/2026
2.3.1-beta.8 36 7/23/2026
2.3.1-beta.2 34 7/22/2026
2.3.0 91 7/19/2026
2.2.1-beta.24 57 7/18/2026
2.2.1-beta.18 49 7/14/2026
2.2.1-beta.15 46 7/12/2026