fn drop(
        &mut self,
        size: usize,
        keep: &[Pubkey],
        stakes: &HashMap<Pubkey, u64>,
        now: u64,
    ) -> Result</*num purged:*/ usize, CrdsError> {
        if stakes.values().all(|&stake| stake == 0) {
            return Err(CrdsError::UnknownStakes);
        }
        let mut keys: Vec<_> = self
            .records
            .keys()
            .map(|k| (stakes.get(k).copied().unwrap_or_default(), *k))
            .collect();
        if size < keys.len() {
            keys.select_nth_unstable(size);
        }
        let keys: Vec<_> = keys
            .into_iter()
            .take(size)
            .map(|(_, k)| k)
            .filter(|k| !keep.contains(k))
            .flat_map(|k| &self.records[&k])
            .map(|k| self.table.get_index(*k).unwrap().0.clone())
            .collect();
        for key in &keys {
            self.remove(key, now);
        }
        Ok(keys.len())
    }
// Drops 'size' many pubkeys with the lowest stake.
Drops 'size' many pubkeys with the lowest stake.
Drops ' size ' many pubkeys with the lowest stake .
fn drop(
        &mut self,
        size: usize,
        keep: &[Pubkey],
        stakes: &HashMap<Pubkey, u64>,
        now: u64,
    ) -> Result</*num purged:*/ usize, CrdsError> {
        if stakes.values().all(|&stake| stake == 0) {
            return Err(CrdsError::UnknownStakes);
        }
        let mut keys: Vec<_> = self
            .records
            .keys()
            .map(|k| (stakes.get(k).copied().unwrap_or_default(), *k))
            .collect();
        if size < keys.len() {
            keys.select_nth_unstable(size);
        }
        let keys: Vec<_> = keys
            .into_iter()
            .take(size)
            .map(|(_, k)| k)
            .filter(|k| !keep.contains(k))
            .flat_map(|k| &self.records[&k])
            .map(|k| self.table.get_index(*k).unwrap().0.clone())
            .collect();
        for key in &keys {
            self.remove(key, now);
        }
        Ok(keys.len())
    }
fn drop ( & mut self , size : usize , keep : & [ Pubkey ] , stakes : & HashMap < Pubkey , u64 > , now : u64 , ) -> Result < /*num purged:*/ usize , CrdsError > { if stakes . values ( ) . all ( | & stake | stake == 0 ) { return Err ( CrdsError :: UnknownStakes ) ; } let mut keys : Vec < _ > = self . records . keys ( ) . map ( | k | ( stakes . get ( k ) . copied ( ) . unwrap_or_default ( ) , * k ) ) . collect ( ) ; if size < keys . len ( ) { keys . select_nth_unstable ( size ) ; } let keys : Vec < _ > = keys . into_iter ( ) . take ( size ) . map ( | ( _ , k ) | k ) . filter ( | k | ! keep . contains ( k ) ) . flat_map ( | k | & self . records [ & k ] ) . map ( | k | self . table . get_index ( * k ) . unwrap ( ) . 0 . clone ( ) ) . collect ( ) ; for key in & keys { self . remove ( key , now ) ; } Ok ( keys . len ( ) ) }
Drops 'size' many pubkeys with the lowest stake.
Drops ' size ' many pubkeys with the lowest stake .
&mut self
size
usize
keep
&[Pubkey]
stakes
&HashMap<Pubkey, u64>
now
u64