Kagome
Polkadot Runtime Engine in C++17
kagome::consensus::grandpa::VoterSet Struct Referencefinal

#include <voter_set.hpp>

Collaboration diagram for kagome::consensus::grandpa::VoterSet:

Public Types

enum  Error { Error::VOTER_ALREADY_EXISTS = 1, Error::INDEX_OUTBOUND }
 
using Index = size_t
 
using Weight = size_t
 

Public Member Functions

 VoterSet ()=default
 
 VoterSet (VoterSetId id_of_set)
 
outcome::result< void > insert (Id voter, Weight weight)
 
VoterSetId id () const
 
std::optional< std::tuple< Index, Weight > > indexAndWeight (const Id &voter) const
 
outcome::result< IdvoterId (Index index) const
 
std::optional< IndexvoterIndex (const Id &voter) const
 
std::optional< WeightvoterWeight (const Id &voter) const
 
outcome::result< WeightvoterWeight (Index voter_index) const
 
size_t size () const
 
bool empty () const
 
Weight totalWeight () const
 

Private Attributes

VoterSetId id_ {}
 
std::unordered_map< Id, Indexmap_
 
std::vector< std::tuple< const Id &, Weight > > list_
 
size_t total_weight_ {0}
 

Friends

template<class Stream >
Stream & operator<< (Stream &s, const VoterSet &voters)
 
template<class Stream >
Stream & operator>> (Stream &s, VoterSet &voters)
 

Detailed Description

Stores voters with their corresponding weights

Definition at line 19 of file voter_set.hpp.

Member Typedef Documentation

Definition at line 26 of file voter_set.hpp.

Definition at line 27 of file voter_set.hpp.

Member Enumeration Documentation

Enumerator
VOTER_ALREADY_EXISTS 
INDEX_OUTBOUND 

Definition at line 21 of file voter_set.hpp.

Constructor & Destructor Documentation

kagome::consensus::grandpa::VoterSet::VoterSet ( )
default
kagome::consensus::grandpa::VoterSet::VoterSet ( VoterSetId  id_of_set)
explicit

Definition at line 21 of file voter_set.cpp.

Member Function Documentation

bool kagome::consensus::grandpa::VoterSet::empty ( ) const
inline

Definition at line 69 of file voter_set.hpp.

VoterSetId kagome::consensus::grandpa::VoterSet::id ( ) const
inline
Returns
unique voter set membership id

Definition at line 41 of file voter_set.hpp.

std::optional< std::tuple< VoterSet::Index, VoterSet::Weight > > kagome::consensus::grandpa::VoterSet::indexAndWeight ( const Id voter) const

Definition at line 49 of file voter_set.cpp.

outcome::result< void > kagome::consensus::grandpa::VoterSet::insert ( Id  voter,
Weight  weight 
)

Insert voter

Parameters
voterwith
weight

Definition at line 23 of file voter_set.cpp.

size_t kagome::consensus::grandpa::VoterSet::size ( ) const
inline

Definition at line 65 of file voter_set.hpp.

Weight kagome::consensus::grandpa::VoterSet::totalWeight ( ) const
inline
Returns
total weight of all voters

Definition at line 76 of file voter_set.hpp.

outcome::result< Id > kagome::consensus::grandpa::VoterSet::voterId ( Index  index) const

Definition at line 40 of file voter_set.cpp.

std::optional< VoterSet::Index > kagome::consensus::grandpa::VoterSet::voterIndex ( const Id voter) const
Returns
index of
Parameters
voter

Definition at line 63 of file voter_set.cpp.

std::optional< VoterSet::Weight > kagome::consensus::grandpa::VoterSet::voterWeight ( const Id voter) const
Returns
weight of
Parameters
voter

Definition at line 75 of file voter_set.cpp.

outcome::result< VoterSet::Weight > kagome::consensus::grandpa::VoterSet::voterWeight ( Index  voter_index) const
Returns
weight of voter by index
Parameters
voter_index

Definition at line 90 of file voter_set.cpp.

Friends And Related Function Documentation

template<class Stream >
Stream& operator<< ( Stream &  s,
const VoterSet voters 
)
friend

Definition at line 94 of file voter_set.hpp.

template<class Stream >
Stream& operator>> ( Stream &  s,
VoterSet voters 
)
friend

Definition at line 100 of file voter_set.hpp.

Member Data Documentation

VoterSetId kagome::consensus::grandpa::VoterSet::id_ {}
private

Definition at line 81 of file voter_set.hpp.

std::vector<std::tuple<const Id &, Weight> > kagome::consensus::grandpa::VoterSet::list_
private

Definition at line 83 of file voter_set.hpp.

std::unordered_map<Id, Index> kagome::consensus::grandpa::VoterSet::map_
private

Definition at line 82 of file voter_set.hpp.

size_t kagome::consensus::grandpa::VoterSet::total_weight_ {0}
private

Definition at line 84 of file voter_set.hpp.


The documentation for this struct was generated from the following files: