fix(avl): reorder recording statements

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-05-06 10:34:42 +02:00
parent 0ef76257af
commit d709599ad9
Signed by: mfocko
GPG key ID: 7C47D46246790496

19
avl.js
View file

@ -36,12 +36,6 @@ class AVLTree extends RankedTree {
recursive = recursive ?? true;
// FIXME: not enough, must be checked against differences
// let bf = balanceFactor(node);
// if (bf < -1 || bf > 1) {
// return false;
// }
let differences = nodeDifferences(node);
differences.sort();
if (!differences.equals([1, 1]) && !differences.equals([1, 2])) {
@ -59,12 +53,13 @@ class AVLTree extends RankedTree {
if (!y || nodeDifference(y) == 2) {
newRoot = rotateRight(z);
z.demote();
if (rotatingAroundRoot) {
this.root = newRoot;
}
this.record();
z.demote();
this.record();
} else if (nodeDifference(y) == 1) {
rotateLeft(x);
this.record();
@ -76,9 +71,12 @@ class AVLTree extends RankedTree {
this.record();
y.promote();
x.demote();
z.demote();
this.record();
x.demote();
this.record();
z.demote();
this.record();
}
}
@ -164,7 +162,6 @@ class AVLTree extends RankedTree {
switch (factor) {
case 0:
updateRank(x);
this.record();
return false;