Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from TheAlgorithms:master #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 1 commit into AlgorithmAndLeetCode:master from TheAlgorithms:master
Dec 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/data_structures/rb_tree.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ unsafe fn delete_fixup<K: Ord, V>(tree: &mut RBTree<K, V>, mut parent: *mut RBNo
let mut sr: *mut RBNode<K, V>;

loop {
// rb-tree will keep color balance up to root,
// if parent is null, we are done.
if parent.is_null() {
break;
}

/*
* Loop invariants:
* - node is black (or null on first iteration)
Expand Down Expand Up @@ -647,4 +653,23 @@ mod tests {
let s: String = tree.iter().map(|x| x.value).collect();
assert_eq!(s, "hlo orl!");
}

#[test]
fn delete_edge_case_null_pointer_guard() {
let mut tree = RBTree::<i8, i8>::new();
tree.insert(4, 4);
tree.insert(2, 2);
tree.insert(5, 5);
tree.insert(0, 0);
tree.insert(3, 3);
tree.insert(-1, -1);
tree.insert(1, 1);
tree.insert(-2, -2);
tree.insert(6, 6);
tree.insert(7, 7);
tree.insert(8, 8);
tree.delete(&1);
tree.delete(&3);
tree.delete(&-1);
}
}

AltStyle によって変換されたページ (->オリジナル) /