Skip to content

Commit

Permalink
Rewrite elected_edges.sort_unstable_by in phragmen (paritytech#4195)
Browse files Browse the repository at this point in the history
* Rewrite phragmen elected_edges.sort_unstable_by

* map -> and_then
  • Loading branch information
expenses authored and bkchr committed Nov 25, 2019
1 parent 1078691 commit 6a063c2
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions primitives/phragmen/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,10 @@ pub(crate) fn do_equalize_float<A>(
e.1 = 0.0;
});

// todo: rewrite.
elected_edges.sort_unstable_by(|x, y|
if let Some(x) = support_map.get(&x.0) {
if let Some(y) = support_map.get(&y.0) {
x.total.partial_cmp(&y.total).unwrap_or(rstd::cmp::Ordering::Equal)
} else {
rstd::cmp::Ordering::Equal
}
} else {
rstd::cmp::Ordering::Equal
}
support_map.get(&x.0)
.and_then(|x| support_map.get(&y.0).and_then(|y| x.total.partial_cmp(&y.total)))
.unwrap_or(rstd::cmp::Ordering::Equal)
);

let mut cumulative_stake = 0.0;
Expand Down

0 comments on commit 6a063c2

Please sign in to comment.