Skip to main content

apache_datasketches/
lib.rs

1//! Safe, idiomatic Rust bindings for [Apache DataSketches](https://github.com/apache/datasketches-cpp),
2//! built via the `cxx` crate over the raw
3//! [`apache-datasketches-sys`](https://docs.rs/apache-datasketches-sys) bridge.
4//!
5//! All four sketch families are enabled by default. To compile only the ones
6//! you need, disable default features and name them:
7//!
8//! ```toml
9//! apache-datasketches = { version = "0.2", default-features = false, features = ["hll"] }
10//! ```
11//!
12//! Unused families cost nothing at runtime — the linker drops what you do not
13//! call — so opting out buys C++ compile time, not a smaller binary.
14//!
15//! The families:
16//!
17//! - `hll` (feature `hll`) — HyperLogLog cardinality estimation (sketch +
18//!   union).
19//! - `theta` (feature `theta`) — cardinality estimation plus set
20//!   operations: union, intersection, a-not-b, and Jaccard similarity.
21//! - `cpc` (feature `cpc`) — Compressed Probabilistic Counting
22//!   cardinality estimation with a more compact serialized form (sketch +
23//!   union only; no set operations beyond union).
24//! - `tuple` (feature `tuple`) — Tuple sketches, in two shapes. The
25//!   ArrayOfDoubles form carries a fixed-width array of `f64` per distinct
26//!   key (summed on collision); the generic form in `tuple::generic` carries
27//!   a summary type you define in Rust. Both support union, intersection,
28//!   a-not-b, and Jaccard similarity.
29//!
30//! (Module-level docs for each feature are only linked above when built
31//! with that feature enabled — see `hll`/`theta`/`cpc`/`tuple` in the
32//! sidebar.)
33//!
34//! See each module's documentation for usage examples, or the crate's
35//! `examples/` directory for complete runnable demos.
36
37#![warn(missing_docs)]
38
39// Disabling default features without naming a family leaves nothing behind
40// but `SketchError`. That used to compile silently; say so instead.
41#[cfg(not(any(feature = "hll", feature = "theta", feature = "cpc", feature = "tuple")))]
42compile_error!(
43    "apache-datasketches: no sketch family is enabled, so this crate exposes nothing. \
44     Enable at least one of the `hll`, `theta`, `cpc`, or `tuple` features, or drop \
45     `default-features = false`."
46);
47
48pub mod error;
49
50#[cfg(feature = "hll")]
51pub mod hll;
52
53#[cfg(feature = "theta")]
54pub mod theta;
55
56#[cfg(feature = "cpc")]
57pub mod cpc;
58
59#[cfg(feature = "tuple")]
60pub mod tuple;
61
62pub use error::SketchError;