Skip to content

Commit b9e7d84

Browse files
authored
use partition_point in WeightedIndex (#1276)
* use partition_point in WeightedIndex * fix partition_point * fix
1 parent fbd9586 commit b9e7d84

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

src/distributions/weighted_index.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,7 @@ where X: SampleUniform + PartialOrd
229229
use ::core::cmp::Ordering;
230230
let chosen_weight = self.weight_distribution.sample(rng);
231231
// Find the first item which has a weight *higher* than the chosen weight.
232-
self.cumulative_weights
233-
.binary_search_by(|w| {
234-
if *w <= chosen_weight {
235-
Ordering::Less
236-
} else {
237-
Ordering::Greater
238-
}
239-
})
240-
.unwrap_err()
232+
self.cumulative_weights.partition_point(|w| w <= &chosen_weight)
241233
}
242234
}
243235

0 commit comments

Comments
 (0)