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;
|
|
|
|
setTrees(AVLTree, 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 13:55:55 +02:00
|
|
|
function setTrees(lType, rType) {
|
2022-05-16 16:47:27 +02:00
|
|
|
left = new lType();
|
|
|
|
left.recorder = lRecorder;
|
|
|
|
|
|
|
|
right = new rType();
|
|
|
|
right.recorder = rRecorder;
|
|
|
|
|
|
|
|
for (let t of [left, right]) {
|
|
|
|
t.recorder.clear();
|
|
|
|
t.record();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:55:55 +02:00
|
|
|
function switchTree(TreeType, side) {
|
|
|
|
let [lType, rType] =
|
|
|
|
side == "left"
|
|
|
|
? [TreeType, right.constructor]
|
|
|
|
: [left.constructor, TreeType];
|
|
|
|
setTrees(lType, rType);
|
|
|
|
}
|
|
|
|
|
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();
|