fn shuffle_nodes<'a, R: Rng>(rng: &mut R, nodes: &[&'a Node]) -> Vec<&'a Node> {
    // Nodes are sorted by (stake, pubkey) in descending order.
    let stakes: Vec<u64> = nodes
        .iter()
        .map(|node| node.stake)
        .take_while(|stake| *stake > 0)
        .collect();
    let num_staked = stakes.len();
    let mut out: Vec<_> = WeightedShuffle::new(rng, &stakes)
        .unwrap()
        .map(|i| nodes[i])
        .collect();
    let weights = vec![1; nodes.len() - num_staked];
    out.extend(
        WeightedShuffle::new(rng, &weights)
            .unwrap()
            .map(|i| nodes[i + num_staked]),
    );
    out
}
// Shuffles nodes w.r.t their stakes.
// Unstaked nodes will always appear at the very end.
Shuffles nodes w.r.t their stakes.
Unstaked nodes will always appear at the very end.
Shuffles nodes w . r . t their stakes . Unstaked nodes will always appear at the very end .
fn shuffle_nodes<'a, R: Rng>(rng: &mut R, nodes: &[&'a Node]) -> Vec<&'a Node> {
    // Nodes are sorted by (stake, pubkey) in descending order.
    let stakes: Vec<u64> = nodes
        .iter()
        .map(|node| node.stake)
        .take_while(|stake| *stake > 0)
        .collect();
    let num_staked = stakes.len();
    let mut out: Vec<_> = WeightedShuffle::new(rng, &stakes)
        .unwrap()
        .map(|i| nodes[i])
        .collect();
    let weights = vec![1; nodes.len() - num_staked];
    out.extend(
        WeightedShuffle::new(rng, &weights)
            .unwrap()
            .map(|i| nodes[i + num_staked]),
    );
    out
}
fn shuffle_nodes < ' a , R : Rng > ( rng : & mut R , nodes : & [ & ' a Node ] ) -> Vec < & ' a Node > { // Nodes are sorted by (stake, pubkey) in descending order. let stakes : Vec < u64 > = nodes . iter ( ) . map ( | node | node . stake ) . take_while ( | stake | * stake > 0 ) . collect ( ) ; let num_staked = stakes . len ( ) ; let mut out : Vec < _ > = WeightedShuffle :: new ( rng , & stakes ) . unwrap ( ) . map ( | i | nodes [ i ] ) . collect ( ) ; let weights = vec ! [ 1 nodes len ( ) num_staked ] ; out . extend ( WeightedShuffle :: new ( rng , & weights ) . unwrap ( ) . map ( | i | nodes [ i + num_staked ] ) , ) ; out }
Shuffles nodes w.r.t their stakes.
Shuffles nodes w . r . t their stakes .
rng
&mut R
nodes
&[&'a Node]