Skip to main content

apache_datasketches/theta/
mod.rs

1//! Theta sketch family: cardinality estimation plus set operations (union,
2//! intersection, a-not-b) and Jaccard similarity.
3//!
4//! ```
5//! # fn main() -> Result<(), apache_datasketches::SketchError> {
6//! use apache_datasketches::theta::ThetaSketchBuilder;
7//!
8//! let mut sketch = ThetaSketchBuilder::new().lg_k(12).build()?;
9//! sketch.update_u64(42);
10//! println!("estimate: {}", sketch.get_estimate());
11//! # Ok(())
12//! # }
13//! ```
14//!
15//! - [`ThetaSketch`] / [`ThetaSketchBuilder`] — the updatable sketch; build
16//!   with `ThetaSketchBuilder::new().lg_k(..).resize_factor(..).p(..).build()`.
17//! - [`CompactThetaSketch`] — an immutable, serializable snapshot produced
18//!   by `ThetaSketch::compact`, `ThetaUnion::get_result`, or
19//!   `ThetaIntersection::get_result`.
20//! - [`WrappedCompactThetaSketch`] — a zero-copy, read-only view over a
21//!   serialized compact sketch's bytes, built with
22//!   `WrappedCompactThetaSketch::wrap`.
23//! - [`ThetaUnion`] / [`ThetaUnionBuilder`] — merges multiple sketches.
24//! - [`ThetaIntersection`] — computes the intersection of sketches fed via
25//!   `update`.
26//! - [`ThetaAnotB`] — computes the set difference (items in `a` but not
27//!   `b`).
28//! - [`jaccard_similarity`] / [`JaccardBounds`] — estimates the Jaccard
29//!   index (intersection-over-union) of two sketches.
30//!
31//! [`ThetaSketch`], [`CompactThetaSketch`], and [`WrappedCompactThetaSketch`]
32//! can all be passed interchangeably (via the sealed [`ThetaInput`] trait)
33//! to `ThetaUnion::update`, `ThetaIntersection::update`, `ThetaAnotB::compute`,
34//! and [`jaccard_similarity`].
35
36mod a_not_b;
37mod builder;
38mod compact;
39mod input;
40mod intersection;
41mod jaccard;
42mod sketch;
43mod union;
44mod wrapped;
45
46pub use a_not_b::ThetaAnotB;
47pub use builder::{ResizeFactor, ThetaSketchBuilder};
48pub use compact::CompactThetaSketch;
49pub use input::ThetaInput;
50pub use intersection::ThetaIntersection;
51pub use jaccard::{jaccard_similarity, JaccardBounds};
52pub use sketch::ThetaSketch;
53pub use union::{ThetaUnion, ThetaUnionBuilder};
54pub use wrapped::WrappedCompactThetaSketch;