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)
| 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; |
no test coverage detected