mirror of
https://github.com/zrwusa/data-structure-typed.git
synced 2024-11-23 12:54:04 +00:00
147 lines
3.9 KiB
HTML
147 lines
3.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang='en'>
|
|
<head>
|
|
<meta charset='UTF-8'>
|
|
<title>CDN Test</title>
|
|
<script src="../../dist/umd/data-structure-typed.min.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>-->
|
|
|
|
<script src='https://unpkg.com/js-sdsl@4.4.2/dist/umd/js-sdsl.js'></script>
|
|
</head>
|
|
<body>
|
|
<div id='app'>
|
|
<ul class='modules'>
|
|
|
|
</ul>
|
|
</div>
|
|
<script defer>
|
|
const $modules = document.querySelector('.modules');
|
|
|
|
|
|
try {
|
|
const queue = new Queue();
|
|
const n = 100000;
|
|
const startEn = performance.now();
|
|
for (let i = 0; i < n; i++) {
|
|
queue.enqueue(i);
|
|
}
|
|
console.log(`Queue ${n} enqueue `, performance.now() - startEn);
|
|
let last = 0;
|
|
const startTime = performance.now();
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
last = queue.dequeue();
|
|
}
|
|
|
|
console.log(`Queue ${n} dequeue `, performance.now() - startTime);
|
|
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
try {
|
|
const { AVLTree } = window.dataStructureTyped;
|
|
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);
|
|
}
|
|
|
|
try {
|
|
const { BinaryTree } = dataStructureTyped;
|
|
const tree = new BinaryTree();
|
|
tree.add(3);
|
|
tree.add(12);
|
|
tree.addMany([1, 6, 9, 8, 5, 2, 3, 4, 7])
|
|
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);
|
|
}
|
|
|
|
|
|
try {
|
|
const { OrderedMap } = sdsl;
|
|
const { RedBlackTree, AVLTree} = dataStructureTyped;
|
|
const cRBTree = new OrderedMap();
|
|
const rbTree = new RedBlackTree();
|
|
const tS = performance.now();
|
|
const n = 100000;
|
|
for (let i = 1; i < n; i++) {
|
|
rbTree.add(i, i);
|
|
}
|
|
console.log(`RedBlackTree ${n} add`, performance.now() - tS);
|
|
console.log(rbTree.size);
|
|
const cS = performance.now();
|
|
for (let i = 1; i < 100000; i++) {
|
|
cRBTree.setElement(i, i);
|
|
}
|
|
console.log(`CRedBlackTree ${n} add`,performance.now() - cS);
|
|
console.log(cRBTree.size());
|
|
|
|
// console.log(tree.isPerfectlyBalanced());
|
|
// tree.print();
|
|
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
|
|
try {
|
|
const { PriorityQueue: CPriorityQueue } = sdsl;
|
|
const { PriorityQueue } = dataStructureTyped;
|
|
const pq = new PriorityQueue({ comparator: (a, b) => b - a });
|
|
|
|
const tS = performance.now();
|
|
const n = 1000000;
|
|
for (let i = 0; i < n; i++) {
|
|
pq.add(i);
|
|
}
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
pq.pop();
|
|
}
|
|
console.log(`PriorityQueue ${n} add`,performance.now() - tS);
|
|
console.log(pq.size);
|
|
const cS = performance.now();
|
|
const cpq = new CPriorityQueue();
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
cpq.push(i);
|
|
}
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
cpq.pop();
|
|
}
|
|
console.log(`CPriorityQueue ${n} add`,performance.now() - cS);
|
|
console.log(cpq.size());
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|
|
|