feat: color edges in red-black tree
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
dce3e3c11c
commit
2bc43652d0
2 changed files with 19 additions and 1 deletions
|
@ -37,10 +37,12 @@ class RankedTree {
|
||||||
|
|
||||||
edges.forEach((vertices) => {
|
edges.forEach((vertices) => {
|
||||||
let [u, v] = vertices;
|
let [u, v] = vertices;
|
||||||
|
let diff = nodeDifference(v);
|
||||||
|
|
||||||
result.push(
|
result.push(
|
||||||
`\t"Node(${u.value})" -> "Node(${
|
`\t"Node(${u.value})" -> "Node(${
|
||||||
v.value
|
v.value
|
||||||
})" [label="${nodeDifference(v)}"];\n`
|
})" [label="${diff}"${this.styleEdge(diff)}];\n`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -176,4 +178,8 @@ class RankedTree {
|
||||||
deleteRebalance(node, parent) {
|
deleteRebalance(node, parent) {
|
||||||
throw "not implemented!";
|
throw "not implemented!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
styleEdge(rankDifference) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
12
rbt.js
12
rbt.js
|
@ -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 "";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue