pub fn retain<F>(&mut self, mut f: F)
    where
        F: FnMut(K, &mut V) -> bool,
    {
        for (i, slot) in self.slots.iter_mut().enumerate() {
            if let Occupied { value, version } = slot {
                let key = KeyData::new(i as u32, version.get()).into();
                if !f(key, value) {
                    self.num_elems -= 1;
                    *slot = Slot::new_vacant();
                }
            }
        }
    }
/// Retains only the elements specified by the predicate.
///
/// In other words, remove all key-value pairs `(k, v)` such that
/// `f(k, &mut v)` returns false. This method invalidates any removed keys.
///
/// This function must iterate over all slots, empty or not. In the face of
/// many deleted elements it can be inefficient.
///
/// # Examples
///
/// ```
/// # use slotmap::*;
/// let mut sm = SlotMap::new();
/// let mut sec = SecondaryMap::new();
///
/// let k1 = sm.insert(0); sec.insert(k1, 10);
/// let k2 = sm.insert(1); sec.insert(k2, 11);
/// let k3 = sm.insert(2); sec.insert(k3, 12);
///
/// sec.retain(|key, val| key == k1 || *val == 11);
///
/// assert!(sec.contains_key(k1));
/// assert!(sec.contains_key(k2));
/// assert!(!sec.contains_key(k3));
/// assert_eq!(sec.len(), 2);
/// ```
Retains only the elements specified by the predicate.
In other words, remove all key-value pairs `(k, v)` such that
`f(k, &mut v)` returns false. This method invalidates any removed keys.

This function must iterate over all slots, empty or not. In the face of
many deleted elements it can be inefficient.
Retains only the elements specified by the predicate . In other words remove all key - value pairs ` ( k v ) ` such that ` f ( k &mut v ) ` returns false . This method invalidates any removed keys . This function must iterate over all slots empty or not . In the face of many deleted elements it can be inefficient .
pub fn retain<F>(&mut self, mut f: F)
    where
        F: FnMut(K, &mut V) -> bool,
    {
        for (i, slot) in self.slots.iter_mut().enumerate() {
            if let Occupied { value, version } = slot {
                let key = KeyData::new(i as u32, version.get()).into();
                if !f(key, value) {
                    self.num_elems -= 1;
                    *slot = Slot::new_vacant();
                }
            }
        }
    }
pub fn retain < F > ( & mut self , mut f : F ) where F : FnMut ( K , & mut V ) -> bool , { for ( i , slot ) in self . slots . iter_mut ( ) . enumerate ( ) { if let Occupied { value , version } = slot { let key = KeyData :: new ( i as u32 , version . get ( ) ) . into ( ) ; if ! f ( key , value ) { self . num_elems -= 1 ; * slot = Slot :: new_vacant ( ) ; } } } }
Retains only the elements specified by the predicate.
Retains only the elements specified by the predicate .
&mut self
f
F
examples
None
use slotmap::*;
let mut sm = SlotMap::new();
let mut sec = SecondaryMap::new().






let mut sm = SlotMap :: new () ; let mut sec = SecondaryMap :: new () .