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;
|
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;
|
||||||
}
|
}
|
||||||
|
|
3
wavl.js
3
wavl.js
|
@ -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))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue