Make fn WeightedTreeIndex::try_sample public

This commit is contained in:
Makro 2024-05-07 11:25:40 +01:00 committed by GitHub
parent a2375dceaf
commit b10172f2cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);