May 2019
Intermediate to advanced
698 pages
17h 21m
English
B-Trees add new entries to their leaves, which then bubble up as nodes grow too large. In order to efficiently find a spot, this is done recursively, removing and replacing ownership as needed. Here is the add() function, which takes care of retrieving ownership of the root node and calling the recursive call with an existing or new node:
type Data = (Option<IoTDevice>, Option<Tree>);pub fn add(&mut self, device: IoTDevice) { let node = if self.root.is_some() { mem::replace(&mut self.root, None).unwrap() } else { Node::new_leaf() }; let (root, _) = self.add_r(node, device, true); self.root = Some(root);}
Except in the case of the root node, the add_r() function (the recursive call) returns two pieces of information: the key it ...
Read now
Unlock full access