Struct AliasTable

Source
pub struct AliasTable<T, F> { /* private fields */ }
Expand description

An alias table, which uses floating point probabilities of type F and table entries of type T.

Implementations§

Source§

impl<T, F> AliasTable<T, F>

Source

pub fn pick<'a, R: Rng>(&'a self, rng: &mut R) -> &'a T

Pick a random element from the distribution. Samples from the RNG using ind_sample only.

Source

pub fn iter<R: Rng>(&self, rng: R) -> AliasTableIterator<'_, T, F, R>

Given an RNG, produce an iterator that picks random element from the distribution by calling pick repeatedly with the given RNG.

Trait Implementations§

Source§

impl<T, F> Debug for AliasTable<T, F>
where F: Debug,

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T, F> FromIterator<(T, F)> for AliasTable<T, F>
where F: Float + NumCast + One + SampleRange + Sum<F> + Zero + 'a,

Source§

fn from_iter<I: IntoIterator<Item = (T, F)>>(iter: I) -> Self

Construct an alias table from an iterator. Expects a tuple, where the left-hand element is the distribution’s value, and the right-hand element is the value’s weight in the distribution.

Source§

impl<'a, T, F> IntoIterator for &'a AliasTable<T, F>

Source§

fn into_iter(self) -> Self::IntoIter

Produces an iterator that picks random element from the distribution by calling calling pick repeatedly with the thread’s RNG.

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = AliasTableIterator<'a, T, F, ThreadRng>

Which kind of iterator are we turning this into?

Auto Trait Implementations§

§

impl<T, F> Freeze for AliasTable<T, F>
where F: Freeze,

§

impl<T, F> RefUnwindSafe for AliasTable<T, F>

§

impl<T, F> Send for AliasTable<T, F>
where F: Send, T: Send,

§

impl<T, F> Sync for AliasTable<T, F>
where F: Sync, T: Sync,

§

impl<T, F> Unpin for AliasTable<T, F>
where F: Unpin, T: Unpin,

§

impl<T, F> UnwindSafe for AliasTable<T, F>
where F: UnwindSafe, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.