MCPcopy Create free account
hub / github.com/diem/move / remove_node

Method remove_node

language/move-prover/bytecode/src/access_path_trie.rs:268–294  ·  view source on GitHub ↗

Removes node located at the given access path Returns the node if it has been fully removed from the trie (i.e. it did not have any children)

(&mut self, ap: AccessPath)

Source from the content-addressed store, hash-verified

266 /// Removes node located at the given access path
267 /// Returns the node if it has been fully removed from the trie (i.e. it did not have any children)
268 pub fn remove_node(&mut self, ap: AccessPath) -> Option<TrieNode<T>> {
269 let mut node = self.0.get_mut(ap.root())?;
270
271 // If no offset, we want to remove the root node
272 if ap.offsets().is_empty() {
273 if node.children.is_empty() {
274 return self.0.remove(ap.root());
275 } else {
276 node.data = None;
277 }
278 // Otherwise, find the offset in the trie
279 } else {
280 let offsets_count = ap.offsets().len();
281 for offset in &ap.offsets()[0..offsets_count - 1] {
282 node = node.get_offset_mut(offset)?;
283 }
284 let last_offset = &ap.offsets()[offsets_count - 1];
285 let to_remove = node.get_offset_mut(last_offset)?;
286
287 if to_remove.children.is_empty() {
288 return node.remove_offset(last_offset);
289 } else {
290 to_remove.data = None;
291 }
292 }
293 None
294 }
295
296 pub fn get_child_data(&self) -> Option<T> {
297 let mut acc = None;

Callers 2

to_summaryMethod · 0.45
remove_access_pathMethod · 0.45

Calls 8

get_offset_mutMethod · 0.80
remove_offsetMethod · 0.80
get_mutMethod · 0.45
rootMethod · 0.45
is_emptyMethod · 0.45
offsetsMethod · 0.45
removeMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected