Retains only the elements specified by the predicate. Remove all elements where the predicate returns false.
(&mut self, forest: &mut SetForest<K>, mut predicate: F)
| 152 | /// |
| 153 | /// Remove all elements where the predicate returns false. |
| 154 | pub fn retain<F>(&mut self, forest: &mut SetForest<K>, mut predicate: F) |
| 155 | where |
| 156 | F: FnMut(K) -> bool, |
| 157 | { |
| 158 | let mut path = Path::default(); |
| 159 | if let Some(root) = self.root.expand() { |
| 160 | path.first(root, &forest.nodes); |
| 161 | } |
| 162 | while let Some((node, entry)) = path.leaf_pos() { |
| 163 | if predicate(forest.nodes[node].unwrap_leaf().0[entry]) { |
| 164 | path.next(&forest.nodes); |
| 165 | } else { |
| 166 | self.root = path.remove(&mut forest.nodes).into(); |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | /// Create a cursor for navigating this set. The cursor is initially positioned off the end of |
| 172 | /// the set. |