// Try to update an item in account_maps. If the account is not
// already present, then the function will return back Some(account_info) which
// the caller can then take the write lock and do an 'insert' with the item.
// It returns None if the item is already present and thus successfully updated.
Try to update an item in account_maps. If the account is not
already present, then the function will return back Some(account_info) which
the caller can then take the write lock and do an 'insert' with the item.
It returns None if the item is already present and thus successfully updated.
Try to update an item in account_maps . If the account is not already present then the function will return back Some ( account_info ) which the caller can then take the write lock and do an ' insert ' with the item . It returns None if the item is already present and thus successfully updated .
pub fn update(
        &self,
        slot: Slot,
        pubkey: &Pubkey,
        account_info: T,
        reclaims: &mut SlotList<T>,
    ) -> Option<T> {
        if let Some(lock) = self.account_maps.get(pubkey) {
            let list = &mut lock.1.write().unwrap();
            // filter out other dirty entries from the same slot
            let mut same_slot_previous_updates: Vec<(usize, (Slot, &T))> = list
                .iter()
                .enumerate()
                .filter_map(|(i, (s, value))| {
                    if *s == slot {
                        Some((i, (*s, value)))
                    } else {
                        None
                    }
                })
                .collect();
            assert!(same_slot_previous_updates.len() <= 1);
            if let Some((list_index, (s, previous_update_value))) = same_slot_previous_updates.pop()
            {
                reclaims.push((s, previous_update_value.clone()));
                list.remove(list_index);
            } else {
                // Only increment ref count if the account was not prevously updated in this slot
                lock.0.fetch_add(1, Ordering::Relaxed);
            }
            list.push((slot, account_info));
            None
        } else {
            Some(account_info)
        }
    }
pub fn update ( & self , slot : Slot , pubkey : & Pubkey , account_info : T , reclaims : & mut SlotList < T > , ) -> Option < T > { if let Some ( lock ) = self . account_maps . get ( pubkey ) { let list = & mut lock . 1 . write ( ) . unwrap ( ) ; // filter out other dirty entries from the same slot let mut same_slot_previous_updates : Vec < ( usize , ( Slot , & T ) ) > = list . iter ( ) . enumerate ( ) . filter_map ( | ( i , ( s , value ) ) | { if * s == slot { Some ( ( i , ( * s , value ) ) ) } else { None } } ) . collect ( ) ; assert ! ( same_slot_previous_updates len ( ) 1 ) ; if let Some ( ( list_index , ( s , previous_update_value ) ) ) = same_slot_previous_updates . pop ( ) { reclaims . push ( ( s , previous_update_value . clone ( ) ) ) ; list . remove ( list_index ) ; } else { // Only increment ref count if the account was not prevously updated in this slot lock . 0 . fetch_add ( 1 , Ordering :: Relaxed ) ; } list . push ( ( slot , account_info ) ) ; None } else { Some ( account_info ) } }
Try to update an item in account_maps.
Try to update an item in account_maps .
&self
slot
Slot
pubkey
&Pubkey
account_info
T
reclaims
&mut SlotList<T>