2023-09-09 15:49:53 +00:00
|
|
|
<!DOCTYPE html>
|
2023-09-26 04:49:33 +00:00
|
|
|
<html lang='en'>
|
2023-09-09 15:49:53 +00:00
|
|
|
<head>
|
2023-09-26 04:49:33 +00:00
|
|
|
<meta charset='UTF-8'>
|
2023-09-19 09:00:25 +00:00
|
|
|
<title>CDN Test</title>
|
2023-11-20 11:27:25 +00:00
|
|
|
<script src="../../dist/umd/data-structure-typed.min.js"></script>
|
|
|
|
<!-- <script src="../../dist/umd/data-structure-typed.js"></script>-->
|
|
|
|
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.min.js'></script>-->
|
|
|
|
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.42.2/dist/umd/data-structure-typed.min.js'></script>-->
|
|
|
|
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.43.3/dist/umd/data-structure-typed.min.js'></script>-->
|
|
|
|
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.44.0/dist/umd/data-structure-typed.min.js'></script>-->
|
2023-11-20 09:30:55 +00:00
|
|
|
|
2023-11-13 04:50:33 +00:00
|
|
|
<script src='https://unpkg.com/js-sdsl@4.4.2/dist/umd/js-sdsl.js'></script>
|
2023-09-09 15:49:53 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2023-09-26 04:49:33 +00:00
|
|
|
<div id='app'>
|
|
|
|
<ul class='modules'>
|
2023-09-19 09:00:25 +00:00
|
|
|
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<script defer>
|
|
|
|
const $modules = document.querySelector('.modules');
|
|
|
|
|
|
|
|
|
2023-10-05 02:37:42 +00:00
|
|
|
try {
|
|
|
|
const queue = new Queue();
|
2023-11-20 09:30:55 +00:00
|
|
|
const n = 100000;
|
|
|
|
const startEn = performance.now();
|
|
|
|
for (let i = 0; i < n; i++) {
|
2023-10-05 02:37:42 +00:00
|
|
|
queue.enqueue(i);
|
|
|
|
}
|
2023-11-20 09:30:55 +00:00
|
|
|
console.log(`Queue ${n} enqueue `, performance.now() - startEn);
|
2023-10-05 02:37:42 +00:00
|
|
|
let last = 0;
|
|
|
|
const startTime = performance.now();
|
|
|
|
|
2023-11-20 09:30:55 +00:00
|
|
|
for (let i = 0; i < n; i++) {
|
2023-10-05 02:37:42 +00:00
|
|
|
last = queue.dequeue();
|
|
|
|
}
|
|
|
|
|
2023-11-20 09:30:55 +00:00
|
|
|
console.log(`Queue ${n} dequeue `, performance.now() - startTime);
|
2023-10-05 02:37:42 +00:00
|
|
|
|
2023-10-25 07:51:50 +00:00
|
|
|
} catch (e) {
|
2023-10-05 02:37:42 +00:00
|
|
|
console.error(e);
|
2023-09-19 09:00:25 +00:00
|
|
|
}
|
2023-11-12 16:03:42 +00:00
|
|
|
try {
|
2023-11-16 03:55:40 +00:00
|
|
|
const { AVLTree } = window.dataStructureTyped;
|
2023-11-12 16:03:42 +00:00
|
|
|
const avlTree = new AVLTree();
|
|
|
|
const $avlTree = document.createElement('li');
|
|
|
|
const $avlTreeSpan = document.createElement('span');
|
|
|
|
$avlTreeSpan.innerText = 'AVLTree';
|
|
|
|
$avlTree.append($avlTreeSpan);
|
|
|
|
for (let i = 1; i < 31; i++) {
|
|
|
|
avlTree.add(i, i);
|
|
|
|
}
|
|
|
|
console.log(avlTree.bfs());
|
|
|
|
// avlTree.print();
|
|
|
|
$modules.append($avlTree);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
2023-09-19 09:00:25 +00:00
|
|
|
|
2023-11-10 03:01:49 +00:00
|
|
|
try {
|
2023-11-16 03:55:40 +00:00
|
|
|
const { BinaryTree } = dataStructureTyped;
|
2023-11-10 03:01:49 +00:00
|
|
|
const tree = new BinaryTree();
|
|
|
|
tree.add(3);
|
|
|
|
tree.add(12);
|
2023-11-13 05:07:28 +00:00
|
|
|
tree.addMany([1, 6, 9, 8, 5, 2, 3, 4, 7])
|
2023-11-10 03:01:49 +00:00
|
|
|
tree.add(10);
|
|
|
|
console.log(tree.isPerfectlyBalanced());
|
|
|
|
tree.print();
|
|
|
|
|
|
|
|
const node3 = tree.getNode(3);
|
|
|
|
if (node3) node3.right = tree.createNode(1);
|
|
|
|
console.log(tree.isPerfectlyBalanced());
|
|
|
|
tree.print();
|
|
|
|
|
|
|
|
tree.clear();
|
|
|
|
tree.addMany([1, null, 2, null, 3, null, 4, null, 5, null, 6, null]);
|
|
|
|
console.log(tree.isPerfectlyBalanced());
|
|
|
|
tree.print();
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
2023-11-12 16:03:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
try {
|
2023-11-16 03:55:40 +00:00
|
|
|
const { OrderedMap } = sdsl;
|
2023-11-20 11:27:25 +00:00
|
|
|
const { RedBlackTree, AVLTree } = dataStructureTyped;
|
2023-11-20 09:30:55 +00:00
|
|
|
const cRBTree = new OrderedMap();
|
|
|
|
const rbTree = new RedBlackTree();
|
2023-11-13 04:50:33 +00:00
|
|
|
const tS = performance.now();
|
2023-11-20 09:30:55 +00:00
|
|
|
const n = 100000;
|
|
|
|
for (let i = 1; i < n; i++) {
|
|
|
|
rbTree.add(i, i);
|
2023-11-12 16:03:42 +00:00
|
|
|
}
|
2023-11-20 09:30:55 +00:00
|
|
|
console.log(`RedBlackTree ${n} add`, performance.now() - tS);
|
|
|
|
console.log(rbTree.size);
|
2023-11-13 04:50:33 +00:00
|
|
|
const cS = performance.now();
|
2023-11-20 09:30:55 +00:00
|
|
|
for (let i = 1; i < 100000; i++) {
|
|
|
|
cRBTree.setElement(i, i);
|
2023-11-13 04:50:33 +00:00
|
|
|
}
|
2023-11-20 11:27:25 +00:00
|
|
|
console.log(`CRedBlackTree ${n} add`, performance.now() - cS);
|
2023-11-20 09:30:55 +00:00
|
|
|
console.log(cRBTree.size());
|
2023-11-13 04:50:33 +00:00
|
|
|
|
|
|
|
// console.log(tree.isPerfectlyBalanced());
|
|
|
|
// tree.print();
|
2023-11-12 16:03:42 +00:00
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
2023-11-13 04:50:33 +00:00
|
|
|
|
|
|
|
try {
|
2023-11-16 03:55:40 +00:00
|
|
|
const { PriorityQueue: CPriorityQueue } = sdsl;
|
|
|
|
const { PriorityQueue } = dataStructureTyped;
|
|
|
|
const pq = new PriorityQueue({ comparator: (a, b) => b - a });
|
2023-11-13 04:50:33 +00:00
|
|
|
|
|
|
|
const tS = performance.now();
|
2023-11-20 09:30:55 +00:00
|
|
|
const n = 1000000;
|
|
|
|
for (let i = 0; i < n; i++) {
|
2023-11-13 04:50:33 +00:00
|
|
|
pq.add(i);
|
|
|
|
}
|
|
|
|
|
2023-11-20 09:30:55 +00:00
|
|
|
for (let i = 0; i < n; i++) {
|
2023-11-13 04:50:33 +00:00
|
|
|
pq.pop();
|
|
|
|
}
|
2023-11-20 11:27:25 +00:00
|
|
|
console.log(`PriorityQueue ${n} add`, performance.now() - tS);
|
2023-11-13 04:50:33 +00:00
|
|
|
console.log(pq.size);
|
|
|
|
const cS = performance.now();
|
|
|
|
const cpq = new CPriorityQueue();
|
|
|
|
|
2023-11-20 09:30:55 +00:00
|
|
|
for (let i = 0; i < n; i++) {
|
2023-11-13 04:50:33 +00:00
|
|
|
cpq.push(i);
|
|
|
|
}
|
|
|
|
|
2023-11-20 09:30:55 +00:00
|
|
|
for (let i = 0; i < n; i++) {
|
2023-11-13 04:50:33 +00:00
|
|
|
cpq.pop();
|
|
|
|
}
|
2023-11-20 11:27:25 +00:00
|
|
|
console.log(`CPriorityQueue ${n} add`, performance.now() - cS);
|
2023-11-13 04:50:33 +00:00
|
|
|
console.log(cpq.size());
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
2023-09-19 09:00:25 +00:00
|
|
|
</script>
|
2023-09-09 15:49:53 +00:00
|
|
|
|
|
|
|
</body>
|
2023-09-19 09:00:25 +00:00
|
|
|
</html>
|
2023-09-21 16:53:34 +00:00
|
|
|
|