mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
Substitute BTreeMap/BTreeSet generated types for Vec (#459)
* Substitute BTreeMap/BTreeSet for Vec * regen code * cargo fmt * undo test tweak since not substituting bounded things at the mo * add a couple of comments
This commit is contained in:
+4
-37
@@ -242,40 +242,7 @@ impl<T> PhantomDataSendSync<T> {
|
||||
unsafe impl<T> Send for PhantomDataSendSync<T> {}
|
||||
unsafe impl<T> Sync for PhantomDataSendSync<T> {}
|
||||
|
||||
/// [`ElectionScore`] overrides any generated instance of `sp_npos_elections::ElectionScore` found
|
||||
/// in the metadata, so that we can add some extra derives required for it to be used as the key
|
||||
/// in a [`std::collections::BTreeMap`].
|
||||
#[derive(Encode, Decode, Debug, PartialEq, Eq)]
|
||||
pub struct ElectionScore {
|
||||
/// The minimal winner, in terms of total backing stake.
|
||||
///
|
||||
/// This parameter should be maximized.
|
||||
pub minimal_stake: u128,
|
||||
/// The sum of the total backing of all winners.
|
||||
///
|
||||
/// This parameter should maximized
|
||||
pub sum_stake: u128,
|
||||
/// The sum squared of the total backing of all winners, aka. the variance.
|
||||
///
|
||||
/// Ths parameter should be minimized.
|
||||
pub sum_stake_squared: u128,
|
||||
}
|
||||
|
||||
// These are copied from the original impl; they don't affect encoding/decoding but help
|
||||
// to keep the ordering the same if we then work with the decoded results.
|
||||
impl Ord for ElectionScore {
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
// we delegate this to the lexicographic cmp of slices`, and to incorporate that we want the
|
||||
// third element to be minimized, we swap them.
|
||||
[self.minimal_stake, self.sum_stake, other.sum_stake_squared].cmp(&[
|
||||
other.minimal_stake,
|
||||
other.sum_stake,
|
||||
self.sum_stake_squared,
|
||||
])
|
||||
}
|
||||
}
|
||||
impl PartialOrd for ElectionScore {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
/// This represents a key-value collection and is SCALE compatible
|
||||
/// with collections like BTreeMap. This has the same type params
|
||||
/// as `BTreeMap` which allows us to easily swap the two during codegen.
|
||||
pub type KeyedVec<K, V> = Vec<(K, V)>;
|
||||
|
||||
Reference in New Issue
Block a user