Trait tp_npos_elections::CompactSolution [−][src]
A common interface for all compact solutions.
See [tp-npos-elections-compact
] for more info.
Associated Types
type Voter: UniqueSaturatedInto<usize> + TryInto<usize> + TryFrom<usize> + Debug + Copy + Clone
[src]
The voter type. Needs to be an index (convert to usize).
type Target: UniqueSaturatedInto<usize> + TryInto<usize> + TryFrom<usize> + Debug + Copy + Clone
[src]
The target type. Needs to be an index (convert to usize).
type Accuracy: PerThing128
[src]
The weight/accuracy type of each vote.
Associated Constants
Loading content...Required methods
fn from_assignment<FV, FT, A>(
assignments: Vec<Assignment<A, Self::Accuracy>>,
voter_index: FV,
target_index: FT
) -> Result<Self, Error> where
A: IdentifierT,
FV: Fn(&'r A) -> Option<Self::Voter>,
FT: Fn(&'r A) -> Option<Self::Target>,
[src]
assignments: Vec<Assignment<A, Self::Accuracy>>,
voter_index: FV,
target_index: FT
) -> Result<Self, Error> where
A: IdentifierT,
FV: Fn(&'r A) -> Option<Self::Voter>,
FT: Fn(&'r A) -> Option<Self::Target>,
Build self from a assignments: Vec<Assignment<A, Self::Accuracy>>
.
fn into_assignment<A: IdentifierT>(
self,
voter_at: impl Fn(Self::Voter) -> Option<A>,
target_at: impl Fn(Self::Target) -> Option<A>
) -> Result<Vec<Assignment<A, Self::Accuracy>>, Error>
[src]
self,
voter_at: impl Fn(Self::Voter) -> Option<A>,
target_at: impl Fn(Self::Target) -> Option<A>
) -> Result<Vec<Assignment<A, Self::Accuracy>>, Error>
Convert self into a Vec<Assignment<A, Self::Accuracy>>
fn voter_count(&self) -> usize
[src]
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.
fn edge_count(&self) -> usize
[src]
Get the total count of edges.
This is effectively in the range of {Self::voter_count
, Self::voter_count
*
Self::LIMIT
}.
fn unique_targets(&self) -> Vec<Self::Target>
[src]
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.
fn remove_voter(&mut self, to_remove: Self::Voter) -> bool
[src]
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 from
self.len()
.
Provided methods
fn average_edge_count(&self) -> usize
[src]
Get the average edge count.
fn score<A, FS>(
self,
winners: &[A],
stake_of: FS,
voter_at: impl Fn(Self::Voter) -> Option<A>,
target_at: impl Fn(Self::Target) -> Option<A>
) -> Result<ElectionScore, Error> where
FS: Fn(&'r A) -> VoteWeight,
A: IdentifierT,
[src]
self,
winners: &[A],
stake_of: FS,
voter_at: impl Fn(Self::Voter) -> Option<A>,
target_at: impl Fn(Self::Target) -> Option<A>
) -> Result<ElectionScore, Error> where
FS: Fn(&'r A) -> VoteWeight,
A: IdentifierT,
Compute the score of this compact solution type.