Skip to main content

StreamReservoirSampler

Struct StreamReservoirSampler 

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

Incremental statistics computation for streaming data processing.

This module provides bounded-memory statistical computation using:

  • NumericAccumulator for numerically stable mean/variance/stddev (O(1) memory), shared with the batch paths so every engine reports the same numbers
  • CardinalityEstimator for distinct counts: exact up to EXACT_CARDINALITY_THRESHOLD distinct values, then a HyperLogLog estimate (~16 KB fixed registers)
  • Reservoir sampling for unbiased samples (fixed capacity; total memory depends on the capacity and the length of sampled strings)
  • Streaming text-length tracking with min/max/mean/histogram (O(1) memory)

Implementations§

Source§

impl StreamReservoirSampler

Source

pub fn new(capacity: usize) -> Self

Source

pub fn offer(&mut self, value: String)

Source

pub fn shrink_to(&mut self, new_capacity: usize)

Keep a uniformly chosen new_capacity of the retained values.

A reservoir is a uniform sample as a set, not slot by slot: the values that filled it first keep their slots until replaced, so truncating kept the head of the stream. Under early memory pressure that made the quality sample the first rows of the source. A uniform subset of a uniform sample is a uniform sample, and later offers keep it one.

Source

pub fn samples(&self) -> &[String]

Source

pub fn memory_usage_bytes(&self) -> usize

Source

pub fn merge(&mut self, other: &StreamReservoirSampler)

Fold another sampler in, leaving every value of the combined population equally likely to have survived.

The two reservoirs stand for populations of very different sizes: a partition of a million rows and one of a hundred each hand over at most capacity values. Pooling the reservoirs and subsampling uniformly would let the small partition supply half the merged sample, so sample values, and the patterns inferred from them, would depend on how the input happened to be split. The number of survivors drawn from each side follows the hypergeometric distribution over the two population counts instead, which is the split a single pass would have produced.

A sampler shrunk under memory pressure holds fewer values than its population earns it. Nothing can be conjured in their place, so the shortfall is filled from the other side rather than returning a sample shorter than the capacity allows.

Trait Implementations§

Source§

impl Clone for StreamReservoirSampler

Source§

fn clone(&self) -> Self

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 StreamReservoirSampler

Source§

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

Formats the value using the given formatter. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V