Last active
April 11, 2019 06:09
-
-
Save kunigami/28b6c30a6f592b7dd8651c166b003b34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn find_node_with_visitor<F>( | |
&self, | |
k: &K, | |
mut visitor: F | |
) -> NodePtr<K, V> where F: FnMut(&K) { | |
if self.root.is_null() { | |
return NodePtr::null(); | |
} | |
let mut temp = &self.root; | |
unsafe { | |
loop { | |
let key = &(*temp.0).key; | |
let next = match k.cmp(key) { | |
Ordering::Less => &mut (*temp.0).left, | |
Ordering::Greater => &mut (*temp.0).right, | |
Ordering::Equal => { | |
visitor(&key); | |
return *temp; | |
} | |
}; | |
visitor(&key); | |
if next.is_null() { | |
break; | |
} | |
temp = next; | |
} | |
} | |
NodePtr::null() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment