11 case E::VOTER_ALREADY_EXISTS:
12 return "Voter already exists";
13 case E::INDEX_OUTBOUND:
14 return "Index outbound";
16 return "Unknown error (invalid VoterSet::Error)";
27 list_.emplace_back(voter, weight);
29 return outcome::success();
31 auto r =
map_.emplace(voter,
map_.size());
33 list_.emplace_back(r.first->first, weight);
35 return outcome::success();
41 if (index >=
list_.size()) {
44 auto voter = std::get<0>(
list_[index]);
48 std::optional<std::tuple<VoterSet::Index, VoterSet::Weight>>
53 auto it =
map_.find(voter);
54 if (it ==
map_.end()) {
57 auto index = it->second;
58 BOOST_ASSERT(index <
list_.size());
59 auto weight = std::get<1>(
list_[index]);
60 return std::tuple(index, weight);
67 auto it =
map_.find(voter);
68 if (it ==
map_.end()) {
71 auto index = it->second;
76 const Id &voter)
const {
80 auto it =
map_.find(voter);
81 if (it ==
map_.end()) {
84 auto index = it->second;
85 BOOST_ASSERT(index <
list_.size());
86 auto weight = std::get<1>(
list_[index]);
91 if (index >=
list_.size()) {
94 auto weight = std::get<1>(
list_.at(index));
outcome::result< void > insert(Id voter, Weight weight)
std::optional< Index > voterIndex(const Id &voter) const
std::optional< std::tuple< Index, Weight > > indexAndWeight(const Id &voter) const
crypto::Ed25519PublicKey Id
OUTCOME_CPP_DEFINE_CATEGORY(kagome::consensus::grandpa, VoterSet::Error, e)
std::unordered_map< Id, Index > map_
std::optional< Weight > voterWeight(const Id &voter) const
outcome::result< Id > voterId(Index index) const
std::vector< std::tuple< const Id &, Weight > > list_