2022-05-15 17:53:12 +02:00
|
|
|
let recorder = new Recorder(
|
|
|
|
d3.select("#graph").graphviz(),
|
|
|
|
document.getElementById("comment"),
|
|
|
|
"graph"
|
|
|
|
);
|
2022-05-06 09:42:13 +02:00
|
|
|
|
2022-05-07 16:54:28 +02:00
|
|
|
let tree = new WAVLTree();
|
2022-05-01 17:10:24 +02:00
|
|
|
tree.recorder = recorder;
|
|
|
|
|
2022-05-17 13:54:10 +02:00
|
|
|
function operationCallback(method, id) {
|
|
|
|
let number = document.getElementById(id).value;
|
|
|
|
let value = parseInt(number);
|
|
|
|
if (number === "" || isNaN(value)) {
|
2022-05-01 17:10:24 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:54:10 +02:00
|
|
|
method(value);
|
|
|
|
document.getElementById(id).value = "";
|
2022-05-01 17:10:24 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:54:10 +02:00
|
|
|
function insertCallback() {
|
|
|
|
return operationCallback(tree.insert.bind(tree), "insertInput");
|
|
|
|
}
|
2022-05-01 17:10:24 +02:00
|
|
|
|
2022-05-17 13:54:10 +02:00
|
|
|
function deleteCallback() {
|
|
|
|
return operationCallback(tree.delete.bind(tree), "deleteInput");
|
2022-05-01 17:10:24 +02:00
|
|
|
}
|
|
|
|
|
2022-05-16 15:58:46 +02:00
|
|
|
function switchTree(TreeType) {
|
|
|
|
tree = new TreeType();
|
|
|
|
tree.recorder = recorder;
|
|
|
|
recorder.clear();
|
|
|
|
tree.record("");
|
|
|
|
}
|
|
|
|
|
2022-05-16 18:23:05 +02:00
|
|
|
// #region prepared scenarios
|
|
|
|
function prepareSingleRotationAfterDelete() {
|
|
|
|
let newTree = new WAVLTree();
|
|
|
|
|
|
|
|
for (let key of [0, 1, 2, -1]) {
|
|
|
|
newTree.insert(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById("wavlTreeBtn").checked = true;
|
|
|
|
|
|
|
|
tree = newTree;
|
|
|
|
tree.recorder = recorder;
|
|
|
|
recorder.clear();
|
|
|
|
tree.record("Prepare tree");
|
|
|
|
|
|
|
|
document.getElementById("deleteInput").value = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareDoubleRotationAfterDelete() {
|
|
|
|
let newTree = new WAVLTree();
|
|
|
|
|
|
|
|
for (let key of [0, -7, 1, -1]) {
|
|
|
|
newTree.insert(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById("wavlTreeBtn").checked = true;
|
|
|
|
|
|
|
|
tree = newTree;
|
|
|
|
tree.recorder = recorder;
|
|
|
|
recorder.clear();
|
|
|
|
tree.record("Prepare tree");
|
|
|
|
|
|
|
|
document.getElementById("deleteInput").value = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareDemotionOfBothNodesDuringDelete() {
|
|
|
|
let newTree = new WAVLTree();
|
|
|
|
|
|
|
|
for (let key of [0, 1, 2, 3, -2, -3, -1]) {
|
|
|
|
newTree.insert(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let key of [-2]) {
|
|
|
|
newTree.delete(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById("wavlTreeBtn").checked = true;
|
|
|
|
|
|
|
|
tree = newTree;
|
|
|
|
tree.recorder = recorder;
|
|
|
|
recorder.clear();
|
|
|
|
tree.record("Prepare tree");
|
|
|
|
|
|
|
|
document.getElementById("deleteInput").value = 2;
|
|
|
|
}
|
|
|
|
// #endregion prepared scenarios
|
|
|
|
|
2022-05-01 17:10:24 +02:00
|
|
|
function render() {
|
|
|
|
recorder.render();
|
|
|
|
setTimeout(render);
|
|
|
|
}
|
|
|
|
render();
|