chore: minor refactor

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-05-07 17:11:07 +02:00
parent 6d804155e1
commit 23a0653d23
Signed by: mfocko
GPG key ID: 7C47D46246790496
2 changed files with 10 additions and 6 deletions

13
avl.js
View file

@ -18,14 +18,15 @@ class AVLTree extends RankedTree {
return true; return true;
} }
recursive = recursive ?? true; let differences = nodeDifferences(node).sort();
if (
let differences = nodeDifferences(node); (!differences.equals([1, 1]) && !differences.equals([1, 2])) ||
differences.sort(); node.rank != 1 + Math.max(...differences)
if (!differences.equals([1, 1]) && !differences.equals([1, 2])) { ) {
return false; return false;
} }
recursive = recursive ?? true;
return ( return (
!recursive || !recursive ||
(this.isCorrectNode(node.left) && this.isCorrectNode(node.right)) (this.isCorrectNode(node.left) && this.isCorrectNode(node.right))
@ -121,6 +122,8 @@ class AVLTree extends RankedTree {
break; break;
default: default:
rotateRight(y); rotateRight(y);
this.record();
newRoot = rotateLeft(x); newRoot = rotateLeft(x);
break; break;
} }

View file

@ -14,8 +14,9 @@ class WAVLTree extends AVLTree {
return node.rank == 0; return node.rank == 0;
} }
recursive = recursive ?? true;
return ( return (
!(recursive ?? true) || !recursive ||
(this.isCorrectNode(node.left) && this.isCorrectNode(node.right)) (this.isCorrectNode(node.left) && this.isCorrectNode(node.right))
); );
} }