Avoid Unstable Sort (#12455)

* dont use unstable sort

* remove comment

* add clippy rule
This commit is contained in:
Shawn Tabrizi
2022-10-11 14:41:43 -04:00
committed by GitHub
parent fbdfa84cd7
commit 023aa03fea
9 changed files with 14 additions and 17 deletions
@@ -112,7 +112,7 @@ impl Stats {
/// Returns the specified percentile for the given data.
/// This is best effort since it ignores the interpolation case.
fn percentile(mut xs: Vec<u64>, p: f64) -> u64 {
xs.sort_unstable();
xs.sort();
let index = (xs.len() as f64 * p).ceil() as usize - 1;
xs[index.clamp(0, xs.len() - 1)]
}