fix(wavl): fix delete and syntax error
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
fc1c9162d6
commit
c3a9a48d99
1 changed files with 10 additions and 5 deletions
15
wavl.js
15
wavl.js
|
@ -97,7 +97,7 @@ class WAVLTree extends AVLTree {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let y = parent.left === x ? parent.right : parent.left;
|
y = parent.left === x ? parent.right : parent.left;
|
||||||
|
|
||||||
xDiff = nodeDifference(x, parent);
|
xDiff = nodeDifference(x, parent);
|
||||||
yDiff = nodeDifference(y, parent);
|
yDiff = nodeDifference(y, parent);
|
||||||
|
@ -136,11 +136,16 @@ class WAVLTree extends AVLTree {
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteFixup(y, parent) {
|
deleteFixup(y, parent) {
|
||||||
let z = y ? y : parent;
|
if (nodeDifferences(y).equals([2, 2])) {
|
||||||
|
y.demote();
|
||||||
if (nodeDifferences(z).equals([2, 2])) {
|
|
||||||
z.demote();
|
|
||||||
this.record();
|
this.record();
|
||||||
|
|
||||||
|
parent = y.parent;
|
||||||
|
} else if (nodeDifferences(parent).equals([2, 2])) {
|
||||||
|
parent.demote();
|
||||||
|
this.record();
|
||||||
|
|
||||||
|
parent = parent.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
|
|
Loading…
Reference in a new issue