fix(wavl): fix delete and syntax error

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-05-07 16:53:50 +02:00
parent fc1c9162d6
commit c3a9a48d99
Signed by: mfocko
GPG key ID: 7C47D46246790496

15
wavl.js
View file

@ -97,7 +97,7 @@ class WAVLTree extends AVLTree {
return;
}
let y = parent.left === x ? parent.right : parent.left;
y = parent.left === x ? parent.right : parent.left;
xDiff = nodeDifference(x, parent);
yDiff = nodeDifference(y, parent);
@ -136,11 +136,16 @@ class WAVLTree extends AVLTree {
}
deleteFixup(y, parent) {
let z = y ? y : parent;
if (nodeDifferences(z).equals([2, 2])) {
z.demote();
if (nodeDifferences(y).equals([2, 2])) {
y.demote();
this.record();
parent = y.parent;
} else if (nodeDifferences(parent).equals([2, 2])) {
parent.demote();
this.record();
parent = parent.parent;
}
if (!parent) {