目录

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

  • 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.

License

Apache-2.0.

关于
58.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号