Expand description
§Apache® DataSketches™ Core Rust Library Component
This crate provides compact, mergeable summaries for answering queries over large data streams. It implements a subset of the algorithms available in the other Apache DataSketches language components.
§Enabling sketches
Sketch implementations are opt-in Cargo features; this crate enables none by default. Enable only the algorithms an application uses:
cargo add datasketches --features hll,thetaEach feature exposes a same-named module. For example, hll exposes datasketches::hll and
tdigest exposes datasketches::tdigest.
§Choosing a sketch
- Use
bloomfor probabilistic membership queries. - Use
countminfor point-frequency estimates andfrequenciesfor discovering heavy hitters. - Use
hllfor fast distinct counts,cpcfor compact serialized distinct counts, orthetawhen set operations are required. - Use
reqortdigestfor ranks and quantiles. REQ targets configurable high- or low-rank accuracy; T-Digest emphasizes distribution tails. - Use
tuplewhen retained Theta keys need application-defined summaries.
See each module’s documentation for accuracy, memory, serialization, and update examples.
§Cross-language hashing
Compatible serialization does not by itself make ordinary Rust Hash
input compatible with Java, C++, or Go. Rust strings and slices include type-specific framing,
and short integers require different widening rules for different sketch families. When
sketches must represent the same updates across languages, use the wrappers in hash::value:
raw_bytesfor byte and string contents;canonical_floatfor floating-point values;sign_extendfor short integers used with HLL and CPC;natural_extendfor short integers used with Bloom filters.
Other DataSketches implementations skip empty strings rather than hashing them. Check for empty input before updating when that cross-language behavior is required.
Modules§
- bloom
bloom - Bloom Filter implementation for probabilistic set membership testing.
- codec
- Codec utilities for datasketches crate.
- common
- Data structures and functions that may be used across all the sketch families.
- countmin
countmin - CountMin sketch implementation for frequency estimation.
- cpc
cpc - Compressed Probabilistic Counting sketch.
- error
- Error types for DataSketches operations.
- frequencies
frequencies - Frequency sketches for finding heavy hitters in data streams.
- hash
- Hashing support for sketches.
- hll
hll - HyperLogLog sketch implementation for cardinality estimation.
- req
req - Relative Error Quantiles (REQ) sketch.
- tdigest
tdigest - T-Digest implementation for estimating quantiles and ranks.
- theta
thetaand (thetaortuple) - Theta sketch implementation for cardinality estimation.
- thetacommon
thetaortuple - Data structures and functions that may be used across all the Theta sketch family.
- tuple
tupleand (thetaortuple) - Tuple sketch implementation.