MoonCardinalityKit is a MoonBit foundation library for approximate distinct-count analysis over streams.
It is useful when a project needs to estimate UV, active device count, distinct trace IDs, unique error signatures, or unique keys in data-quality checks without storing every raw value forever.
What It Solves
exact distinct counting for small sets
approximate cardinality estimation for larger streams
mergeable sketches for sharded logs or distributed jobs
stable basis-point error reporting
sketch diagnostics for saturation, duplicate ratio, and rebucket signals
JSON summaries for CLI, dashboard, and regression snapshots
Why It Is Not A Duplicate
The project is not a hash library, not a bitmap index, not a database, and not a charting tool. It focuses on a reusable analytics primitive: compact distinct-count sketches that can sit under monitoring systems, log analyzers, event pipelines, and data-quality tools.
Core API
SketchConfig::new(buckets, exact_limit)
CardinalitySketch::new(config)
add(sketch, value)
add_many(sketch, values)
estimate(sketch)
merge(left, right)
evaluate(values, sketch)
sketch.diagnostics()
Estimate::to_json()
AccuracyReport::to_json()
Quick Start
let values = demo_values()
let sketch = CardinalitySketch::new(default_config()).add_many(values)
let estimate = sketch.estimate()
println(estimate.to_json())
Run:
moon check --target all
moon test --target wasm
moon test --target wasm-gc
moon run cmd/main
Boundary
MoonCardinalityKit does not collect logs, store events, render dashboards, or guarantee cryptographic hashing. It provides deterministic MoonBit data structures and algorithms for distinct-count estimation.
MoonCardinalityKit
MoonCardinalityKit is a MoonBit foundation library for approximate distinct-count analysis over streams.
It is useful when a project needs to estimate UV, active device count, distinct trace IDs, unique error signatures, or unique keys in data-quality checks without storing every raw value forever.
What It Solves
Why It Is Not A Duplicate
The project is not a hash library, not a bitmap index, not a database, and not a charting tool. It focuses on a reusable analytics primitive: compact distinct-count sketches that can sit under monitoring systems, log analyzers, event pipelines, and data-quality tools.
Core API
SketchConfig::new(buckets, exact_limit)CardinalitySketch::new(config)add(sketch, value)add_many(sketch, values)estimate(sketch)merge(left, right)evaluate(values, sketch)sketch.diagnostics()Estimate::to_json()AccuracyReport::to_json()Quick Start
Run:
Boundary
MoonCardinalityKit does not collect logs, store events, render dashboards, or guarantee cryptographic hashing. It provides deterministic MoonBit data structures and algorithms for distinct-count estimation.
License
Apache-2.0.