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;
|
||||
|
||||
// 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;
|
||||
|
|
Loading…
Reference in a new issue