pub struct ReservoirSampler { /* private fields */ }Expand description
Enhanced reservoir sampling implementation based on Vitter’s algorithm
This is a proper implementation of Algorithm R with optimizations:
- True randomness with seedable RNG for reproducibility
- Optimized skip calculation using geometric distribution
- Memory-efficient storage of sample indices
- Support for weighted sampling
Implementations§
Source§impl ReservoirSampler
impl ReservoirSampler
Sourcepub fn seed(capacity: usize, seed: u64) -> Self
pub fn seed(capacity: usize, seed: u64) -> Self
Create a new reservoir sampler with custom seed
Sourcepub fn process_record(&mut self, record_index: usize) -> bool
pub fn process_record(&mut self, record_index: usize) -> bool
Process a new record and decide if it should be included Returns true if the record is selected for the sample
Sourcepub fn get_sample_indices(&self) -> &[usize]
pub fn get_sample_indices(&self) -> &[usize]
Get current sample as a vector of indices
Sourcepub fn sample_size(&self) -> usize
pub fn sample_size(&self) -> usize
Get current sample size
Sourcepub fn get_stats(&self) -> &ReservoirStats
pub fn get_stats(&self) -> &ReservoirStats
Get sampling statistics
Sourcepub fn sampling_ratio(&self) -> f64
pub fn sampling_ratio(&self) -> f64
Calculate current sampling ratio
Sourcepub fn update_efficiency_stats(&mut self)
pub fn update_efficiency_stats(&mut self)
Update efficiency statistics
Trait Implementations§
Source§impl Clone for ReservoirSampler
impl Clone for ReservoirSampler
Source§fn clone(&self) -> ReservoirSampler
fn clone(&self) -> ReservoirSampler
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ReservoirSampler
impl RefUnwindSafe for ReservoirSampler
impl Send for ReservoirSampler
impl Sync for ReservoirSampler
impl Unpin for ReservoirSampler
impl UnsafeUnpin for ReservoirSampler
impl UnwindSafe for ReservoirSampler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more