Struct finality_grandpa::voter_set::VoterSet
source · [−]Expand description
A (non-empty) set of voters and associated weights.
A VoterSet
identifies all voters that are permitted to vote in a round
of the protocol and their associated weights. A VoterSet
is furthermore
equipped with a total order, given by the ordering of the voter’s IDs.
Implementations
sourceimpl<Id: Eq + Ord> VoterSet<Id>
impl<Id: Eq + Ord> VoterSet<Id>
sourcepub fn new<I>(weights: I) -> Option<Self> where
Id: Ord + Clone,
I: IntoIterator<Item = (Id, u64)>,
pub fn new<I>(weights: I) -> Option<Self> where
Id: Ord + Clone,
I: IntoIterator<Item = (Id, u64)>,
Create a voter set from a weight distribution produced by the given iterator.
If the distribution contains multiple weights for the same voter ID, they are understood to be partial weights and are accumulated. As a result, the order in which the iterator produces the weights is irrelevant.
Returns None
if the iterator does not yield a valid voter set, which is
the case if it either produced no non-zero weights or, i.e. the voter set
would be empty, or if the total voter weight exceeds u64::MAX
.
sourcepub fn get(&self, id: &Id) -> Option<&VoterInfo>
pub fn get(&self, id: &Id) -> Option<&VoterInfo>
Get the voter info for the voter with the given ID, if any.
sourcepub fn len(&self) -> NonZeroUsize
pub fn len(&self) -> NonZeroUsize
Get the size of the set.
sourcepub fn nth_mod(&self, n: usize) -> (&Id, &VoterInfo)
pub fn nth_mod(&self, n: usize) -> (&Id, &VoterInfo)
Get the nth voter in the set, modulo the size of the set, as per the associated total order.
sourcepub fn nth(&self, n: usize) -> Option<(&Id, &VoterInfo)>
pub fn nth(&self, n: usize) -> Option<(&Id, &VoterInfo)>
Get the nth voter in the set, if any.
Returns None
if n >= len
.
sourcepub fn threshold(&self) -> VoterWeight
pub fn threshold(&self) -> VoterWeight
Get the threshold vote weight required for supermajority w.r.t. this set of voters.
sourcepub fn total_weight(&self) -> VoterWeight
pub fn total_weight(&self) -> VoterWeight
Get the total weight of all voters.
Trait Implementations
impl<Id: Eq + Eq + Ord> Eq for VoterSet<Id>
impl<Id: Eq + Ord> StructuralEq for VoterSet<Id>
impl<Id: Eq + Ord> StructuralPartialEq for VoterSet<Id>
Auto Trait Implementations
impl<Id> RefUnwindSafe for VoterSet<Id> where
Id: RefUnwindSafe,
impl<Id> Send for VoterSet<Id> where
Id: Send,
impl<Id> Sync for VoterSet<Id> where
Id: Sync,
impl<Id> Unpin for VoterSet<Id> where
Id: Unpin,
impl<Id> UnwindSafe for VoterSet<Id> where
Id: UnwindSafe + RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more