fix(avl): reorder recording statements
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
0ef76257af
commit
d709599ad9
1 changed files with 8 additions and 11 deletions
19
avl.js
19
avl.js
|
@ -36,12 +36,6 @@ class AVLTree extends RankedTree {
|
||||||
|
|
||||||
recursive = recursive ?? true;
|
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);
|
let differences = nodeDifferences(node);
|
||||||
differences.sort();
|
differences.sort();
|
||||||
if (!differences.equals([1, 1]) && !differences.equals([1, 2])) {
|
if (!differences.equals([1, 1]) && !differences.equals([1, 2])) {
|
||||||
|
@ -59,12 +53,13 @@ class AVLTree extends RankedTree {
|
||||||
|
|
||||||
if (!y || nodeDifference(y) == 2) {
|
if (!y || nodeDifference(y) == 2) {
|
||||||
newRoot = rotateRight(z);
|
newRoot = rotateRight(z);
|
||||||
z.demote();
|
|
||||||
|
|
||||||
if (rotatingAroundRoot) {
|
if (rotatingAroundRoot) {
|
||||||
this.root = newRoot;
|
this.root = newRoot;
|
||||||
}
|
}
|
||||||
this.record();
|
this.record();
|
||||||
|
|
||||||
|
z.demote();
|
||||||
|
this.record();
|
||||||
} else if (nodeDifference(y) == 1) {
|
} else if (nodeDifference(y) == 1) {
|
||||||
rotateLeft(x);
|
rotateLeft(x);
|
||||||
this.record();
|
this.record();
|
||||||
|
@ -76,9 +71,12 @@ class AVLTree extends RankedTree {
|
||||||
this.record();
|
this.record();
|
||||||
|
|
||||||
y.promote();
|
y.promote();
|
||||||
x.demote();
|
this.record();
|
||||||
z.demote();
|
|
||||||
|
|
||||||
|
x.demote();
|
||||||
|
this.record();
|
||||||
|
|
||||||
|
z.demote();
|
||||||
this.record();
|
this.record();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,7 +162,6 @@ class AVLTree extends RankedTree {
|
||||||
switch (factor) {
|
switch (factor) {
|
||||||
case 0:
|
case 0:
|
||||||
updateRank(x);
|
updateRank(x);
|
||||||
|
|
||||||
this.record();
|
this.record();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue