Avoid Unstable Sort (#12455)

* dont use unstable sort

* remove comment

* add clippy rule
This commit is contained in:
Shawn Tabrizi authored and GitHub committed 2022-10-11 18:41:43 +00:00
1 parent fbdfa84cd7
commit 023aa03fea
9 files changed
+14 -17

No files matched your search

@@ -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)]
}