feat: fix root in rotation functions

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-05-20 15:29:50 +02:00
parent 948f47de3b
commit df787476ac
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -36,7 +36,7 @@ function nodeDifferences(node) {
return [r - nodeRank(left), r - nodeRank(right)];
}
function rotateRight(x) {
function rotateRight(x, t) {
let parent = x.parent;
let y = x.left;
// let z = x.right;
@ -47,6 +47,8 @@ function rotateRight(x) {
} else {
parent.right = y;
}
} else if (t) {
t.root = y;
}
x.left = y.right;
@ -61,7 +63,7 @@ function rotateRight(x) {
return y;
}
function rotateLeft(x) {
function rotateLeft(x, t) {
let parent = x.parent;
// let y = x.left;
let z = x.right;
@ -72,6 +74,8 @@ function rotateLeft(x) {
} else {
parent.right = z;
}
} else if (t) {
t.root = z;
}
x.right = z.left;