Created
March 28, 2016 05:37
-
-
Save nathansobo/01afbd5638e9e64af11c to your computer and use it in GitHub Desktop.
Lots of `as_ref`... Am I doing this right?
This file contains hidden or 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_lower_bound(&self, target: &Point) -> Option<Rc<Node<'a>>> { | |
self.root.as_ref().and_then(|root| { | |
let mut current_node: Rc<Node> = root.clone(); | |
let mut max_lower_bound: Option<Rc<Node>> = None; | |
let mut left_ancestor_end = Point::zero(); | |
loop { | |
let current_node_start = left_ancestor_end.traverse(¤t_node.new_distance_from_left_ancestor); | |
if target < ¤t_node_start { | |
if current_node.left_child.is_none() { | |
return max_lower_bound; | |
} else { | |
current_node = current_node.left_child.as_ref().unwrap().clone(); | |
} | |
} else { | |
max_lower_bound = Some(current_node.clone()); | |
if current_node.right_child.is_none() { | |
return max_lower_bound; | |
} else { | |
left_ancestor_end = current_node_start.traverse(¤t_node.new_extent); | |
current_node = current_node.right_child.as_ref().unwrap().clone(); | |
} | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment