Skip to content

Commit

Permalink
Convert to if-else in insert_fix (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
brittcyr authored Oct 23, 2024
1 parent ebe5cee commit 31b77ca
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/src/red_black_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,28 +1331,28 @@ impl<'a, V: Payload> RedBlackTree<'a, V> {
return NIL;
}

let index_to_fix_color: Color = self.get_color::<V>(index_to_fix);
// Case II: Uncle is black, left left
if parent_is_left && current_is_left {
self.rotate_right::<V>(grandparent_index);
self.set_color::<V>(grandparent_index, parent_color);
self.set_color::<V>(parent_index, grandparent_color);
}
let index_to_fix_color: Color = self.get_color::<V>(index_to_fix);
// Case III: Uncle is black, left right
if parent_is_left && !current_is_left {
else if parent_is_left && !current_is_left {
self.rotate_left::<V>(parent_index);
self.rotate_right::<V>(grandparent_index);
self.set_color::<V>(index_to_fix, grandparent_color);
self.set_color::<V>(grandparent_index, index_to_fix_color);
}
// Case IV: Uncle is black, right right
if !parent_is_left && !current_is_left {
else if !parent_is_left && !current_is_left {
self.rotate_left::<V>(grandparent_index);
self.set_color::<V>(grandparent_index, parent_color);
self.set_color::<V>(parent_index, grandparent_color);
}
// Case V: Uncle is black, right left
if !parent_is_left && current_is_left {
else if !parent_is_left && current_is_left {
self.rotate_right::<V>(parent_index);
self.rotate_left::<V>(grandparent_index);
self.set_color::<V>(index_to_fix, grandparent_color);
Expand Down

0 comments on commit 31b77ca

Please sign in to comment.