Expand description
Theta sketch family: cardinality estimation plus set operations (union, intersection, a-not-b) and Jaccard similarity.
use apache_datasketches::theta::ThetaSketchBuilder;
let mut sketch = ThetaSketchBuilder::new().lg_k(12).build()?;
sketch.update_u64(42);
println!("estimate: {}", sketch.get_estimate());ThetaSketch/ThetaSketchBuilder— the updatable sketch; build withThetaSketchBuilder::new().lg_k(..).resize_factor(..).p(..).build().CompactThetaSketch— an immutable, serializable snapshot produced byThetaSketch::compact,ThetaUnion::get_result, orThetaIntersection::get_result.WrappedCompactThetaSketch— a zero-copy, read-only view over a serialized compact sketch’s bytes, built withWrappedCompactThetaSketch::wrap.ThetaUnion/ThetaUnionBuilder— merges multiple sketches.ThetaIntersection— computes the intersection of sketches fed viaupdate.ThetaAnotB— computes the set difference (items inabut notb).jaccard_similarity/JaccardBounds— estimates the Jaccard index (intersection-over-union) of two sketches.
ThetaSketch, CompactThetaSketch, and WrappedCompactThetaSketch
can all be passed interchangeably (via the sealed ThetaInput trait)
to ThetaUnion::update, ThetaIntersection::update, ThetaAnotB::compute,
and jaccard_similarity.
Structs§
- Compact
Theta Sketch - An immutable, serializable snapshot of a theta sketch. Produced by
super::ThetaSketch::compact, by any set operation’s result (ThetaUnion::get_result,ThetaIntersection::get_result,ThetaAnotB::compute), or bySelf::deserialize. - Jaccard
Bounds - The result of
jaccard_similarity: a confidence interval around the estimated Jaccard index of two theta sketches, in[0.0, 1.0]. - Theta
AnotB - Computes the set difference (“A not B”: items in
abut notb) of two theta sketches viaSelf::compute. Stateless between calls — unlikesuper::ThetaUnion/super::ThetaIntersection, there is no accumulation across repeated calls. - Theta
Intersection - Computes the intersection of theta sketches fed via
Self::update. Unlikesuper::ThetaUnion/super::ThetaAnotB, intersection has no builder — the intersecting universe is defined entirely by the sketches passed toupdate, matching upstream’s plain-constructortheta_intersection. - Theta
Sketch - A mutable, update-only theta sketch: estimates the number of distinct
items added via
update_*. Build one withThetaSketchBuilder. - Theta
Sketch Builder - Builder for
crate::theta::ThetaSketch, mirroring upstream’supdate_theta_sketch::builder.lg_kdefaults to12(theta_constants::DEFAULT_LG_K),resize_factortoResizeFactor::X8,pto1.0(no sampling). The seed is never exposed — every sketch built by this crate always uses upstream’sDEFAULT_SEED. - Theta
Union - A streaming union accumulator over theta sketches. Accepts any of
super::ThetaSketch,CompactThetaSketch, orsuper::WrappedCompactThetaSketchvia the sealedThetaInputtrait. - Theta
Union Builder - Builder for
ThetaUnion, mirroring upstream’stheta_union::builder.lg_kdefaults to12,resize_factortoResizeFactor::X8,pto1.0(no sampling). As withsuper::ThetaSketchBuilder, the seed is never exposed. - Wrapped
Compact Theta Sketch - A zero-copy, read-only view over an already-serialized compact theta
sketch’s bytes, usable directly as set-operation input without a full
super::CompactThetaSketch::deserialize. Build one withSelf::wrap.
Enums§
- Resize
Factor - Controls how aggressively a theta sketch’s internal hash table grows.
Mirrors upstream’s
datasketches::resize_factor. Default isX8, matchingtheta_constants::DEFAULT_RESIZE_FACTOR.
Traits§
- Theta
Input - Any of the three theta sketch types can be fed into a
ThetaUnion,ThetaIntersection,ThetaAnotB, orjaccard_similarity. This trait is sealed — it cannot be implemented outside this crate — since the set-op shims only have concrete overloads for these three exact types.
Functions§
- jaccard_
similarity - Estimates the Jaccard index (intersection-over-union) of two theta
sketches, each of which may independently be a
super::ThetaSketch,super::CompactThetaSketch, orsuper::WrappedCompactThetaSketch.