From 482671ab2ab1a85a8173f32468f42f29feef3467 Mon Sep 17 00:00:00 2001 From: Theo Butler Date: Thu, 10 Nov 2022 11:49:02 -0500 Subject: [PATCH] Fix sorting in ISA scoring (#245) --- Cargo.lock | 7 +++++++ indexer-selection/Cargo.toml | 1 + indexer-selection/src/score.rs | 17 +++++------------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 634121ef..f236adf9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1088,6 +1088,7 @@ dependencies = [ "lazy_static", "num-traits", "ordered-float", + "permutation", "prelude", "prometheus", "rand_distr", @@ -1632,6 +1633,12 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" +[[package]] +name = "permutation" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df202b0b0f5b8e389955afd5f27b007b00fb948162953f1db9c70d2c7e3157d7" + [[package]] name = "pin-project" version = "1.0.12" diff --git a/indexer-selection/Cargo.toml b/indexer-selection/Cargo.toml index e2645546..fced2fe3 100644 --- a/indexer-selection/Cargo.toml +++ b/indexer-selection/Cargo.toml @@ -14,6 +14,7 @@ itertools = "0.10" lazy_static = "1.4" num-traits = "0.2" ordered-float = "3.0" +permutation = "0.4" prelude = { path = "../prelude" } prometheus = { version = "0.13", default-features = false } rand_distr = "0.4" diff --git a/indexer-selection/src/score.rs b/indexer-selection/src/score.rs index a2fe777c..2e73c595 100644 --- a/indexer-selection/src/score.rs +++ b/indexer-selection/src/score.rs @@ -138,18 +138,11 @@ impl MetaIndexer<'_> { let mut perf_success: V = self.0.iter().map(|f| f.perf_success).collect(); let mut slashable_usd: V = self.0.iter().map(|f| f.slashable_usd).collect(); - let mut order = (0..perf_success.len()).collect::>(); - order.sort_unstable_by_key(|i| NotNan::try_from(perf_success[*i]).unwrap()); - macro_rules! sort_by_perf_success { - ($v:ident) => { - for i in 0..$v.len() { - $v.swap(i, order[i]); - } - }; - } - sort_by_perf_success!(reliability); - sort_by_perf_success!(perf_success); - sort_by_perf_success!(slashable_usd); + let mut permutation = + permutation::sort_unstable_by_key(&perf_success, |n| NotNan::try_from(*n).unwrap()); + permutation.apply_slice_in_place(&mut reliability); + permutation.apply_slice_in_place(&mut perf_success); + permutation.apply_slice_in_place(&mut slashable_usd); // BQN: pf ← ×`1-r let pf = reliability