pub struct AliasTable<T> { /* private fields */ }Expand description
Generic alias table for O(1) weighted sampling.
Construct with AliasTable::from_weights or AliasTable::uniform,
then sample with AliasTable::sample.
Implementations§
Source§impl<T: Clone> AliasTable<T>
impl<T: Clone> AliasTable<T>
Sourcepub fn from_weights(outcomes: &[T], weights: &[f64]) -> Self
pub fn from_weights(outcomes: &[T], weights: &[f64]) -> Self
Build an alias table from outcomes and their weights.
Weights do not need to be normalized — they are scaled internally. All weights must be non-negative; at least one must be positive.
Sourcepub fn uniform(outcomes: &[T]) -> Self
pub fn uniform(outcomes: &[T]) -> Self
Build a uniform alias table (all outcomes equally weighted).
Auto Trait Implementations§
impl<T> Freeze for AliasTable<T>
impl<T> RefUnwindSafe for AliasTable<T>where
Vec<AliasSlot<T>>: RefUnwindSafe,
impl<T> Send for AliasTable<T>
impl<T> Sync for AliasTable<T>
impl<T> Unpin for AliasTable<T>
impl<T> UnsafeUnpin for AliasTable<T>where
Vec<AliasSlot<T>>: UnsafeUnpin,
impl<T> UnwindSafe for AliasTable<T>where
Vec<AliasSlot<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