A B-Tree's search works just the way binary tree searches do: recursively checking each node for the path to follow. In B-Trees, this becomes very convenient since it can be done in a loop, in this case, by the get_device() function:
pub fn get_device(&self, key: KeyType) -> Option<&IoTDevice> {
let mut result = None;
for d in self.devices.iter() {
if let Some(device) = d {
if device.numerical_id == key {
result = Some(device);
break;
}
}
}
result
}
This function is implemented at the node structure and does a regular linear search for the key itself. If it is unable to find that key, the find_r() function has to decide whether to continue, which it does by evaluating the node type. Since leaf nodes don't have any children, not finding the desired key will end the search, returning None. Regular nodes allow the search to continue on a deeper level of the tree:
pub...