pub struct SamplingReservoir<T, const N: usize> { /* private fields */ }
Expand description

Infinity Sampler

See the top-level doc for an example.

This struct wraps a RawReservoir adding an autoscaling sampler in front of it. The sampling rate gets halved after every N/2 stored values, which is the same as every N*2^X values observed by the sampler.

Feed the values into the reservoir using sample() and then turn it into an ordered iterator with into_ordered_iter().

The buffer size must be a power of two.

Implementations§

source§

impl<T, const N: usize> SamplingReservoir<T, N>

source

pub const fn capacity(&self) -> usize

Returns N, the capacity of the internal buffer.

source

pub const fn len(&self) -> usize

Get the number of currently stored items. Can be from 0 to N-1 and never decreases.

source

pub fn into_inner(self) -> ([Item<T>; N], InfinitySamplerIndexer<N>)

Consume self and return the internal components: item buffer and iterator state.

source

pub fn as_unordered_slice(&self) -> &[InitializedItem<T>]

Get a view into the occupied part of the internal buffer.

source

pub fn into_ordered_iter(self) -> ReservoirOrderedIter<T, N>

Sort the reservoir in-place, and return an iterator over the items in chronological order - O(N*log(n)).

This is irreversible and consumes the reservoir.

source

pub const fn new() -> Self

Creates a empty reservoir, allocating an uninitialized buffer.

source

pub fn sampling_rate(&self) -> &SamplingRate

Returns a reference to the current sampling rate.

source

pub fn sample(&mut self, value: T) -> SamplingOutcome<T>

Observe a value and possibly store it - O(1).

Performs a sampling “step”, consuming the value and storing it into the buffer, or returning it back if it’s discarded due to the sampling rate.

Trait Implementations§

source§

impl<T: Clone, const N: usize> Clone for SamplingReservoir<T, N>

source§

fn clone(&self) -> SamplingReservoir<T, N>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T, const N: usize> RefUnwindSafe for SamplingReservoir<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> Send for SamplingReservoir<T, N>
where T: Send,

§

impl<T, const N: usize> Sync for SamplingReservoir<T, N>
where T: Sync,

§

impl<T, const N: usize> Unpin for SamplingReservoir<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnwindSafe for SamplingReservoir<T, N>
where T: 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> 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,

§

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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.