Created
March 28, 2016 05:37
Revisions
-
Nathan Sobo created this gist
Mar 28, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ 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(); } } } }) }