chore: minor refactor
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
6d804155e1
commit
23a0653d23
2 changed files with 10 additions and 6 deletions
13
avl.js
13
avl.js
|
@ -18,14 +18,15 @@ class AVLTree extends RankedTree {
|
|||
return true;
|
||||
}
|
||||
|
||||
recursive = recursive ?? true;
|
||||
|
||||
let differences = nodeDifferences(node);
|
||||
differences.sort();
|
||||
if (!differences.equals([1, 1]) && !differences.equals([1, 2])) {
|
||||
let differences = nodeDifferences(node).sort();
|
||||
if (
|
||||
(!differences.equals([1, 1]) && !differences.equals([1, 2])) ||
|
||||
node.rank != 1 + Math.max(...differences)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
recursive = recursive ?? true;
|
||||
return (
|
||||
!recursive ||
|
||||
(this.isCorrectNode(node.left) && this.isCorrectNode(node.right))
|
||||
|
@ -121,6 +122,8 @@ class AVLTree extends RankedTree {
|
|||
break;
|
||||
default:
|
||||
rotateRight(y);
|
||||
this.record();
|
||||
|
||||
newRoot = rotateLeft(x);
|
||||
break;
|
||||
}
|
||||
|
|
3
wavl.js
3
wavl.js
|
@ -14,8 +14,9 @@ class WAVLTree extends AVLTree {
|
|||
return node.rank == 0;
|
||||
}
|
||||
|
||||
recursive = recursive ?? true;
|
||||
return (
|
||||
!(recursive ?? true) ||
|
||||
!recursive ||
|
||||
(this.isCorrectNode(node.left) && this.isCorrectNode(node.right))
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue