Skip to content

Commit

Permalink
Name field better
Browse files Browse the repository at this point in the history
Signed-off-by: Justus Fluegel <[email protected]>
  • Loading branch information
JustusFluegel committed Mar 5, 2024
1 parent f8b8b77 commit 41b044a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/distributions/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,25 @@ use alloc::string::String;
pub struct Slice<'a, T> {
slice: &'a [T],
range: Uniform<usize>,
choices: NonZeroUsize,
num_choices: NonZeroUsize,
}

impl<'a, T> Slice<'a, T> {
/// Create a new `Slice` instance which samples uniformly from the slice.
/// Returns `Err` if the slice is empty.
pub fn new(slice: &'a [T]) -> Result<Self, EmptySlice> {
let len = NonZeroUsize::new(slice.len()).ok_or(EmptySlice)?;
let num_choices = NonZeroUsize::new(slice.len()).ok_or(EmptySlice)?;

Ok(Self {
slice,
range: Uniform::new(0, len.get()).unwrap(),
choices: len,
range: Uniform::new(0, num_choices.get()).unwrap(),
num_choices,
})
}

/// Returns the count of choices in this distribution
pub fn num_choices(&self) -> NonZeroUsize {
self.choices
self.num_choices
}
}

Expand Down

0 comments on commit 41b044a

Please sign in to comment.