Skip to main content

Sketch

Struct Sketch 

Source
pub struct Sketch { /* private fields */ }
Expand description

A bottom-k sketch of the distinct values of a column.

The retained hashes are sorted and deduplicated, so the sketch is a function of the set of values and not of the order they were added in.

Implementations§

Source§

impl Sketch

Source

pub fn new(k: usize) -> Result<Self>

An empty sketch that will keep the k smallest hashes.

§Errors

If k is zero, which would make every estimate a division by nothing.

Source

pub fn of(values: &[&[u8]]) -> Self

A sketch over a column, at the default k.

Source

pub fn add(&mut self, value: &[u8])

Adds a value.

Source

pub fn add_hash(&mut self, hash: u64)

Adds a value that has already been hashed, for a caller that is hashing anyway.

Source

pub fn len(&self) -> usize

How many hashes the sketch is holding.

Source

pub fn is_empty(&self) -> bool

Whether nothing has been added.

Source

pub fn is_exact(&self) -> bool

Whether the sketch saw at most k distinct values, in which case it holds all of them and every count it gives is exact rather than estimated.

Source

pub fn distinct(&self) -> f64

The estimated number of distinct values, which is the exact number when Sketch::is_exact holds.

Source

pub fn union(&self, other: &Self) -> Result<Self>

The union of two sketches, which is the sketch the union of the two columns would have produced.

§Errors

If the two sketches keep a different number of hashes, because then neither one’s threshold applies to the other and no estimate over the pair means anything.

Source

pub fn jaccard(&self, other: &Self) -> Result<f64>

The estimated Jaccard similarity, which is the size of the intersection of the two value sets over the size of their union.

Section 6.4 wants this to decide whether two columns are drawn from the same universe and should share a dictionary. It is not a decision on its own, because two columns can overlap heavily and still be better off apart if one of them is tiny, but it is what prunes 5,460 pairs down to the handful worth measuring properly.

§Errors

As Sketch::union.

Trait Implementations§

Source§

impl Clone for Sketch

Source§

fn clone(&self) -> Sketch

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 Debug for Sketch

Source§

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

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

impl Eq for Sketch

Source§

impl PartialEq for Sketch

Source§

fn eq(&self, other: &Sketch) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Sketch

Auto Trait Implementations§

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.