Expand description
CPC (Compressed Probabilistic Counting) sketch family: cardinality estimation with a more compact serialized form than HLL or Theta.
Unlike the theta module, CPC has no set operations beyond union — no
intersection, a-not-b, or Jaccard similarity.
use apache_datasketches::cpc::CpcSketchBuilder;
let mut sketch = CpcSketchBuilder::new().lg_k(11).build()?;
sketch.update_u64(42);
println!("estimate: {}", sketch.get_estimate());CpcSketch/CpcSketchBuilder— the sketch; build withCpcSketchBuilder::new().lg_k(..).build().CpcUnion/CpcUnionBuilder— merges multiple sketches.get_max_serialized_size_bytes— the estimated maximum compressed serialized size, in bytes, for a givenlg_k.init— eagerly initializes CPC’s global decompression tables, as a one-time latency optimization; see its own doc comment for details.
Structs§
- CpcSketch
- A CPC (Compressed Probabilistic Counting) sketch: estimates the number
of distinct items added via
update_*. Unlike Theta’sThetaSketch, there is no separate compact/wrapped variant — this single type is both the mutable/update type and the serializable type, since CPC’s serialized form is always compressed by construction. Build one withCpcSketchBuilder. - CpcSketch
Builder - Builder for
crate::cpc::CpcSketch, mirroring upstream’scpc_sketch_allocconstructor.lg_kdefaults to11(cpc_constants::DEFAULT_LG_K). The seed is never exposed — every sketch built by this crate always uses upstream’sDEFAULT_SEED. - CpcUnion
- Merges multiple
CpcSketches into one, e.g. combining per-shard or per-day counts into a total distinct count across all of them. Build one withCpcUnionBuilder. - CpcUnion
Builder - Builder for
crate::cpc::CpcUnion, mirroring upstream’scpc_union_allocconstructor.lg_kdefaults to11(cpc_constants::DEFAULT_LG_K). The seed is never exposed, same asCpcSketchBuilder.
Functions§
- get_
max_ serialized_ size_ bytes - The estimated maximum compressed serialized size, in bytes, of a CPC
sketch built with the given
lg_k. Useful for pre-allocating buffers. - init
- Eagerly initializes CPC’s global decompression tables, used during serialization/deserialization.