MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / retain

Method retain

cranelift/bforest/src/set.rs:154–169  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 1

emptyFunction · 0.45

Calls 6

leaf_posMethod · 0.80
unwrap_leafMethod · 0.80
expandMethod · 0.45
firstMethod · 0.45
nextMethod · 0.45
removeMethod · 0.45

Tested by 1

emptyFunction · 0.36