pub struct CompactTupleSketch<S> { /* private fields */ }tuple and (crate features theta or tuple) only.Expand description
Compact (immutable) Tuple sketch.
This is the serialization-friendly form: a compact array of retained hash-summary pairs plus theta and a 16-bit seed hash. It can be ordered (sorted ascending by hash) or unordered.
Implementations§
Source§impl<S> CompactTupleSketch<S>
impl<S> CompactTupleSketch<S>
Sourcepub fn as_view(&self) -> TupleSketchView<'_, S>
pub fn as_view(&self) -> TupleSketchView<'_, S>
Returns a read-only view accepted by Tuple set operations.
Sourcepub fn is_estimation_mode(&self) -> bool
pub fn is_estimation_mode(&self) -> bool
Returns true if the sketch is in estimation mode.
Sourcepub fn num_retained(&self) -> usize
pub fn num_retained(&self) -> usize
Returns the number of retained entries.
Sourcepub fn is_ordered(&self) -> bool
pub fn is_ordered(&self) -> bool
Returns true if retained entries are ordered (sorted ascending by hash).
Sourcepub fn iter(&self) -> impl Iterator<Item = &TupleEntry<S>> + '_
pub fn iter(&self) -> impl Iterator<Item = &TupleEntry<S>> + '_
Returns an iterator over retained entries.
Sourcepub fn lower_bound(&self, num_std_dev: NumStdDev) -> f64
pub fn lower_bound(&self, num_std_dev: NumStdDev) -> f64
Returns the approximate lower error bound given the number of standard deviations.
Sourcepub fn upper_bound(&self, num_std_dev: NumStdDev) -> f64
pub fn upper_bound(&self, num_std_dev: NumStdDev) -> f64
Returns the approximate upper error bound given the number of standard deviations.
Sourcepub fn estimated_size(&self) -> usize
pub fn estimated_size(&self) -> usize
Returns the estimated size of the sketch in bytes.
Sourcepub fn serialize(&self) -> Vec<u8> ⓘwhere
S: TupleSummaryValue,
pub fn serialize(&self) -> Vec<u8> ⓘwhere
S: TupleSummaryValue,
Serializes this sketch into the compact Tuple binary format.
Each summary is encoded by its TupleSummaryValue implementation. The layout matches the
Java/C++ Tuple sketches, so the output can be read by those implementations given a
compatible summary encoding.
§Examples
use datasketches::tuple::DefaultUpdatePolicy;
use datasketches::tuple::TupleSketchBuilder;
let policy = DefaultUpdatePolicy::<u64>::default();
let mut sketch = TupleSketchBuilder::new(policy).build().unwrap();
sketch.update("apple", 1);
let bytes = sketch.compact(true).serialize();
assert!(!bytes.is_empty());Sourcepub fn deserialize(bytes: &[u8]) -> Result<Self, Error>where
S: TupleSummaryValue,
pub fn deserialize(bytes: &[u8]) -> Result<Self, Error>where
S: TupleSummaryValue,
Deserializes a compact Tuple sketch using the default seed.
§Errors
Returns InvalidData if the image is malformed, its seed hash does not match the default
seed, or a summary cannot be decoded by S.
Sourcepub fn deserialize_with_seed(bytes: &[u8], seed: u64) -> Result<Self, Error>where
S: TupleSummaryValue,
pub fn deserialize_with_seed(bytes: &[u8], seed: u64) -> Result<Self, Error>where
S: TupleSummaryValue,
Deserializes a compact Tuple sketch using the provided expected seed.
§Errors
Returns InvalidData if the bytes are truncated, the family/serial version/sketch type are
unexpected, the seed hash does not match, the supplied seed computes to the reserved zero
seed hash, or an entry is corrupted.
Trait Implementations§
Source§impl<S: Clone> Clone for CompactTupleSketch<S>
impl<S: Clone> Clone for CompactTupleSketch<S>
Source§fn clone(&self) -> CompactTupleSketch<S>
fn clone(&self) -> CompactTupleSketch<S>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more