data-structure-typed 1.46.5 → 1.46.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +18 -18
- package/benchmark/report.html +46 -1
- package/benchmark/report.json +428 -5
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +2 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +29 -46
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +10 -5
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/types/{helpers.js → common.js} +1 -1
- package/dist/cjs/types/common.js.map +1 -0
- package/dist/cjs/types/index.d.ts +1 -1
- package/dist/cjs/types/index.js +1 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +2 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +29 -46
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +10 -5
- package/dist/mjs/types/index.d.ts +1 -1
- package/dist/mjs/types/index.js +1 -1
- package/dist/umd/data-structure-typed.js +32 -50
- package/dist/umd/data-structure-typed.min.js +10 -5
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +70 -47
- package/src/data-structures/binary-tree/binary-tree.ts +33 -46
- package/src/data-structures/binary-tree/rb-tree.ts +9 -4
- package/src/types/index.ts +1 -1
- package/test/integration/index.html +32 -23
- package/test/performance/data-structures/{comparison.test.ts → comparison/comparison.test.ts} +34 -28
- package/test/performance/data-structures/hash/hash-map.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +17 -0
- package/tsup.config.js +1 -1
- package/dist/cjs/types/helpers.js.map +0 -1
- /package/dist/cjs/types/{helpers.d.ts → common.d.ts} +0 -0
- /package/dist/mjs/types/{helpers.d.ts → common.d.ts} +0 -0
- /package/dist/mjs/types/{helpers.js → common.js} +0 -0
- /package/src/types/{helpers.ts → common.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.46.
|
|
4
|
-
"description": "Data Structures of Javascript & TypeScript. Binary Tree,
|
|
3
|
+
"version": "1.46.7",
|
|
4
|
+
"description": "Data Structures of Javascript & TypeScript. Heap, Binary Tree, RedBlack Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/mjs/index.js",
|
|
7
7
|
"types": "dist/mjs/index.d.ts",
|
|
@@ -101,8 +101,6 @@
|
|
|
101
101
|
"data-structures",
|
|
102
102
|
"in data structures",
|
|
103
103
|
"in data structure",
|
|
104
|
-
"DataStructure",
|
|
105
|
-
"DataStructures",
|
|
106
104
|
"binary",
|
|
107
105
|
"depth",
|
|
108
106
|
"breadth",
|
|
@@ -110,10 +108,18 @@
|
|
|
110
108
|
"search",
|
|
111
109
|
"index",
|
|
112
110
|
"avl",
|
|
111
|
+
"red",
|
|
112
|
+
"black",
|
|
113
|
+
"redblack",
|
|
114
|
+
"RB",
|
|
113
115
|
"segment",
|
|
114
116
|
"prefix",
|
|
115
117
|
"tree",
|
|
118
|
+
"multi",
|
|
119
|
+
"map",
|
|
120
|
+
"set",
|
|
116
121
|
"multiset",
|
|
122
|
+
"multimap",
|
|
117
123
|
"directed",
|
|
118
124
|
"undirected",
|
|
119
125
|
"graph",
|
|
@@ -131,39 +137,53 @@
|
|
|
131
137
|
"javascript",
|
|
132
138
|
"typscript",
|
|
133
139
|
"Node.js",
|
|
134
|
-
"
|
|
135
|
-
"
|
|
136
|
-
"UMD",
|
|
137
|
-
"esmodule",
|
|
138
|
-
"java.util",
|
|
139
|
-
"c++ stl",
|
|
140
|
-
"c++ std",
|
|
141
|
-
"Python collections",
|
|
142
|
-
"System.Collections.Generic",
|
|
143
|
-
"STL",
|
|
144
|
-
"stl",
|
|
145
|
-
"STD",
|
|
140
|
+
"NodeJS",
|
|
141
|
+
"c++",
|
|
146
142
|
"std",
|
|
147
|
-
"
|
|
148
|
-
"
|
|
143
|
+
"C++ STL",
|
|
144
|
+
"c++stl",
|
|
145
|
+
"C++ std",
|
|
146
|
+
"stl",
|
|
147
|
+
"std::",
|
|
148
|
+
"Python",
|
|
149
149
|
"collections",
|
|
150
|
+
"Python Collections",
|
|
151
|
+
"pythoncollections",
|
|
152
|
+
"python-collections",
|
|
153
|
+
"C#",
|
|
154
|
+
"System.Collections.Generic",
|
|
150
155
|
"collection",
|
|
156
|
+
"java.util",
|
|
157
|
+
"Java",
|
|
151
158
|
"util",
|
|
152
|
-
"sort",
|
|
153
|
-
"algorithm",
|
|
154
159
|
"binary search tree",
|
|
155
160
|
"binarysearchtree",
|
|
156
161
|
"binary-search-tree",
|
|
162
|
+
"BST",
|
|
157
163
|
"binary tree",
|
|
158
164
|
"binarytree",
|
|
159
165
|
"binary-tree",
|
|
160
|
-
"
|
|
161
|
-
"
|
|
166
|
+
"red black tree",
|
|
167
|
+
"redblacktree",
|
|
168
|
+
"redblack tree",
|
|
169
|
+
"red-black-tree",
|
|
170
|
+
"redblack-tree",
|
|
171
|
+
"trie",
|
|
172
|
+
"prefix tree",
|
|
173
|
+
"prefixtree",
|
|
174
|
+
"prefix-tree",
|
|
162
175
|
"avl tree",
|
|
163
176
|
"avltree",
|
|
164
177
|
"avl-tree",
|
|
178
|
+
"tree set",
|
|
179
|
+
"treeset",
|
|
180
|
+
"tree-set",
|
|
165
181
|
"tree multiset",
|
|
166
182
|
"treemultiset",
|
|
183
|
+
"tree-multiset",
|
|
184
|
+
"tree map",
|
|
185
|
+
"treemap",
|
|
186
|
+
"tree-map",
|
|
167
187
|
"tree multimap",
|
|
168
188
|
"treemultimap",
|
|
169
189
|
"tree-multimap",
|
|
@@ -173,21 +193,31 @@
|
|
|
173
193
|
"segment tree",
|
|
174
194
|
"segmenttree",
|
|
175
195
|
"segment-tree",
|
|
176
|
-
"
|
|
177
|
-
"
|
|
178
|
-
"
|
|
179
|
-
"
|
|
196
|
+
"sort",
|
|
197
|
+
"sorted",
|
|
198
|
+
"order",
|
|
199
|
+
"ordered",
|
|
200
|
+
"algorithm",
|
|
201
|
+
"morris",
|
|
202
|
+
"Morris",
|
|
203
|
+
"bellman ford",
|
|
204
|
+
"bellmanford",
|
|
205
|
+
"bellman-ford",
|
|
206
|
+
"dijkstra",
|
|
207
|
+
"Dijkstra",
|
|
208
|
+
"floyd warshall",
|
|
209
|
+
"floydwarshall",
|
|
210
|
+
"floyd-warshall",
|
|
211
|
+
"tarjan",
|
|
212
|
+
"tarjan's",
|
|
180
213
|
"dfs",
|
|
181
|
-
"DFS",
|
|
182
214
|
"depth first Search",
|
|
183
215
|
"depthfirstSearch",
|
|
184
216
|
"depth-first-Search",
|
|
185
217
|
"bfs",
|
|
186
|
-
"BFS",
|
|
187
218
|
"breadth first search",
|
|
188
219
|
"breadthfirstsearch",
|
|
189
220
|
"dfs iterative",
|
|
190
|
-
"DFS Iterative",
|
|
191
221
|
"recursive",
|
|
192
222
|
"iterative",
|
|
193
223
|
"directed graph",
|
|
@@ -211,13 +241,12 @@
|
|
|
211
241
|
"min priority queue",
|
|
212
242
|
"minpriorityqueue",
|
|
213
243
|
"min-priority-queue",
|
|
214
|
-
"array queue",
|
|
215
|
-
"array-queue",
|
|
216
|
-
"stack",
|
|
217
244
|
"hash",
|
|
245
|
+
"map",
|
|
246
|
+
"hash map",
|
|
247
|
+
"hashmap",
|
|
248
|
+
"hash-map",
|
|
218
249
|
"deque",
|
|
219
|
-
"object deque",
|
|
220
|
-
"array deque",
|
|
221
250
|
"linked list",
|
|
222
251
|
"linkedlist",
|
|
223
252
|
"linked-list",
|
|
@@ -227,18 +256,12 @@
|
|
|
227
256
|
"doubly linked list",
|
|
228
257
|
"doublylinkedlist",
|
|
229
258
|
"doubly-linked-list",
|
|
230
|
-
"
|
|
231
|
-
"
|
|
232
|
-
"
|
|
233
|
-
"
|
|
234
|
-
"
|
|
235
|
-
"
|
|
236
|
-
"
|
|
237
|
-
"floyd warshall",
|
|
238
|
-
"Floyd Warshall",
|
|
239
|
-
"floyd-warshall",
|
|
240
|
-
"tarjan",
|
|
241
|
-
"Tarjan",
|
|
242
|
-
"Tarjan's"
|
|
259
|
+
"stack",
|
|
260
|
+
"CommonJS",
|
|
261
|
+
"ES6",
|
|
262
|
+
"UMD",
|
|
263
|
+
"ES Modules",
|
|
264
|
+
"ESModules",
|
|
265
|
+
"ESModule"
|
|
243
266
|
]
|
|
244
267
|
}
|
|
@@ -1727,7 +1727,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
|
|
|
1727
1727
|
|
|
1728
1728
|
/**
|
|
1729
1729
|
* The `print` function is used to display a binary tree structure in a visually appealing way.
|
|
1730
|
-
* @param {N | null | undefined}
|
|
1730
|
+
* @param {N | null | undefined} beginRoot - The `root` parameter is of type `BTNKey | N | null |
|
|
1731
1731
|
* undefined`. It represents the root node of a binary tree. The root node can have one of the
|
|
1732
1732
|
* following types:
|
|
1733
1733
|
*/
|
|
@@ -1736,61 +1736,48 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
|
|
|
1736
1736
|
if (!beginRoot) return;
|
|
1737
1737
|
|
|
1738
1738
|
const display = (root: N | null | undefined): void => {
|
|
1739
|
-
const [lines, , ,] = _displayAux(root);
|
|
1739
|
+
const [lines, , ,] = this._displayAux(root);
|
|
1740
1740
|
for (const line of lines) {
|
|
1741
1741
|
console.log(line);
|
|
1742
1742
|
}
|
|
1743
1743
|
};
|
|
1744
1744
|
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
return [[], 0, 0, 0];
|
|
1748
|
-
}
|
|
1745
|
+
display(beginRoot);
|
|
1746
|
+
}
|
|
1749
1747
|
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
const middle = Math.floor(width / 2);
|
|
1755
|
-
return [[line], width, height, middle];
|
|
1756
|
-
}
|
|
1748
|
+
protected _displayAux(node: N | null | undefined): [string[], number, number, number] {
|
|
1749
|
+
if (!node) {
|
|
1750
|
+
return [['─'], 1, 0, 0];
|
|
1751
|
+
}
|
|
1757
1752
|
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
const s = `${node.key}`;
|
|
1761
|
-
const u = s.length;
|
|
1762
|
-
const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s;
|
|
1763
|
-
const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u);
|
|
1764
|
-
const shifted_lines = lines.map(line => line + ' '.repeat(u));
|
|
1765
|
-
return [[first_line, second_line, ...shifted_lines], n + u, p + 2, n + Math.floor(u / 2)];
|
|
1766
|
-
}
|
|
1753
|
+
const line = node.key.toString();
|
|
1754
|
+
const width = line.length;
|
|
1767
1755
|
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
const x = s.length;
|
|
1772
|
-
const first_line = s + '_'.repeat(x) + ' '.repeat(n - x);
|
|
1773
|
-
const second_line = ' '.repeat(u + x) + '\\' + ' '.repeat(n - x - 1);
|
|
1774
|
-
const shifted_lines = lines.map(line => ' '.repeat(u) + line);
|
|
1775
|
-
return [[first_line, second_line, ...shifted_lines], n + x, p + 2, Math.floor(u / 2)];
|
|
1776
|
-
}
|
|
1756
|
+
if (!node.left && !node.right) {
|
|
1757
|
+
return [[line], width, 1, Math.floor(width / 2)];
|
|
1758
|
+
}
|
|
1777
1759
|
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
const s = `${node.key}`;
|
|
1781
|
-
const u = s.length;
|
|
1782
|
-
const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s + '_'.repeat(y) + ' '.repeat(m - y);
|
|
1783
|
-
const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u + y) + '\\' + ' '.repeat(m - y - 1);
|
|
1784
|
-
if (p < q) {
|
|
1785
|
-
left.push(...new Array(q - p).fill(' '.repeat(n)));
|
|
1786
|
-
} else if (q < p) {
|
|
1787
|
-
right.push(...new Array(p - q).fill(' '.repeat(m)));
|
|
1788
|
-
}
|
|
1789
|
-
const zipped_lines = left.map((a, i) => a + ' '.repeat(u) + right[i]);
|
|
1790
|
-
return [[first_line, second_line, ...zipped_lines], n + m + u, Math.max(p, q) + 2, n + Math.floor(u / 2)];
|
|
1791
|
-
};
|
|
1760
|
+
const [leftLines, leftWidth, leftHeight, leftMiddle] = node.left ? this._displayAux(node.left) : [[''], 0, 0, 0];
|
|
1761
|
+
const [rightLines, rightWidth, rightHeight, rightMiddle] = node.right ? this._displayAux(node.right) : [[''], 0, 0, 0];
|
|
1792
1762
|
|
|
1793
|
-
|
|
1763
|
+
const firstLine = ' '.repeat(Math.max(0, leftMiddle + 1))
|
|
1764
|
+
+ '_'.repeat(Math.max(0, leftWidth - leftMiddle - 1))
|
|
1765
|
+
+ line
|
|
1766
|
+
+ '_'.repeat(Math.max(0, rightMiddle))
|
|
1767
|
+
+ ' '.repeat(Math.max(0, rightWidth - rightMiddle));
|
|
1768
|
+
|
|
1769
|
+
const secondLine = (leftHeight > 0 ? ' '.repeat(leftMiddle) + '/' + ' '.repeat(leftWidth - leftMiddle - 1) : ' '.repeat(leftWidth))
|
|
1770
|
+
+ ' '.repeat(width)
|
|
1771
|
+
+ (rightHeight > 0 ? ' '.repeat(rightMiddle) + '\\' + ' '.repeat(rightWidth - rightMiddle - 1) : ' '.repeat(rightWidth));
|
|
1772
|
+
|
|
1773
|
+
const mergedLines = [firstLine, secondLine];
|
|
1774
|
+
for (let i = 0; i < Math.max(leftHeight, rightHeight); i++) {
|
|
1775
|
+
const leftLine = i < leftHeight ? leftLines[i] : ' '.repeat(leftWidth);
|
|
1776
|
+
const rightLine = i < rightHeight ? rightLines[i] : ' '.repeat(rightWidth);
|
|
1777
|
+
mergedLines.push(leftLine + ' '.repeat(width) + rightLine);
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
return [mergedLines, leftWidth + width + rightWidth, Math.max(leftHeight, rightHeight) + 2, leftWidth + Math.floor(width / 2)];
|
|
1794
1781
|
}
|
|
1795
1782
|
|
|
1796
1783
|
protected _defaultOneParamCallback = (node: N) => node.key;
|
|
@@ -103,11 +103,16 @@ export class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTr
|
|
|
103
103
|
|
|
104
104
|
while (x !== this.NIL) {
|
|
105
105
|
y = x;
|
|
106
|
-
if (x
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
if (x) {
|
|
107
|
+
if (node.key < x.key) {
|
|
108
|
+
x = x.left;
|
|
109
|
+
} else if (node.key > x.key) {
|
|
110
|
+
x = x?.right;
|
|
111
|
+
} else {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
110
114
|
}
|
|
115
|
+
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
node.parent = y;
|
package/src/types/index.ts
CHANGED
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset='UTF-8'>
|
|
5
5
|
<title>CDN Test</title>
|
|
6
|
-
|
|
7
|
-
<script src=
|
|
6
|
+
<script src="../../dist/umd/data-structure-typed.min.js"></script>
|
|
7
|
+
<!-- <script src="../../dist/umd/data-structure-typed.js"></script>-->
|
|
8
|
+
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.min.js'></script>-->
|
|
9
|
+
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.42.2/dist/umd/data-structure-typed.min.js'></script>-->
|
|
10
|
+
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.43.3/dist/umd/data-structure-typed.min.js'></script>-->
|
|
11
|
+
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.44.0/dist/umd/data-structure-typed.min.js'></script>-->
|
|
12
|
+
|
|
8
13
|
<script src='https://unpkg.com/js-sdsl@4.4.2/dist/umd/js-sdsl.js'></script>
|
|
9
14
|
</head>
|
|
10
15
|
<body>
|
|
@@ -19,17 +24,20 @@
|
|
|
19
24
|
|
|
20
25
|
try {
|
|
21
26
|
const queue = new Queue();
|
|
22
|
-
|
|
27
|
+
const n = 100000;
|
|
28
|
+
const startEn = performance.now();
|
|
29
|
+
for (let i = 0; i < n; i++) {
|
|
23
30
|
queue.enqueue(i);
|
|
24
31
|
}
|
|
32
|
+
console.log(`Queue ${n} enqueue `, performance.now() - startEn);
|
|
25
33
|
let last = 0;
|
|
26
34
|
const startTime = performance.now();
|
|
27
35
|
|
|
28
|
-
for (let i = 0; i <
|
|
36
|
+
for (let i = 0; i < n; i++) {
|
|
29
37
|
last = queue.dequeue();
|
|
30
38
|
}
|
|
31
39
|
|
|
32
|
-
console.log(performance.now() - startTime);
|
|
40
|
+
console.log(`Queue ${n} dequeue `, performance.now() - startTime);
|
|
33
41
|
|
|
34
42
|
} catch (e) {
|
|
35
43
|
console.error(e);
|
|
@@ -77,21 +85,22 @@
|
|
|
77
85
|
|
|
78
86
|
try {
|
|
79
87
|
const { OrderedMap } = sdsl;
|
|
80
|
-
const { RedBlackTree } = dataStructureTyped;
|
|
81
|
-
const
|
|
82
|
-
const
|
|
88
|
+
const { RedBlackTree, AVLTree } = dataStructureTyped;
|
|
89
|
+
const cRBTree = new OrderedMap();
|
|
90
|
+
const rbTree = new RedBlackTree();
|
|
83
91
|
const tS = performance.now();
|
|
84
|
-
|
|
85
|
-
|
|
92
|
+
const n = 100000;
|
|
93
|
+
for (let i = 1; i < n; i++) {
|
|
94
|
+
rbTree.add(i, i);
|
|
86
95
|
}
|
|
87
|
-
console.log(performance.now() - tS);
|
|
88
|
-
console.log(
|
|
96
|
+
console.log(`RedBlackTree ${n} add`, performance.now() - tS);
|
|
97
|
+
console.log(rbTree.size);
|
|
89
98
|
const cS = performance.now();
|
|
90
|
-
for (let i = 1; i <
|
|
91
|
-
|
|
99
|
+
for (let i = 1; i < 100000; i++) {
|
|
100
|
+
cRBTree.setElement(i, i);
|
|
92
101
|
}
|
|
93
|
-
console.log(performance.now() - cS);
|
|
94
|
-
console.log(
|
|
102
|
+
console.log(`CRedBlackTree ${n} add`, performance.now() - cS);
|
|
103
|
+
console.log(cRBTree.size());
|
|
95
104
|
|
|
96
105
|
// console.log(tree.isPerfectlyBalanced());
|
|
97
106
|
// tree.print();
|
|
@@ -106,27 +115,27 @@
|
|
|
106
115
|
const pq = new PriorityQueue({ comparator: (a, b) => b - a });
|
|
107
116
|
|
|
108
117
|
const tS = performance.now();
|
|
109
|
-
|
|
110
|
-
for (let i = 0; i <
|
|
118
|
+
const n = 1000000;
|
|
119
|
+
for (let i = 0; i < n; i++) {
|
|
111
120
|
pq.add(i);
|
|
112
121
|
}
|
|
113
122
|
|
|
114
|
-
for (let i = 0; i <
|
|
123
|
+
for (let i = 0; i < n; i++) {
|
|
115
124
|
pq.pop();
|
|
116
125
|
}
|
|
117
|
-
console.log(performance.now() - tS);
|
|
126
|
+
console.log(`PriorityQueue ${n} add`, performance.now() - tS);
|
|
118
127
|
console.log(pq.size);
|
|
119
128
|
const cS = performance.now();
|
|
120
129
|
const cpq = new CPriorityQueue();
|
|
121
130
|
|
|
122
|
-
for (let i = 0; i <
|
|
131
|
+
for (let i = 0; i < n; i++) {
|
|
123
132
|
cpq.push(i);
|
|
124
133
|
}
|
|
125
134
|
|
|
126
|
-
for (let i = 0; i <
|
|
135
|
+
for (let i = 0; i < n; i++) {
|
|
127
136
|
cpq.pop();
|
|
128
137
|
}
|
|
129
|
-
console.log(performance.now() - cS);
|
|
138
|
+
console.log(`CPriorityQueue ${n} add`, performance.now() - cS);
|
|
130
139
|
console.log(cpq.size());
|
|
131
140
|
} catch (e) {
|
|
132
141
|
console.error(e);
|
package/test/performance/data-structures/{comparison.test.ts → comparison/comparison.test.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PriorityQueue as MJSPriorityQueue } from '
|
|
2
|
-
import { PriorityQueue as SRCPriorityQueue } from '
|
|
3
|
-
import { PriorityQueue as CJSPriorityQueue } from '
|
|
1
|
+
import { PriorityQueue as MJSPriorityQueue } from '../../../../dist/cjs';
|
|
2
|
+
import { PriorityQueue as SRCPriorityQueue } from '../../../../src';
|
|
3
|
+
import { PriorityQueue as CJSPriorityQueue } from '../../../../dist/mjs';
|
|
4
4
|
import {
|
|
5
5
|
Deque as CDeque,
|
|
6
6
|
HashMap as CHashMap,
|
|
@@ -12,27 +12,30 @@ import {
|
|
|
12
12
|
} from 'js-sdsl';
|
|
13
13
|
|
|
14
14
|
import * as Benchmark from 'benchmark';
|
|
15
|
-
import { getRandomIntArray, magnitude } from '
|
|
16
|
-
import { isCompetitor } from '
|
|
15
|
+
import { getRandomIntArray, magnitude } from '../../../utils';
|
|
16
|
+
import { isCompetitor } from '../../../config';
|
|
17
17
|
|
|
18
18
|
const suite = new Benchmark.Suite();
|
|
19
19
|
const { TEN_THOUSAND, HUNDRED_THOUSAND, LINEAR } = magnitude;
|
|
20
20
|
const cOrderedMap = new OrderedMap<number, number>();
|
|
21
21
|
const arrHundredThousand = getRandomIntArray(HUNDRED_THOUSAND, 0, HUNDRED_THOUSAND, true);
|
|
22
22
|
|
|
23
|
-
suite
|
|
23
|
+
suite
|
|
24
|
+
.add(`SRC PQ ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
26
|
+
const pq = new SRCPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
27
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
28
|
+
})
|
|
29
|
+
.add(`CJS PQ ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
})
|
|
31
|
+
const pq = new CJSPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
32
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
33
|
+
})
|
|
34
|
+
.add(`MJS PQ ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
+
const pq = new MJSPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
37
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
38
|
+
});
|
|
36
39
|
|
|
37
40
|
if (isCompetitor) {
|
|
38
41
|
suite.add(`CPT PQ ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
@@ -42,22 +45,25 @@ if (isCompetitor) {
|
|
|
42
45
|
});
|
|
43
46
|
}
|
|
44
47
|
|
|
45
|
-
suite
|
|
46
|
-
|
|
48
|
+
suite
|
|
49
|
+
.add(`SRC PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
|
|
50
|
+
const pq = new SRCPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
53
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
|
|
54
|
+
})
|
|
55
|
+
.add(`CJS PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
|
|
56
|
+
const pq = new CJSPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
52
57
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
})
|
|
56
|
-
|
|
58
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
59
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
|
|
60
|
+
})
|
|
61
|
+
.add(`MJS PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
|
|
62
|
+
const pq = new MJSPriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
57
63
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
64
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
65
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
|
|
66
|
+
});
|
|
61
67
|
|
|
62
68
|
|
|
63
69
|
if (isCompetitor) {
|
|
@@ -83,7 +83,7 @@ suite.add(`${MILLION.toLocaleString()} Set add & has`, () => {
|
|
|
83
83
|
|
|
84
84
|
suite.add(`${MILLION.toLocaleString()} ObjKey set & get`, () => {
|
|
85
85
|
const hm = new HashMap<[number, number], number>();
|
|
86
|
-
const objKeys:[number, number][] = [];
|
|
86
|
+
const objKeys: [number, number][] = [];
|
|
87
87
|
for (let i = 0; i < MILLION; i++) {
|
|
88
88
|
const obj: [number, number] = [i, i];
|
|
89
89
|
objKeys.push(obj)
|
|
@@ -96,7 +96,7 @@ suite.add(`${MILLION.toLocaleString()} ObjKey set & get`, () => {
|
|
|
96
96
|
|
|
97
97
|
suite.add(`${MILLION.toLocaleString()} Map ObjKey set & get`, () => {
|
|
98
98
|
const hm = new Map<[number, number], number>();
|
|
99
|
-
const objs:[number, number][] = [];
|
|
99
|
+
const objs: [number, number][] = [];
|
|
100
100
|
for (let i = 0; i < MILLION; i++) {
|
|
101
101
|
const obj: [number, number] = [i, i];
|
|
102
102
|
objs.push(obj)
|
|
@@ -109,7 +109,7 @@ suite.add(`${MILLION.toLocaleString()} Map ObjKey set & get`, () => {
|
|
|
109
109
|
|
|
110
110
|
suite.add(`${MILLION.toLocaleString()} Set ObjKey add & has`, () => {
|
|
111
111
|
const hs = new Set<[number, number]>();
|
|
112
|
-
const objs:[number, number][] = [];
|
|
112
|
+
const objs: [number, number][] = [];
|
|
113
113
|
for (let i = 0; i < MILLION; i++) {
|
|
114
114
|
const obj: [number, number] = [i, i];
|
|
115
115
|
objs.push(obj)
|
|
@@ -487,4 +487,21 @@ describe('RedBlackTree', () => {
|
|
|
487
487
|
}
|
|
488
488
|
isDebug && console.log(performance.now() - cS);
|
|
489
489
|
});
|
|
490
|
+
|
|
491
|
+
it('duplicates', () => {
|
|
492
|
+
tree.addMany([9, 8, 7, 8, 8, 8, 2, 3, 6, 5, 5, 4]);
|
|
493
|
+
tree.print();
|
|
494
|
+
|
|
495
|
+
expect(tree.size).toBe(8);
|
|
496
|
+
expect(tree.isBST()).toBe(true);
|
|
497
|
+
expect(tree.isAVLBalanced()).toBe(true);
|
|
498
|
+
tree.addMany([10, 5, 2, 11]);
|
|
499
|
+
expect(tree.size).toBe(10);
|
|
500
|
+
expect(tree.isBST()).toBe(true);
|
|
501
|
+
expect(tree.isAVLBalanced()).toBe(true);
|
|
502
|
+
|
|
503
|
+
tree.clear();
|
|
504
|
+
tree.addMany([10, 20, 30, 40, 50, 60])
|
|
505
|
+
expect(tree.isAVLBalanced()).toBe(false);
|
|
506
|
+
})
|
|
490
507
|
});
|
package/tsup.config.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/types/helpers.ts"],"names":[],"mappings":";;;AAMA,IAAY,EAIX;AAJD,WAAY,EAAE;IACZ,eAAS,CAAA;IACT,eAAS,CAAA;IACT,eAAS,CAAA;AACX,CAAC,EAJW,EAAE,kBAAF,EAAE,QAIb"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|