Attempt to remove the where bounds in arithmetic. (#7933)

* Attempt to remove the where bounds.

* Fix further and further.

* Format better.

* Update primitives/npos-elections/src/lib.rs

* fix build

* remove unused
This commit is contained in:
Kian Paimani
2021-01-21 09:39:30 +00:00
committed by GitHub
parent 9031c35114
commit 0dd8cd6277
11 changed files with 125 additions and 139 deletions
+8 -13
View File
@@ -75,7 +75,7 @@
use sp_arithmetic::{
traits::{Bounded, UniqueSaturatedInto, Zero},
InnerOf, Normalizable, PerThing, Rational128, ThresholdOrd,
Normalizable, PerThing, Rational128, ThresholdOrd,
};
use sp_std::{
cell::RefCell,
@@ -209,7 +209,6 @@ pub trait CompactSolution: Sized {
where
for<'r> FS: Fn(&'r A) -> VoteWeight,
A: IdentifierT,
ExtendedBalance: From<InnerOf<Self::Accuracy>>,
{
let ratio = self.into_assignment(voter_at, target_at)?;
let staked = helpers::assignment_ratio_to_staked_normalized(ratio, stake_of)?;
@@ -332,14 +331,14 @@ impl<AccountId: IdentifierT> Voter<AccountId> {
/// Note that this might create _un-normalized_ assignments, due to accuracy loss of `P`. Call
/// site might compensate by calling `normalize()` on the returned `Assignment` as a
/// post-precessing.
pub fn into_assignment<P: PerThing>(self) -> Option<Assignment<AccountId, P>>
where
ExtendedBalance: From<InnerOf<P>>,
{
pub fn into_assignment<P: PerThing>(self) -> Option<Assignment<AccountId, P>> {
let who = self.who;
let budget = self.budget;
let distribution = self.edges.into_iter().filter_map(|e| {
let per_thing = P::from_rational_approximation(e.weight, budget);
let distribution = self
.edges
.into_iter()
.filter_map(|e| {
let per_thing = P::from_rational_approximation(e.weight, budget);
// trim zero edges.
if per_thing.is_zero() { None } else { Some((e.who, per_thing)) }
}).collect::<Vec<_>>();
@@ -507,7 +506,6 @@ impl<AccountId> StakedAssignment<AccountId> {
/// can never be re-created and does not mean anything useful anymore.
pub fn into_assignment<P: PerThing>(self) -> Assignment<AccountId, P>
where
ExtendedBalance: From<InnerOf<P>>,
AccountId: IdentifierT,
{
let stake = self.total();
@@ -706,10 +704,7 @@ where
/// greater or less than `that`.
///
/// Note that the third component should be minimized.
pub fn is_score_better<P: PerThing>(this: ElectionScore, that: ElectionScore, epsilon: P) -> bool
where
ExtendedBalance: From<InnerOf<P>>,
{
pub fn is_score_better<P: PerThing>(this: ElectionScore, that: ElectionScore, epsilon: P) -> bool {
match this
.iter()
.zip(that.iter())