pub(crate) fn alternative_majority_committed_index<T: AckedIndexer>(
    c: MajorityConfig,
    l: &T,
) -> Index {
    if c.is_empty() {
        return u64::MAX;
    }
    let mut id_to_idx = HashMap::new();
    c.votes.iter().for_each(|node| {
        if let Some(idx) = l.acked_index(node) {
            id_to_idx.insert(node, idx);
        }
    });

    // Build a map from index to voters who have acked that or any higher index.
    let mut idx_to_votes = HashMap::new();
    id_to_idx.iter().for_each(|(id, idx)| {
        idx_to_votes.insert(idx, 0);
    });

    for (_, idx) in id_to_idx.iter() {
        for (idy, v) in idx_to_votes.iter_mut() {
            if ***idy > **idx {
                continue;
            }
            *v += 1;
        }
    }

    // Find the maximum index that has achieved quorum.
    let q = c.len() / 2 + 1;
    let mut max_quorum_index = Index::default();
    for (idx, n) in idx_to_votes.clone() {
        if n >= q as u64 && *idx > &max_quorum_index {
            max_quorum_index = **idx;
        }
    }
    // println!("---->{:?}, {:?}, quorum: {}, max_quorum_index: {:?}", id_to_idx, idx_to_votes, q, max_quorum_index);
    max_quorum_index
}
// This is an alternative implmentation of (MajorityConfig).CommittedIndex(l).
This is an alternative implmentation of (MajorityConfig).CommittedIndex(l).
This is an alternative implmentation of ( MajorityConfig ) . CommittedIndex ( l ) .
pub(crate) fn alternative_majority_committed_index<T: AckedIndexer>(
    c: MajorityConfig,
    l: &T,
) -> Index {
    if c.is_empty() {
        return u64::MAX;
    }
    let mut id_to_idx = HashMap::new();
    c.votes.iter().for_each(|node| {
        if let Some(idx) = l.acked_index(node) {
            id_to_idx.insert(node, idx);
        }
    });
    // Build a map from index to voters who have acked that or any higher index.
    let mut idx_to_votes = HashMap::new();
    id_to_idx.iter().for_each(|(id, idx)| {
        idx_to_votes.insert(idx, 0);
    });
    for (_, idx) in id_to_idx.iter() {
        for (idy, v) in idx_to_votes.iter_mut() {
            if ***idy > **idx {
                continue;
            }
            *v += 1;
        }
    }
    // Find the maximum index that has achieved quorum.
    let q = c.len() / 2 + 1;
    let mut max_quorum_index = Index::default();
    for (idx, n) in idx_to_votes.clone() {
        if n >= q as u64 && *idx > &max_quorum_index {
            max_quorum_index = **idx;
        }
    }
    // println!("---->{:?}, {:?}, quorum: {}, max_quorum_index: {:?}", id_to_idx, idx_to_votes, q, max_quorum_index);
    max_quorum_index
}
pub ( crate ) fn alternative_majority_committed_index < T : AckedIndexer > ( c : MajorityConfig , l : & T , ) -> Index { if c . is_empty ( ) { return u64 :: MAX ; } let mut id_to_idx = HashMap :: new ( ) ; c . votes . iter ( ) . for_each ( | node | { if let Some ( idx ) = l . acked_index ( node ) { id_to_idx . insert ( node , idx ) ; } } ) ; // Build a map from index to voters who have acked that or any higher index. let mut idx_to_votes = HashMap :: new ( ) ; id_to_idx . iter ( ) . for_each ( | ( id , idx ) | { idx_to_votes . insert ( idx , 0 ) ; } ) ; for ( _ , idx ) in id_to_idx . iter ( ) { for ( idy , v ) in idx_to_votes . iter_mut ( ) { if * * * idy > * * idx { continue ; } * v += 1 ; } } // Find the maximum index that has achieved quorum. let q = c . len ( ) / 2 + 1 ; let mut max_quorum_index = Index :: default ( ) ; for ( idx , n ) in idx_to_votes . clone ( ) { if n >= q as u64 && * idx > & max_quorum_index { max_quorum_index = * * idx ; } } // println!("---->{:?}, {:?}, quorum: {}, max_quorum_index: {:?}", id_to_idx, idx_to_votes, q, max_quorum_index); max_quorum_index }
This is an alternative implmentation of (MajorityConfig).CommittedIndex(l).
This is an alternative implmentation of ( MajorityConfig ) . CommittedIndex ( l ) .
c
MajorityConfig
l
&T