pub trait NposSolution{
type VoterIndex: UniqueSaturatedInto<usize> + TryInto<usize> + TryFrom<usize> + Debug + Copy + Clone + Bounded + Encode + Ord + PartialOrd + TypeInfo;
type TargetIndex: UniqueSaturatedInto<usize> + TryInto<usize> + TryFrom<usize> + Debug + Copy + Clone + Bounded + Encode + Ord + PartialOrd + TypeInfo;
type Accuracy: PerThing128;
const LIMIT: usize;
// Required methods
fn voter_count(&self) -> usize;
fn edge_count(&self) -> usize;
fn unique_targets(&self) -> Vec<Self::TargetIndex>;
fn remove_voter(&mut self, to_remove: Self::VoterIndex) -> bool;
fn from_assignment<FV, FT, A>(
assignments: &[Assignment<A, Self::Accuracy>],
voter_index: FV,
target_index: FT,
) -> Result<Self, Error>
where A: IdentifierT,
for<'r> FV: Fn(&'r A) -> Option<Self::VoterIndex>,
for<'r> FT: Fn(&'r A) -> Option<Self::TargetIndex>;
fn into_assignment<A: IdentifierT>(
self,
voter_at: impl Fn(Self::VoterIndex) -> Option<A>,
target_at: impl Fn(Self::TargetIndex) -> Option<A>,
) -> Result<Vec<Assignment<A, Self::Accuracy>>, Error>;
fn sort<F>(&mut self, voter_stake: F)
where F: FnMut(&Self::VoterIndex) -> VoteWeight;
fn remove_weakest_sorted<F>(
&mut self,
voter_stake: F,
) -> Option<Self::VoterIndex>
where F: FnMut(&Self::VoterIndex) -> VoteWeight;
fn corrupt(&mut self);
// Provided methods
fn average_edge_count(&self) -> usize { ... }
fn score<A, FS>(
self,
stake_of: FS,
voter_at: impl Fn(Self::VoterIndex) -> Option<A>,
target_at: impl Fn(Self::TargetIndex) -> Option<A>,
) -> Result<ElectionScore, Error>
where for<'r> FS: Fn(&'r A) -> VoteWeight,
A: IdentifierT { ... }
}
Expand description
An opaque index-based, NPoS solution type.
Required Associated Constants§
Required Associated Types§
Sourcetype VoterIndex: UniqueSaturatedInto<usize> + TryInto<usize> + TryFrom<usize> + Debug + Copy + Clone + Bounded + Encode + Ord + PartialOrd + TypeInfo
type VoterIndex: UniqueSaturatedInto<usize> + TryInto<usize> + TryFrom<usize> + Debug + Copy + Clone + Bounded + Encode + Ord + PartialOrd + TypeInfo
The voter type. Needs to be an index (convert to usize).
Sourcetype TargetIndex: UniqueSaturatedInto<usize> + TryInto<usize> + TryFrom<usize> + Debug + Copy + Clone + Bounded + Encode + Ord + PartialOrd + TypeInfo
type TargetIndex: UniqueSaturatedInto<usize> + TryInto<usize> + TryFrom<usize> + Debug + Copy + Clone + Bounded + Encode + Ord + PartialOrd + TypeInfo
The target type. Needs to be an index (convert to usize).
Sourcetype Accuracy: PerThing128
type Accuracy: PerThing128
The weight/accuracy type of each vote.
Required Methods§
Sourcefn voter_count(&self) -> usize
fn voter_count(&self) -> usize
Get the length of all the voters that this type is encoding.
This is basically the same as the number of assignments, or number of active voters.
Sourcefn edge_count(&self) -> usize
fn edge_count(&self) -> usize
Get the total count of edges.
This is effectively in the range of {Self::voter_count
, Self::voter_count
*
Self::LIMIT
}.
Sourcefn unique_targets(&self) -> Vec<Self::TargetIndex>
fn unique_targets(&self) -> Vec<Self::TargetIndex>
Get the number of unique targets in the whole struct.
Once presented with a list of winners, this set and the set of winners must be equal.
Sourcefn remove_voter(&mut self, to_remove: Self::VoterIndex) -> bool
fn remove_voter(&mut self, to_remove: Self::VoterIndex) -> bool
Remove a certain voter.
This will only search until the first instance of to_remove
, and return true. If
no instance is found (no-op), then it returns false.
In other words, if this return true, exactly one element must have been removed self.
Sourcefn from_assignment<FV, FT, A>(
assignments: &[Assignment<A, Self::Accuracy>],
voter_index: FV,
target_index: FT,
) -> Result<Self, Error>where
A: IdentifierT,
for<'r> FV: Fn(&'r A) -> Option<Self::VoterIndex>,
for<'r> FT: Fn(&'r A) -> Option<Self::TargetIndex>,
fn from_assignment<FV, FT, A>(
assignments: &[Assignment<A, Self::Accuracy>],
voter_index: FV,
target_index: FT,
) -> Result<Self, Error>where
A: IdentifierT,
for<'r> FV: Fn(&'r A) -> Option<Self::VoterIndex>,
for<'r> FT: Fn(&'r A) -> Option<Self::TargetIndex>,
Build self from a list of assignments.
Sourcefn into_assignment<A: IdentifierT>(
self,
voter_at: impl Fn(Self::VoterIndex) -> Option<A>,
target_at: impl Fn(Self::TargetIndex) -> Option<A>,
) -> Result<Vec<Assignment<A, Self::Accuracy>>, Error>
fn into_assignment<A: IdentifierT>( self, voter_at: impl Fn(Self::VoterIndex) -> Option<A>, target_at: impl Fn(Self::TargetIndex) -> Option<A>, ) -> Result<Vec<Assignment<A, Self::Accuracy>>, Error>
Convert self into a Vec<Assignment<A, Self::Accuracy>>
Sourcefn sort<F>(&mut self, voter_stake: F)
fn sort<F>(&mut self, voter_stake: F)
Sort self by the means of the given function.
This might be helpful to allow for easier trimming.
Sourcefn remove_weakest_sorted<F>(
&mut self,
voter_stake: F,
) -> Option<Self::VoterIndex>
fn remove_weakest_sorted<F>( &mut self, voter_stake: F, ) -> Option<Self::VoterIndex>
Remove the least staked voter.
This is ONLY sensible to do if Self::sort
has been called on the struct at least once.
Provided Methods§
Sourcefn average_edge_count(&self) -> usize
fn average_edge_count(&self) -> usize
Get the average edge count.
Sourcefn score<A, FS>(
self,
stake_of: FS,
voter_at: impl Fn(Self::VoterIndex) -> Option<A>,
target_at: impl Fn(Self::TargetIndex) -> Option<A>,
) -> Result<ElectionScore, Error>
fn score<A, FS>( self, stake_of: FS, voter_at: impl Fn(Self::VoterIndex) -> Option<A>, target_at: impl Fn(Self::TargetIndex) -> Option<A>, ) -> Result<ElectionScore, Error>
Compute the score of this solution type.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.