pub struct WeightedReservoirSampler<T> { /* private fields */ }Expand description
Maintains a single weighted sample from a stream. Each item is selected with probability proportional to its weight.
Implementations§
Source§impl<T> WeightedReservoirSampler<T>
impl<T> WeightedReservoirSampler<T>
Sourcepub fn sample<R: Rng + ?Sized>(&mut self, weight: u64, item: T, rng: &mut R)
pub fn sample<R: Rng + ?Sized>(&mut self, weight: u64, item: T, rng: &mut R)
Add a new item with a given weight.
Items with weight 0 are ignored.
Sourcepub fn into_selected(self) -> Option<T>
pub fn into_selected(self) -> Option<T>
Take ownership of the selected item.
Sourcepub fn total_weight(&self) -> u64
pub fn total_weight(&self) -> u64
Sum of all positive weights processed so far.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for WeightedReservoirSampler<T>where
T: Freeze,
impl<T> RefUnwindSafe for WeightedReservoirSampler<T>where
T: RefUnwindSafe,
impl<T> Send for WeightedReservoirSampler<T>where
T: Send,
impl<T> Sync for WeightedReservoirSampler<T>where
T: Sync,
impl<T> Unpin for WeightedReservoirSampler<T>where
T: Unpin,
impl<T> UnwindSafe for WeightedReservoirSampler<T>where
T: UnwindSafe,
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