Celerity.Cardinality
2.4.0
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
<PackageReference Include="Celerity.Cardinality" Version="2.4.0" />
<PackageVersion Include="Celerity.Cardinality" Version="2.4.0" />
<PackageReference Include="Celerity.Cardinality" />
paket add Celerity.Cardinality --version 2.4.0
#r "nuget: Celerity.Cardinality, 2.4.0"
#:package Celerity.Cardinality@2.4.0
#addin nuget:?package=Celerity.Cardinality&version=2.4.0
#tool nuget:?package=Celerity.Cardinality&version=2.4.0
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 | Versions 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. |
-
net10.0
- Celerity.Collections (>= 2.4.0)
-
net8.0
- Celerity.Collections (>= 2.4.0)
-
net9.0
- Celerity.Collections (>= 2.4.0)
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 |