Make fn WeightedTreeIndex::try_sample public
This commit is contained in:
parent
a2375dceaf
commit
b10172f2cf
@ -247,7 +247,7 @@ impl<W: Clone + PartialEq + PartialOrd + SampleUniform + SubAssign<W> + Weight>
|
|||||||
///
|
///
|
||||||
/// Returns an error if there are no elements or all weights are zero. This
|
/// Returns an error if there are no elements or all weights are zero. This
|
||||||
/// is unlike [`Distribution::sample`], which panics in those cases.
|
/// is unlike [`Distribution::sample`], which panics in those cases.
|
||||||
fn try_sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Result<usize, WeightError> {
|
pub fn try_sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Result<usize, WeightError> {
|
||||||
let total_weight = self.subtotals.first().cloned().unwrap_or(W::ZERO);
|
let total_weight = self.subtotals.first().cloned().unwrap_or(W::ZERO);
|
||||||
if total_weight == W::ZERO {
|
if total_weight == W::ZERO {
|
||||||
return Err(WeightError::InsufficientNonZero);
|
return Err(WeightError::InsufficientNonZero);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user