Struct infinity_sampler::SamplingReservoir
source · 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>
impl<T, const N: usize> SamplingReservoir<T, N>
sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Get the number of currently stored items. Can be from 0 to N-1 and never decreases.
sourcepub fn into_inner(self) -> ([Item<T>; N], InfinitySamplerIndexer<N>)
pub fn into_inner(self) -> ([Item<T>; N], InfinitySamplerIndexer<N>)
Consume self and return the internal components: item buffer and iterator state.
sourcepub fn as_unordered_slice(&self) -> &[InitializedItem<T>]
pub fn as_unordered_slice(&self) -> &[InitializedItem<T>]
Get a view into the occupied part of the internal buffer.
sourcepub fn into_ordered_iter(self) -> ReservoirOrderedIter<T, N> ⓘ
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.
sourcepub fn sampling_rate(&self) -> &SamplingRate
pub fn sampling_rate(&self) -> &SamplingRate
Returns a reference to the current sampling rate.
sourcepub fn sample(&mut self, value: T) -> SamplingOutcome<T>
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.