Skip to main content

Module theta

Module theta 

Source
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, CompactThetaSketch, and WrappedCompactThetaSketch can all be passed interchangeably (via the sealed ThetaInput trait) to ThetaUnion::update, ThetaIntersection::update, ThetaAnotB::compute, and jaccard_similarity.

Structs§

CompactThetaSketch
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 by Self::deserialize.
JaccardBounds
The result of jaccard_similarity: a confidence interval around the estimated Jaccard index of two theta sketches, in [0.0, 1.0].
ThetaAnotB
Computes the set difference (“A not B”: items in a but not b) of two theta sketches via Self::compute. Stateless between calls — unlike super::ThetaUnion/super::ThetaIntersection, there is no accumulation across repeated calls.
ThetaIntersection
Computes the intersection of theta sketches fed via Self::update. Unlike super::ThetaUnion/super::ThetaAnotB, intersection has no builder — the intersecting universe is defined entirely by the sketches passed to update, matching upstream’s plain-constructor theta_intersection.
ThetaSketch
A mutable, update-only theta sketch: estimates the number of distinct items added via update_*. Build one with ThetaSketchBuilder.
ThetaSketchBuilder
Builder for crate::theta::ThetaSketch, mirroring upstream’s update_theta_sketch::builder. lg_k defaults to 12 (theta_constants::DEFAULT_LG_K), resize_factor to ResizeFactor::X8, p to 1.0 (no sampling). The seed is never exposed — every sketch built by this crate always uses upstream’s DEFAULT_SEED.
ThetaUnion
A streaming union accumulator over theta sketches. Accepts any of super::ThetaSketch, CompactThetaSketch, or super::WrappedCompactThetaSketch via the sealed ThetaInput trait.
ThetaUnionBuilder
Builder for ThetaUnion, mirroring upstream’s theta_union::builder. lg_k defaults to 12, resize_factor to ResizeFactor::X8, p to 1.0 (no sampling). As with super::ThetaSketchBuilder, the seed is never exposed.
WrappedCompactThetaSketch
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 with Self::wrap.

Enums§

ResizeFactor
Controls how aggressively a theta sketch’s internal hash table grows. Mirrors upstream’s datasketches::resize_factor. Default is X8, matching theta_constants::DEFAULT_RESIZE_FACTOR.

Traits§

ThetaInput
Any of the three theta sketch types can be fed into a ThetaUnion, ThetaIntersection, ThetaAnotB, or jaccard_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, or super::WrappedCompactThetaSketch.