Skip to main content

CompactTupleSketch

Struct CompactTupleSketch 

Source
pub struct CompactTupleSketch<S> { /* private fields */ }
Available on crate feature 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>

Source

pub fn as_view(&self) -> TupleSketchView<'_, S>

Returns a read-only view accepted by Tuple set operations.

Source

pub fn estimate(&self) -> f64

Returns the cardinality (distinct key count) estimate.

Source

pub fn theta(&self) -> f64

Returns theta as a fraction (0.0 to 1.0).

Source

pub fn theta64(&self) -> u64

Returns theta as u64.

Source

pub fn is_empty(&self) -> bool

Returns true if the sketch is empty.

Source

pub fn is_estimation_mode(&self) -> bool

Returns true if the sketch is in estimation mode.

Source

pub fn num_retained(&self) -> usize

Returns the number of retained entries.

Source

pub fn is_ordered(&self) -> bool

Returns true if retained entries are ordered (sorted ascending by hash).

Source

pub fn seed_hash(&self) -> u16

Returns the 16-bit seed hash.

Source

pub fn iter(&self) -> impl Iterator<Item = &TupleEntry<S>> + '_

Returns an iterator over retained entries.

Source

pub fn lower_bound(&self, num_std_dev: NumStdDev) -> f64

Returns the approximate lower error bound given the number of standard deviations.

Source

pub fn upper_bound(&self, num_std_dev: NumStdDev) -> f64

Returns the approximate upper error bound given the number of standard deviations.

Source

pub fn estimated_size(&self) -> usize

Returns the estimated size of the sketch in bytes.

Source

pub fn serialize(&self) -> Vec<u8>

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());
Source

pub fn deserialize(bytes: &[u8]) -> Result<Self, Error>

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.

Source

pub fn deserialize_with_seed(bytes: &[u8], seed: u64) -> Result<Self, Error>

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>

Source§

fn clone(&self) -> CompactTupleSketch<S>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Debug> Debug for CompactTupleSketch<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, S> From<&'a CompactTupleSketch<S>> for TupleSketchView<'a, S>

Source§

fn from(sketch: &'a CompactTupleSketch<S>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S> Freeze for CompactTupleSketch<S>
where CompactSketchState<TupleEntry<S>>: Freeze,

§

impl<S> RefUnwindSafe for CompactTupleSketch<S>
where CompactSketchState<TupleEntry<S>>: RefUnwindSafe,

§

impl<S> Send for CompactTupleSketch<S>
where CompactSketchState<TupleEntry<S>>: Send,

§

impl<S> Sync for CompactTupleSketch<S>
where CompactSketchState<TupleEntry<S>>: Sync,

§

impl<S> Unpin for CompactTupleSketch<S>
where CompactSketchState<TupleEntry<S>>: Unpin,

§

impl<S> UnsafeUnpin for CompactTupleSketch<S>
where CompactSketchState<TupleEntry<S>>: UnsafeUnpin,

§

impl<S> UnwindSafe for CompactTupleSketch<S>
where CompactSketchState<TupleEntry<S>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.