Struct random_wheel::RandomWheel
[−]
[src]
pub struct RandomWheel<T> {
// some fields omitted
}a little implementation of a random-wheel. https://en.wikipedia.org/wiki/Fitness_proportionate_selection
Methods
impl<T> RandomWheel<T>[src]
fn new() -> RandomWheel<T>
create a new empty random-wheel.
fn with_capacity(n: usize) -> RandomWheel<T>
Creates an empty RandomWheel with space for at least n elements.
fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more elements to be inserted in the given Ringbuf.
The collection may reserve more space to avoid frequent reallocations.
fn capacity(&self) -> usize
Returns the number of elements the RandomWheel can hold without reallocating.
fn len(&self) -> usize
returns the number of elements in the wheel.
fn clear(&mut self)
remove all elements in this wheel.
fn is_empty(&self) -> bool
returns true if this wheel is empty else return false.
fn push(&mut self, proba: f32, data: T)
add an element associated with a probability.
fn proba_sum(&self) -> f32
returns total of luck you pushed.
fn peek(&self) -> Option<&T>
returns a ref to the randomly peeked element.
fn pop(&mut self) -> Option<T>
removes a randomly peeked element and return it.