Skip to content

Commit

Permalink
use partition_point in WeightedIndex (#1276)
Browse files Browse the repository at this point in the history
* use partition_point in WeightedIndex

* fix partition_point

* fix
  • Loading branch information
TheIronBorn authored Dec 22, 2022
1 parent fbd9586 commit b9e7d84
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/distributions/weighted_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,7 @@ where X: SampleUniform + PartialOrd
use ::core::cmp::Ordering;
let chosen_weight = self.weight_distribution.sample(rng);
// Find the first item which has a weight *higher* than the chosen weight.
self.cumulative_weights
.binary_search_by(|w| {
if *w <= chosen_weight {
Ordering::Less
} else {
Ordering::Greater
}
})
.unwrap_err()
self.cumulative_weights.partition_point(|w| w <= &chosen_weight)
}
}

Expand Down

0 comments on commit b9e7d84

Please sign in to comment.