refactor: clean up logic blocks
@@ -393,9 +393,7 @@ where
// For root node, same node is returned for node and parent node.
fn lookup_at(&self, mut at: u64, key: &K) -> Option<(Node<K>, Node<K>)> {
let mut p: Node<K> = self.node(at).unwrap();
- loop {
- match self.node(at) {
- Some(node) => {
+ while let Some(node) = self.node(at) {
if node.key.eq(key) {
return Some((node, p));
} else if node.key.lt(key) {
@@ -416,9 +414,6 @@ where
}
}
}
- None => break,
- }
- }
None
}
@@ -432,22 +427,14 @@ where
self.enforce_balance(&mut node)
} else {
if node.key.gt(key) {
- match node.lft {
- Some(l) => {
+ if let Some(l) = node.lft {
let id = self.check_balance(l, key);
node.lft = Some(id);
}
- None => (),
- }
- } else {
- match node.rgt {
- Some(r) => {
+ } else if let Some(r) = node.rgt {
let id = self.check_balance(r, key);
node.rgt = Some(id);
}
- None => (),
- }
- }
self.update_height(&mut node);
self.enforce_balance(&mut node)
}
