May 2019
Intermediate to advanced
698 pages
17h 21m
English
This piece of code can almost be reused from the binary search tree. Other than the borrow() calls (instead of a simple dereference or * operator) adding some amount of processing time, they provides a consistent search speed. For greater reuse of existing functions, the value to be found is wrapped into a dummy node. This way, no additional interface has to be created for comparing nodes:
pub fn find(&self, numerical_id: u64) -> Option<IoTDevice> { self.find_r( &self.root, &IoTDevice::new(numerical_id, "".to_owned(), "".to_owned()), )}fn find_r(&self, node: &Tree, dev: &IoTDevice) -> Option<IoTDevice> { match node { Some(n) => { let n = n.borrow(); if n.dev.numerical_id == dev.numerical_id { Some(n.dev.clone()) ...Read now
Unlock full access