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

Method retain

cranelift/bforest/src/map.rs:181–200  ·  view source on GitHub ↗

Retains only the elements specified by the predicate. Remove all key-value pairs where the predicate returns false. The predicate is allowed to update the values stored in the map.

(&mut self, forest: &mut MapForest<K, V>, mut predicate: F)

Source from the content-addressed store, hash-verified

179 ///
180 /// The predicate is allowed to update the values stored in the map.
181 pub fn retain<F>(&mut self, forest: &mut MapForest<K, V>, mut predicate: F)
182 where
183 F: FnMut(K, &mut V) -> bool,
184 {
185 let mut path = Path::default();
186 if let Some(root) = self.root.expand() {
187 path.first(root, &forest.nodes);
188 }
189 while let Some((node, entry)) = path.leaf_pos() {
190 let keep = {
191 let (ks, vs) = forest.nodes[node].unwrap_leaf_mut();
192 predicate(ks[entry], &mut vs[entry])
193 };
194 if keep {
195 path.next(&forest.nodes);
196 } else {
197 self.root = path.remove(&mut forest.nodes).into();
198 }
199 }
200 }
201
202 /// Create an immutable cursor for navigating this map.
203 ///

Callers 9

remove_set_ofMethod · 0.45
emptyFunction · 0.45
split_level0_leafFunction · 0.45
do_remove_constant_phisFunction · 0.45
resolve_all_aliasesMethod · 0.45
gen_call_infoMethod · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 6

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

Tested by 2

emptyFunction · 0.36
split_level0_leafFunction · 0.36