feat: color edges in red-black tree

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-05-21 13:02:05 +02:00
parent dce3e3c11c
commit 2bc43652d0
Signed by: mfocko
GPG key ID: 7C47D46246790496
2 changed files with 19 additions and 1 deletions

View file

@ -37,10 +37,12 @@ class RankedTree {
edges.forEach((vertices) => {
let [u, v] = vertices;
let diff = nodeDifference(v);
result.push(
`\t"Node(${u.value})" -> "Node(${
v.value
})" [label="${nodeDifference(v)}"];\n`
})" [label="${diff}"${this.styleEdge(diff)}];\n`
);
});
@ -176,4 +178,8 @@ class RankedTree {
deleteRebalance(node, parent) {
throw "not implemented!";
}
styleEdge(rankDifference) {
return "";
}
}

12
rbt.js
View file

@ -158,4 +158,16 @@ class RBTree extends RankedTree {
}
}
}
styleEdge(rankDifference) {
switch (rankDifference) {
case 2:
return " penwidth=2";
case 0:
return ', color="red"';
case 1:
default:
return "";
}
}
}