Skip to content

Instantly share code, notes, and snippets.

@kunigami
Last active April 11, 2019 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunigami/28b6c30a6f592b7dd8651c166b003b34 to your computer and use it in GitHub Desktop.
Save kunigami/28b6c30a6f592b7dd8651c166b003b34 to your computer and use it in GitHub Desktop.
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