2022-05-07 16:55:12 +02:00
|
|
|
let lRecorder = new Recorder(
|
|
|
|
d3.select("#left").graphviz(),
|
2022-05-15 17:53:12 +02:00
|
|
|
null,
|
2022-05-07 16:55:12 +02:00
|
|
|
"left"
|
|
|
|
).renderAtOnce();
|
|
|
|
let rRecorder = new Recorder(
|
|
|
|
d3.select("#right").graphviz(),
|
2022-05-15 17:53:12 +02:00
|
|
|
null,
|
2022-05-07 16:55:12 +02:00
|
|
|
"right"
|
|
|
|
).renderAtOnce();
|
|
|
|
|
2022-05-17 13:55:55 +02:00
|
|
|
let left = null;
|
|
|
|
let right = null;
|
2022-05-17 14:39:33 +02:00
|
|
|
setTrees(new AVLTree(), new WAVLTree());
|
2022-05-07 16:55:12 +02:00
|
|
|
|
2022-05-17 13:54:10 +02:00
|
|
|
function operationCallback(lMethod, rMethod, id) {
|
|
|
|
let number = document.getElementById(id).value;
|
|
|
|
let value = parseInt(number);
|
|
|
|
if (number === "" || isNaN(value)) {
|
2022-05-07 16:55:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:54:10 +02:00
|
|
|
lMethod(value);
|
|
|
|
rMethod(value);
|
|
|
|
document.getElementById(id).value = "";
|
2022-05-07 16:55:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:54:10 +02:00
|
|
|
function insertCallback() {
|
|
|
|
return operationCallback(
|
|
|
|
left.insert.bind(left),
|
|
|
|
right.insert.bind(right),
|
|
|
|
"insertInput"
|
|
|
|
);
|
|
|
|
}
|
2022-05-07 16:55:12 +02:00
|
|
|
|
2022-05-17 13:54:10 +02:00
|
|
|
function deleteCallback() {
|
|
|
|
return operationCallback(
|
|
|
|
left.delete.bind(left),
|
|
|
|
right.delete.bind(right),
|
|
|
|
"deleteInput"
|
|
|
|
);
|
2022-05-07 16:55:12 +02:00
|
|
|
}
|
|
|
|
|
2022-05-17 14:39:33 +02:00
|
|
|
function setTrees(newLeft, newRight, msg) {
|
|
|
|
left = newLeft;
|
2022-05-16 16:47:27 +02:00
|
|
|
left.recorder = lRecorder;
|
|
|
|
|
2022-05-17 14:39:33 +02:00
|
|
|
right = newRight;
|
2022-05-16 16:47:27 +02:00
|
|
|
right.recorder = rRecorder;
|
|
|
|
|
|
|
|
for (let t of [left, right]) {
|
|
|
|
t.recorder.clear();
|
2022-05-17 14:39:33 +02:00
|
|
|
t.record(msg);
|
2022-05-16 16:47:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:55:55 +02:00
|
|
|
function switchTree(TreeType, side) {
|
|
|
|
let [lType, rType] =
|
|
|
|
side == "left"
|
|
|
|
? [TreeType, right.constructor]
|
|
|
|
: [left.constructor, TreeType];
|
2022-05-17 14:39:33 +02:00
|
|
|
setTrees(new lType(), new rType());
|
2022-05-17 13:55:55 +02:00
|
|
|
}
|
|
|
|
|
2022-05-17 14:39:33 +02:00
|
|
|
// #region prepared scenarios
|
|
|
|
function prepareDifferentRanks() {
|
|
|
|
let newLTree = new AVLTree();
|
|
|
|
let newRTree = new WAVLTree();
|
|
|
|
|
|
|
|
for (let key of [0, -7, 1, -1]) {
|
|
|
|
newLTree.insert(key);
|
|
|
|
newRTree.insert(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById("lAvlTreeBtn").checked = true;
|
|
|
|
document.getElementById("rWavlTreeBtn").checked = true;
|
|
|
|
|
|
|
|
setTrees(newLTree, newRTree, "Prepare tree");
|
|
|
|
|
|
|
|
document.getElementById("deleteInput").value = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareDifferentTrees() {
|
|
|
|
let newLTree = new AVLTree();
|
|
|
|
let newRTree = new WAVLTree();
|
|
|
|
|
|
|
|
for (let key of [0, -31, 2, 3, 4, 1, 6, -1, -4, -3, -2, 31]) {
|
|
|
|
newLTree.insert(key);
|
|
|
|
newRTree.insert(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById("lAvlTreeBtn").checked = true;
|
|
|
|
document.getElementById("rWavlTreeBtn").checked = true;
|
|
|
|
|
|
|
|
setTrees(newLTree, newRTree, "Prepare tree");
|
|
|
|
|
|
|
|
document.getElementById("deleteInput").value = -31;
|
|
|
|
}
|
|
|
|
// #endregion prepared scenarios
|
|
|
|
|
|
|
|
const tooltipTriggerList = document.querySelectorAll(
|
|
|
|
'[data-bs-toggle="tooltip"]'
|
|
|
|
);
|
|
|
|
const tooltipList = [...tooltipTriggerList].map(
|
|
|
|
(tooltipTriggerEl) => new bootstrap.Tooltip(tooltipTriggerEl)
|
|
|
|
);
|
|
|
|
|
2022-05-07 16:55:12 +02:00
|
|
|
async function render() {
|
|
|
|
await Promise.all([
|
|
|
|
new Promise(() => lRecorder.render()),
|
|
|
|
new Promise(() => rRecorder.render()),
|
|
|
|
]);
|
|
|
|
setTimeout(render);
|
|
|
|
}
|
|
|
|
render();
|