Skip to content

Commit

Permalink
tree: optimise findReplacement used in deletion operation. (#12)
Browse files Browse the repository at this point in the history
source: Russell A. Brown, Optimized Deletion From an AVL Tree.
https://arxiv.org/pdf/2406.05162v5.
  • Loading branch information
avdva authored Sep 9, 2024
1 parent 0e5df00 commit 5ad215e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/avl.zig
Original file line number Diff line number Diff line change
Expand Up @@ -599,16 +599,16 @@ pub fn TreeWithOptions(comptime K: type, comptime V: type, comptime Cmp: fn (a:
const right = loc.child(.right);
if (left) |l| {
if (right) |r| {
if (l.data().h <= r.data().h) {
// Russell A. Brown, Optimized Deletion From an AVL Tree.
// https://arxiv.org/pdf/2406.05162v5
if (loc.balance() <= 0) {
return goRight(l);
}
return goLeft(r);
}
return goRight(l);
} else if (right) |r| {
return goLeft(r);
return left;
}
return null;
return right;
}

// getMin returns the minimum element of the tree.
Expand Down

0 comments on commit 5ad215e

Please sign in to comment.