data-structure-typed 1.50.4 → 1.50.6

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.
Files changed (82) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +116 -55
  3. package/SPECIFICATION.md +2 -2
  4. package/SPECIFICATION_zh-CN.md +81 -0
  5. package/{SPONSOR-zh-CN.md → SPONSOR_zh-CN.md} +1 -1
  6. package/benchmark/report.html +24 -24
  7. package/benchmark/report.json +261 -237
  8. package/dist/cjs/data-structures/base/iterable-base.d.ts +10 -8
  9. package/dist/cjs/data-structures/base/iterable-base.js +8 -12
  10. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.js +19 -19
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +158 -135
  14. package/dist/cjs/data-structures/binary-tree/rb-tree.js +415 -386
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  16. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +1 -0
  17. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +84 -76
  18. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  19. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -0
  20. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -0
  21. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  22. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  23. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +14 -76
  24. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +16 -86
  25. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  26. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +27 -69
  27. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +35 -79
  28. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  29. package/dist/cjs/data-structures/queue/deque.d.ts +0 -53
  30. package/dist/cjs/data-structures/queue/deque.js +0 -61
  31. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  32. package/dist/cjs/data-structures/queue/queue.d.ts +0 -70
  33. package/dist/cjs/data-structures/queue/queue.js +0 -87
  34. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  35. package/dist/mjs/data-structures/base/iterable-base.d.ts +10 -8
  36. package/dist/mjs/data-structures/base/iterable-base.js +8 -12
  37. package/dist/mjs/data-structures/binary-tree/binary-tree.js +19 -19
  38. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +158 -135
  39. package/dist/mjs/data-structures/binary-tree/rb-tree.js +412 -386
  40. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +1 -0
  41. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +84 -76
  42. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -0
  43. package/dist/mjs/data-structures/graph/abstract-graph.js +3 -0
  44. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +14 -76
  45. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +16 -86
  46. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +27 -69
  47. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +33 -79
  48. package/dist/mjs/data-structures/queue/deque.d.ts +0 -53
  49. package/dist/mjs/data-structures/queue/deque.js +0 -61
  50. package/dist/mjs/data-structures/queue/queue.d.ts +0 -70
  51. package/dist/mjs/data-structures/queue/queue.js +0 -86
  52. package/dist/umd/data-structure-typed.js +539 -756
  53. package/dist/umd/data-structure-typed.min.js +2 -2
  54. package/dist/umd/data-structure-typed.min.js.map +1 -1
  55. package/package.json +1 -1
  56. package/src/data-structures/base/iterable-base.ts +14 -10
  57. package/src/data-structures/binary-tree/binary-tree.ts +19 -19
  58. package/src/data-structures/binary-tree/rb-tree.ts +437 -395
  59. package/src/data-structures/binary-tree/tree-multi-map.ts +85 -82
  60. package/src/data-structures/graph/abstract-graph.ts +4 -0
  61. package/src/data-structures/heap/heap.ts +1 -1
  62. package/src/data-structures/linked-list/doubly-linked-list.ts +16 -94
  63. package/src/data-structures/linked-list/singly-linked-list.ts +35 -87
  64. package/src/data-structures/queue/deque.ts +0 -67
  65. package/src/data-structures/queue/queue.ts +0 -98
  66. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +3 -3
  67. package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +3 -3
  68. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +26 -16
  69. package/test/performance/data-structures/hash/hash-map.test.ts +6 -6
  70. package/test/performance/data-structures/heap/heap.test.ts +14 -14
  71. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +11 -6
  72. package/test/performance/data-structures/queue/deque.test.ts +8 -8
  73. package/test/performance/data-structures/queue/queue.test.ts +5 -12
  74. package/test/performance/reportor.ts +43 -1
  75. package/test/unit/data-structures/binary-tree/overall.test.ts +23 -21
  76. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +168 -105
  77. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +311 -192
  78. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +6 -6
  79. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +10 -10
  80. package/test/unit/data-structures/linked-list/skip-list.test.ts +4 -4
  81. package/test/unit/data-structures/queue/deque.test.ts +26 -26
  82. package/test/unit/data-structures/queue/queue.test.ts +20 -20
package/CHANGELOG.md CHANGED
@@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file.
8
8
  - [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
9
9
  - [`auto-changelog`](https://github.com/CookPete/auto-changelog)
10
10
 
11
- ## [v1.50.4](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
11
+ ## [v1.50.6](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
12
12
 
13
13
  ### Changes
14
14
 
package/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # data-structure-typed
2
2
 
3
-
4
3
  ![npm](https://img.shields.io/npm/dm/data-structure-typed)
5
4
  ![GitHub contributors](https://img.shields.io/github/contributors/zrwusa/data-structure-typed)
6
5
  ![npm package minimized gzipped size (select exports)](https://img.shields.io/bundlejs/size/data-structure-typed)
@@ -17,7 +16,8 @@
17
16
  ## Why
18
17
 
19
18
  Do you envy C++ with [STL]() (std::), Python with [collections](), and Java with [java.util]() ? Well, no need to envy
20
- anymore! JavaScript and TypeScript now have [data-structure-typed]().**`Benchmark`** compared with C++ STL. **`API standards`** aligned with ES6 and Java. **`Usability`** is comparable to Python
19
+ anymore! JavaScript and TypeScript now have [data-structure-typed]().**`Benchmark`** compared with C++ STL. *
20
+ *`API standards`** aligned with ES6 and Java. **`Usability`** is comparable to Python
21
21
 
22
22
 
23
23
  [//]: # (![Branches](https://img.shields.io/badge/branches-55.47%25-red.svg?style=flat))
@@ -28,13 +28,15 @@ anymore! JavaScript and TypeScript now have [data-structure-typed]().**`Benchmar
28
28
 
29
29
  [//]: # (![Lines](https://img.shields.io/badge/lines-68.6%25-red.svg?style=flat))
30
30
 
31
- ### We provide data structures that are not available in JS/TS
32
-
33
- Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, Directed Graph, Undirected Graph, BST, AVL Tree, Priority Queue, Queue, Tree Multiset.
31
+ ### Data structures available
34
32
 
33
+ We provide data structures that are not available in JS/TS
34
+ Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, Directed Graph, Undirected Graph, BST, AVL Tree, Priority
35
+ Queue, Queue, Tree Multiset.
35
36
 
36
- ### Performance surpasses that of native JS/TS
37
+ ### Performance
37
38
 
39
+ Performance surpasses that of native JS/TS
38
40
 
39
41
  <table style="display: table; width:100%; table-layout: fixed;">
40
42
  <thead>
@@ -99,6 +101,53 @@ Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, Directed Graph, Und
99
101
  </tbody>
100
102
  </table>
101
103
 
104
+ ### Conciseness and uniformity
105
+ In Java.utils, you need to memorize a table for all sequential data structures(Queue, Deque, LinkedList),
106
+
107
+ <table>
108
+ <thead>
109
+ <tr>
110
+ <th>Operation</th>
111
+ <th>Java ArrayList</th>
112
+ <th>Java Queue</th>
113
+ <th>Java ArrayDeque</th>
114
+ <th>Java LinkedList</th>
115
+ </tr>
116
+ </thead>
117
+ <tbody>
118
+ <tr>
119
+ <td>push</td>
120
+ <td>add</td>
121
+ <td>offer</td>
122
+ <td>push</td>
123
+ <td>push</td>
124
+ </tr>
125
+ <tr>
126
+ <td>pop</td>
127
+ <td>remove</td>
128
+ <td>poll</td>
129
+ <td>removeLast</td>
130
+ <td>removeLast</td>
131
+ </tr>
132
+ <tr>
133
+ <td>shift</td>
134
+ <td>remove</td>
135
+ <td>poll</td>
136
+ <td>removeFirst</td>
137
+ <td>removeFirst</td>
138
+ </tr>
139
+ <tr>
140
+ <td>unshift</td>
141
+ <td>add(0, element)</td>
142
+ <td>offerFirst</td>
143
+ <td>unshift</td>
144
+ <td>unshift</td>
145
+ </tr>
146
+ </tbody>
147
+ </table>
148
+
149
+ whereas in our data-structure-typed, you **only** need to remember four methods: `push`, `pop`, `shift`, and `unshift` for all sequential data structures.
150
+
102
151
  ## Installation and Usage
103
152
 
104
153
  ### npm
@@ -155,7 +204,7 @@ our [visual tool](https://github.com/zrwusa/vivid-algorithm)
155
204
  #### TS
156
205
 
157
206
  ```ts
158
- import {RedBlackTree} from 'data-structure-typed';
207
+ import { RedBlackTree } from 'data-structure-typed';
159
208
 
160
209
  const rbTree = new RedBlackTree<number>();
161
210
  rbTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
@@ -177,7 +226,7 @@ rbTree.print()
177
226
  #### JS
178
227
 
179
228
  ```js
180
- import {RedBlackTree} from 'data-structure-typed';
229
+ import { RedBlackTree } from 'data-structure-typed';
181
230
 
182
231
  const rbTree = new RedBlackTree();
183
232
  rbTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
@@ -204,31 +253,31 @@ const orgStrArr = ["trie", "trial", "trick", "trip", "tree", "trend", "triangle"
204
253
  const entries = [[6, "6"], [1, "1"], [2, "2"], [7, "7"], [5, "5"], [3, "3"], [4, "4"], [9, "9"], [8, "8"]];
205
254
 
206
255
  const queue = new Queue(orgArr);
207
- queue.print();
256
+ queue.print();
208
257
  // [6, 1, 2, 7, 5, 3, 4, 9, 8]
209
258
 
210
259
  const deque = new Deque(orgArr);
211
- deque.print();
260
+ deque.print();
212
261
  // [6, 1, 2, 7, 5, 3, 4, 9, 8]
213
262
 
214
263
  const sList = new SinglyLinkedList(orgArr);
215
- sList.print();
264
+ sList.print();
216
265
  // [6, 1, 2, 7, 5, 3, 4, 9, 8]
217
266
 
218
267
  const dList = new DoublyLinkedList(orgArr);
219
- dList.print();
268
+ dList.print();
220
269
  // [6, 1, 2, 7, 5, 3, 4, 9, 8]
221
270
 
222
271
  const stack = new Stack(orgArr);
223
- stack.print();
272
+ stack.print();
224
273
  // [6, 1, 2, 7, 5, 3, 4, 9, 8]
225
274
 
226
275
  const minHeap = new MinHeap(orgArr);
227
- minHeap.print();
276
+ minHeap.print();
228
277
  // [1, 5, 2, 7, 6, 3, 4, 9, 8]
229
278
 
230
279
  const maxPQ = new MaxPriorityQueue(orgArr);
231
- maxPQ.print();
280
+ maxPQ.print();
232
281
  // [9, 8, 4, 7, 5, 2, 3, 1, 6]
233
282
 
234
283
  const biTree = new BinaryTree(entries);
@@ -284,7 +333,7 @@ treeMulti.print();
284
333
  // 7 9
285
334
 
286
335
  const hm = new HashMap(entries);
287
- hm.print()
336
+ hm.print()
288
337
  // [[6, "6"], [1, "1"], [2, "2"], [7, "7"], [5, "5"], [3, "3"], [4, "4"], [9, "9"], [8, "8"]]
289
338
 
290
339
  const rbTreeH = new RedBlackTree(hm);
@@ -298,7 +347,7 @@ rbTreeH.print();
298
347
  // 7 9
299
348
 
300
349
  const pq = new MinPriorityQueue(orgArr);
301
- pq.print();
350
+ pq.print();
302
351
  // [1, 5, 2, 7, 6, 3, 4, 9, 8]
303
352
 
304
353
  const bst1 = new BST(pq);
@@ -312,7 +361,7 @@ bst1.print();
312
361
  // 4 9
313
362
 
314
363
  const dq1 = new Deque(orgArr);
315
- dq1.print();
364
+ dq1.print();
316
365
  // [6, 1, 2, 7, 5, 3, 4, 9, 8]
317
366
  const rbTree1 = new RedBlackTree(dq1);
318
367
  rbTree1.print();
@@ -326,13 +375,13 @@ rbTree1.print();
326
375
 
327
376
 
328
377
  const trie2 = new Trie(orgStrArr);
329
- trie2.print();
378
+ trie2.print();
330
379
  // ['trie', 'trial', 'triangle', 'trick', 'trip', 'tree', 'trend', 'track', 'trace', 'transmit']
331
380
  const heap2 = new Heap(trie2, { comparator: (a, b) => Number(a) - Number(b) });
332
- heap2.print();
381
+ heap2.print();
333
382
  // ['transmit', 'trace', 'tree', 'trend', 'track', 'trial', 'trip', 'trie', 'trick', 'triangle']
334
383
  const dq2 = new Deque(heap2);
335
- dq2.print();
384
+ dq2.print();
336
385
  // ['transmit', 'trace', 'tree', 'trend', 'track', 'trial', 'trip', 'trie', 'trick', 'triangle']
337
386
  const entries2 = dq2.map((el, i) => [i, el]);
338
387
  const avl2 = new AVLTree(entries2);
@@ -349,7 +398,7 @@ avl2.print();
349
398
  ### Binary Search Tree (BST) snippet
350
399
 
351
400
  ```ts
352
- import {BST, BSTNode} from 'data-structure-typed';
401
+ import { BST, BSTNode } from 'data-structure-typed';
353
402
 
354
403
  const bst = new BST<number>();
355
404
  bst.add(11);
@@ -381,7 +430,7 @@ bst.print()
381
430
  // \
382
431
  // 7
383
432
 
384
- const objBST = new BST<number, {height: number, age: number}>();
433
+ const objBST = new BST<number, { height: number, age: number }>();
385
434
 
386
435
  objBST.add(11, { "name": "Pablo", "age": 15 });
387
436
  objBST.add(3, { "name": "Kirk", "age": 1 });
@@ -410,7 +459,7 @@ objBST.delete(11);
410
459
  ### AVLTree snippet
411
460
 
412
461
  ```ts
413
- import {AVLTree} from 'data-structure-typed';
462
+ import { AVLTree } from 'data-structure-typed';
414
463
 
415
464
  const avlTree = new AVLTree<number>();
416
465
  avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
@@ -422,7 +471,7 @@ avlTree.isAVLBalanced(); // true
422
471
  ### Directed Graph simple snippet
423
472
 
424
473
  ```ts
425
- import {DirectedGraph} from 'data-structure-typed';
474
+ import { DirectedGraph } from 'data-structure-typed';
426
475
 
427
476
  const graph = new DirectedGraph<string>();
428
477
 
@@ -451,7 +500,7 @@ const topologicalOrderKeys = graph.topologicalSort(); // ['A', 'B', 'C']
451
500
  ### Undirected Graph snippet
452
501
 
453
502
  ```ts
454
- import {UndirectedGraph} from 'data-structure-typed';
503
+ import { UndirectedGraph } from 'data-structure-typed';
455
504
 
456
505
  const graph = new UndirectedGraph<string>();
457
506
  graph.addVertex('A');
@@ -885,7 +934,10 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', '
885
934
 
886
935
  ## Software Engineering Design Standards
887
936
 
888
- We strictly adhere to computer science theory and software development standards. Our LinkedList is designed in the traditional sense of the LinkedList data structure, and we refrain from substituting it with a Deque solely for the purpose of showcasing performance test data. However, we have also implemented a Deque based on a dynamic array concurrently.
937
+ We strictly adhere to computer science theory and software development standards. Our LinkedList is designed in the
938
+ traditional sense of the LinkedList data structure, and we refrain from substituting it with a Deque solely for the
939
+ purpose of showcasing performance test data. However, we have also implemented a Deque based on a dynamic array
940
+ concurrently.
889
941
 
890
942
 
891
943
  <table style="display: table; width:100%; table-layout: fixed;">
@@ -935,56 +987,63 @@ We strictly adhere to computer science theory and software development standards
935
987
  </tr>
936
988
  </table>
937
989
 
938
-
939
990
  ## Benchmark
940
991
 
992
+ macOS Big Sur
993
+ Version 11.7.9
994
+
995
+ MacBook Pro (15-inch, 2018)
996
+ Processor 2.2 GHz 6-Core Intel Core i7
997
+ Memory 16 GB 2400 MHz DDR4
998
+ Graphics Radeon Pro 555X 4 GB
999
+ Intel UHD Graphics 630 1536 MB
1000
+
941
1001
  [//]: # (No deletion!!! Start of Replace Section)
942
1002
  <div class="json-to-html-collapse clearfix 0">
943
- <div class='collapsible level0' ><span class='json-to-html-label'>avl-tree</span></div>
944
- <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 add randomly</td><td>125.60</td><td>7.96</td><td>0.00</td></tr><tr><td>10,000 add & delete randomly</td><td>181.22</td><td>5.52</td><td>0.00</td></tr><tr><td>10,000 addMany</td><td>134.12</td><td>7.46</td><td>0.01</td></tr><tr><td>10,000 get</td><td>55.08</td><td>18.16</td><td>0.01</td></tr></table></div>
945
- </div><div class="json-to-html-collapse clearfix 0">
946
- <div class='collapsible level0' ><span class='json-to-html-label'>binary-tree-overall</span></div>
947
- <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 RBTree add</td><td>6.17</td><td>161.95</td><td>0.00</td></tr><tr><td>10,000 RBTree add & delete randomly</td><td>16.07</td><td>62.22</td><td>2.62e-4</td></tr><tr><td>10,000 RBTree get</td><td>19.86</td><td>50.36</td><td>2.44e-4</td></tr><tr><td>10,000 AVLTree add</td><td>134.38</td><td>7.44</td><td>0.02</td></tr><tr><td>10,000 AVLTree add & delete randomly</td><td>207.20</td><td>4.83</td><td>0.06</td></tr><tr><td>10,000 AVLTree get</td><td>0.98</td><td>1015.54</td><td>2.73e-5</td></tr></table></div>
1003
+ <div class='collapsible level0' ><span class='json-to-html-label'>heap</span></div>
1004
+ <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>6.42</td><td>155.87</td><td>1.90e-4</td></tr><tr><td>100,000 add & poll</td><td>31.50</td><td>31.74</td><td>8.72e-4</td></tr></table></div>
948
1005
  </div><div class="json-to-html-collapse clearfix 0">
949
1006
  <div class='collapsible level0' ><span class='json-to-html-label'>rb-tree</span></div>
950
- <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>86.65</td><td>11.54</td><td>0.02</td></tr><tr><td>100,000 add & delete randomly</td><td>221.02</td><td>4.52</td><td>0.03</td></tr><tr><td>100,000 getNode</td><td>190.54</td><td>5.25</td><td>0.00</td></tr><tr><td>100,000 add & iterator</td><td>122.10</td><td>8.19</td><td>0.01</td></tr></table></div>
1007
+ <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add orderly</td><td>42.46</td><td>23.55</td><td>0.01</td></tr><tr><td>100,000 delete orderly</td><td>176.04</td><td>5.68</td><td>0.01</td></tr><tr><td>100,000 add randomly</td><td>98.02</td><td>10.20</td><td>0.00</td></tr><tr><td>100,000 delete randomly</td><td>182.58</td><td>5.48</td><td>0.00</td></tr><tr><td>100,000 add orderly</td><td>42.10</td><td>23.76</td><td>8.79e-4</td></tr><tr><td>100,000 delete randomly</td><td>182.16</td><td>5.49</td><td>5.65e-4</td></tr><tr><td>100,000 getNode randomly</td><td>180.63</td><td>5.54</td><td>0.00</td></tr><tr><td>100,000 add & iterator</td><td>129.92</td><td>7.70</td><td>0.00</td></tr></table></div>
951
1008
  </div><div class="json-to-html-collapse clearfix 0">
952
- <div class='collapsible level0' ><span class='json-to-html-label'>directed-graph</span></div>
953
- <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000 addVertex</td><td>0.11</td><td>8896.51</td><td>2.63e-5</td></tr><tr><td>1,000 addEdge</td><td>6.53</td><td>153.21</td><td>0.00</td></tr><tr><td>1,000 getVertex</td><td>0.05</td><td>2.08e+4</td><td>1.06e-5</td></tr><tr><td>1,000 getEdge</td><td>27.53</td><td>36.33</td><td>0.01</td></tr><tr><td>tarjan</td><td>224.53</td><td>4.45</td><td>0.01</td></tr><tr><td>topologicalSort</td><td>184.02</td><td>5.43</td><td>0.00</td></tr></table></div>
1009
+ <div class='collapsible level0' ><span class='json-to-html-label'>queue</span></div>
1010
+ <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>44.33</td><td>22.56</td><td>0.01</td></tr><tr><td>100,000 push & shift</td><td>4.68</td><td>213.63</td><td>1.41e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>2633.11</td><td>0.38</td><td>0.44</td></tr></table></div>
1011
+ </div><div class="json-to-html-collapse clearfix 0">
1012
+ <div class='collapsible level0' ><span class='json-to-html-label'>deque</span></div>
1013
+ <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>24.62</td><td>40.62</td><td>0.00</td></tr><tr><td>1,000,000 push & pop</td><td>30.71</td><td>32.56</td><td>0.00</td></tr><tr><td>1,000,000 push & shift</td><td>31.93</td><td>31.32</td><td>0.01</td></tr><tr><td>100,000 push & shift</td><td>3.25</td><td>307.22</td><td>2.74e-4</td></tr><tr><td>Native JS Array 100,000 push & shift</td><td>2455.51</td><td>0.41</td><td>0.29</td></tr><tr><td>100,000 unshift & shift</td><td>2.94</td><td>340.31</td><td>2.39e-4</td></tr><tr><td>Native JS Array 100,000 unshift & shift</td><td>4314.20</td><td>0.23</td><td>0.41</td></tr></table></div>
954
1014
  </div><div class="json-to-html-collapse clearfix 0">
955
1015
  <div class='collapsible level0' ><span class='json-to-html-label'>hash-map</span></div>
956
- <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 set</td><td>126.27</td><td>7.92</td><td>0.05</td></tr><tr><td>Native Map 1,000,000 set</td><td>229.80</td><td>4.35</td><td>0.03</td></tr><tr><td>Native Set 1,000,000 add</td><td>175.83</td><td>5.69</td><td>0.01</td></tr><tr><td>1,000,000 set & get</td><td>121.34</td><td>8.24</td><td>0.03</td></tr><tr><td>Native Map 1,000,000 set & get</td><td>290.80</td><td>3.44</td><td>0.03</td></tr><tr><td>Native Set 1,000,000 add & has</td><td>180.71</td><td>5.53</td><td>0.01</td></tr><tr><td>1,000,000 ObjKey set & get</td><td>357.68</td><td>2.80</td><td>0.07</td></tr><tr><td>Native Map 1,000,000 ObjKey set & get</td><td>310.57</td><td>3.22</td><td>0.06</td></tr><tr><td>Native Set 1,000,000 ObjKey add & has</td><td>278.42</td><td>3.59</td><td>0.05</td></tr></table></div>
1016
+ <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 set</td><td>116.60</td><td>8.58</td><td>0.02</td></tr><tr><td>Native JS Map 1,000,000 set</td><td>202.39</td><td>4.94</td><td>0.01</td></tr><tr><td>Native JS Set 1,000,000 add</td><td>167.89</td><td>5.96</td><td>0.01</td></tr><tr><td>1,000,000 set & get</td><td>125.21</td><td>7.99</td><td>0.03</td></tr><tr><td>Native JS Map 1,000,000 set & get</td><td>272.20</td><td>3.67</td><td>0.03</td></tr><tr><td>Native JS Set 1,000,000 add & has</td><td>168.51</td><td>5.93</td><td>0.01</td></tr><tr><td>1,000,000 ObjKey set & get</td><td>309.10</td><td>3.24</td><td>0.01</td></tr><tr><td>Native JS Map 1,000,000 ObjKey set & get</td><td>299.43</td><td>3.34</td><td>0.03</td></tr><tr><td>Native JS Set 1,000,000 ObjKey add & has</td><td>260.93</td><td>3.83</td><td>0.02</td></tr></table></div>
957
1017
  </div><div class="json-to-html-collapse clearfix 0">
958
- <div class='collapsible level0' ><span class='json-to-html-label'>heap</span></div>
959
- <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add & poll</td><td>24.85</td><td>40.24</td><td>0.00</td></tr><tr><td>100,000 add & dfs</td><td>33.14</td><td>30.17</td><td>0.00</td></tr><tr><td>10,000 fib add & pop</td><td>366.11</td><td>2.73</td><td>0.00</td></tr></table></div>
1018
+ <div class='collapsible level0' ><span class='json-to-html-label'>trie</span></div>
1019
+ <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 push</td><td>43.32</td><td>23.08</td><td>6.16e-4</td></tr><tr><td>100,000 getWords</td><td>84.84</td><td>11.79</td><td>0.00</td></tr></table></div>
1020
+ </div><div class="json-to-html-collapse clearfix 0">
1021
+ <div class='collapsible level0' ><span class='json-to-html-label'>avl-tree</span></div>
1022
+ <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 add randomly</td><td>129.04</td><td>7.75</td><td>0.00</td></tr><tr><td>10,000 get</td><td>51.31</td><td>19.49</td><td>5.76e-4</td></tr><tr><td>10,000 add & delete randomly</td><td>190.44</td><td>5.25</td><td>0.00</td></tr><tr><td>10,000 addMany</td><td>137.94</td><td>7.25</td><td>0.00</td></tr></table></div>
1023
+ </div><div class="json-to-html-collapse clearfix 0">
1024
+ <div class='collapsible level0' ><span class='json-to-html-label'>binary-tree-overall</span></div>
1025
+ <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>10,000 RBTree add</td><td>8.13</td><td>122.97</td><td>1.87e-4</td></tr><tr><td>10,000 RBTree add & delete randomly</td><td>58.30</td><td>17.15</td><td>5.24e-4</td></tr><tr><td>10,000 RBTree get</td><td>18.16</td><td>55.06</td><td>2.06e-4</td></tr><tr><td>10,000 AVLTree add</td><td>129.10</td><td>7.75</td><td>0.00</td></tr><tr><td>10,000 AVLTree get</td><td>51.37</td><td>19.47</td><td>7.26e-4</td></tr><tr><td>10,000 AVLTree add & delete randomly</td><td>189.84</td><td>5.27</td><td>8.96e-4</td></tr></table></div>
1026
+ </div><div class="json-to-html-collapse clearfix 0">
1027
+ <div class='collapsible level0' ><span class='json-to-html-label'>directed-graph</span></div>
1028
+ <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000 addVertex</td><td>0.10</td><td>9882.73</td><td>1.12e-6</td></tr><tr><td>1,000 addEdge</td><td>6.18</td><td>161.76</td><td>7.54e-4</td></tr><tr><td>1,000 getVertex</td><td>0.05</td><td>2.17e+4</td><td>3.35e-7</td></tr><tr><td>1,000 getEdge</td><td>23.36</td><td>42.81</td><td>0.00</td></tr><tr><td>tarjan</td><td>208.84</td><td>4.79</td><td>0.01</td></tr><tr><td>topologicalSort</td><td>178.78</td><td>5.59</td><td>0.00</td></tr></table></div>
960
1029
  </div><div class="json-to-html-collapse clearfix 0">
961
1030
  <div class='collapsible level0' ><span class='json-to-html-label'>doubly-linked-list</span></div>
962
- <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>217.98</td><td>4.59</td><td>0.07</td></tr><tr><td>1,000,000 unshift</td><td>223.20</td><td>4.48</td><td>0.08</td></tr><tr><td>1,000,000 unshift & shift</td><td>172.87</td><td>5.78</td><td>0.03</td></tr><tr><td>1,000,000 addBefore</td><td>387.13</td><td>2.58</td><td>0.20</td></tr></table></div>
1031
+ <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>217.73</td><td>4.59</td><td>0.05</td></tr><tr><td>1,000,000 unshift</td><td>200.41</td><td>4.99</td><td>0.04</td></tr><tr><td>1,000,000 unshift & shift</td><td>168.75</td><td>5.93</td><td>0.04</td></tr><tr><td>1,000,000 addBefore</td><td>298.21</td><td>3.35</td><td>0.06</td></tr></table></div>
963
1032
  </div><div class="json-to-html-collapse clearfix 0">
964
1033
  <div class='collapsible level0' ><span class='json-to-html-label'>singly-linked-list</span></div>
965
- <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push & shift</td><td>225.13</td><td>4.44</td><td>0.07</td></tr><tr><td>10,000 push & pop</td><td>234.54</td><td>4.26</td><td>0.02</td></tr><tr><td>10,000 addBefore</td><td>252.62</td><td>3.96</td><td>0.00</td></tr></table></div>
1034
+ <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push & shift</td><td>196.65</td><td>5.09</td><td>0.04</td></tr><tr><td>10,000 push & pop</td><td>221.63</td><td>4.51</td><td>0.02</td></tr><tr><td>10,000 addBefore</td><td>249.40</td><td>4.01</td><td>0.01</td></tr></table></div>
966
1035
  </div><div class="json-to-html-collapse clearfix 0">
967
1036
  <div class='collapsible level0' ><span class='json-to-html-label'>priority-queue</span></div>
968
- <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add & poll</td><td>76.49</td><td>13.07</td><td>0.00</td></tr></table></div>
969
- </div><div class="json-to-html-collapse clearfix 0">
970
- <div class='collapsible level0' ><span class='json-to-html-label'>deque</span></div>
971
- <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>13.20</td><td>75.75</td><td>2.79e-4</td></tr><tr><td>1,000,000 push & pop</td><td>22.21</td><td>45.03</td><td>3.27e-4</td></tr><tr><td>100,000 push & shift</td><td>2.26</td><td>442.24</td><td>1.43e-4</td></tr><tr><td>Native Array 100,000 push & shift</td><td>2329.51</td><td>0.43</td><td>0.10</td></tr><tr><td>100,000 unshift & shift</td><td>2.16</td><td>463.83</td><td>8.20e-5</td></tr><tr><td>Native Array 100,000 unshift & shift</td><td>4590.64</td><td>0.22</td><td>0.33</td></tr></table></div>
972
- </div><div class="json-to-html-collapse clearfix 0">
973
- <div class='collapsible level0' ><span class='json-to-html-label'>queue</span></div>
974
- <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>49.92</td><td>20.03</td><td>0.02</td></tr><tr><td>100,000 push & shift</td><td>5.07</td><td>197.28</td><td>5.86e-4</td></tr><tr><td>Native Array 100,000 push & shift</td><td>2315.78</td><td>0.43</td><td>0.13</td></tr><tr><td>Native Array 100,000 push & pop</td><td>4.37</td><td>228.72</td><td>1.32e-4</td></tr></table></div>
1037
+ <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 add</td><td>28.95</td><td>34.55</td><td>0.00</td></tr><tr><td>100,000 add & poll</td><td>76.25</td><td>13.11</td><td>6.57e-4</td></tr></table></div>
975
1038
  </div><div class="json-to-html-collapse clearfix 0">
976
1039
  <div class='collapsible level0' ><span class='json-to-html-label'>stack</span></div>
977
- <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>44.50</td><td>22.47</td><td>0.01</td></tr><tr><td>1,000,000 push & pop</td><td>53.57</td><td>18.67</td><td>0.02</td></tr></table></div>
978
- </div><div class="json-to-html-collapse clearfix 0">
979
- <div class='collapsible level0' ><span class='json-to-html-label'>trie</span></div>
980
- <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>100,000 push</td><td>42.95</td><td>23.28</td><td>6.68e-4</td></tr><tr><td>100,000 getWords</td><td>92.11</td><td>10.86</td><td>0.01</td></tr></table></div>
1040
+ <div class="content"><table style="display: table; width:100%; table-layout: fixed;"><tr><th>test name</th><th>time taken (ms)</th><th>executions per sec</th><th>sample deviation</th></tr><tr><td>1,000,000 push</td><td>39.72</td><td>25.18</td><td>0.01</td></tr><tr><td>1,000,000 push & pop</td><td>49.18</td><td>20.33</td><td>0.01</td></tr></table></div>
981
1041
  </div>
982
1042
 
983
1043
  [//]: # (No deletion!!! End of Replace Section)
984
1044
 
985
-
986
-
987
1045
  ## supported module system
1046
+
988
1047
  Now you can use it in Node.js and browser environments
989
1048
 
990
1049
  CommonJS:**`require export.modules =`**
@@ -1002,19 +1061,21 @@ Copy the line below into the head tag in an HTML document.
1002
1061
  #### development
1003
1062
 
1004
1063
  ```html
1064
+
1005
1065
  <script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.js'></script>
1006
1066
  ```
1007
1067
 
1008
1068
  #### production
1009
1069
 
1010
1070
  ```html
1071
+
1011
1072
  <script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.min.js'></script>
1012
1073
  ```
1013
1074
 
1014
1075
  Copy the code below into the script tag of your HTML, and you're good to go with your development.
1015
1076
 
1016
1077
  ```js
1017
- const {Heap} = dataStructureTyped;
1078
+ const { Heap } = dataStructureTyped;
1018
1079
  const {
1019
1080
  BinaryTree, Graph, Queue, Stack, PriorityQueue, BST, Trie, DoublyLinkedList,
1020
1081
  AVLTree, MinHeap, SinglyLinkedList, DirectedGraph, TreeMultiMap,
package/SPECIFICATION.md CHANGED
@@ -45,7 +45,7 @@
45
45
 
46
46
  ### Use of Commonly Understood Industry Standard Naming
47
47
 
48
- - `enqueue`, `dequeue`, `push`, `pop`, `poll`, `addLast`, `addFirst`, `pollFirst`, `pollLast`, `isEmpty`, `clear`, `print`, `clone`.
48
+ - `enqueue`, `dequeue`, `push`, `pop`, `poll`, `push`, `unshift`, `shift`, `pop`, `isEmpty`, `clear`, `print`, `clone`.
49
49
 
50
50
  ### Implementation of Customizable Features Whenever Possible
51
51
 
@@ -53,4 +53,4 @@
53
53
 
54
54
  ### Comprehensive Documentation
55
55
 
56
- - The documentation not only explains the purpose of methods but also annotates time and space complexity across the entire series.
56
+ - The documentation not only explains the purpose of methods but also annotates time and space complexity across the entire series.
@@ -0,0 +1,81 @@
1
+
2
+ [NPM](https://www.npmjs.com/package/data-structure-typed)
3
+
4
+ [Github](https://github.com/zrwusa/data-structure-typed)
5
+
6
+ ## Pain Points Addressed
7
+
8
+ ### Enhancing the Performance of Simulated Data Structures in JS/TS
9
+
10
+ - `Queue`: While many resort to using Arrays to simulate Queues and Deques, the time complexity of Array.shift is O(n). We have tackled this challenge by implementing a Queue and Deque with O(1) time complexity for enqueue and dequeue operations.
11
+
12
+ - `HashMap`: Opting for a pure HashMap over the built-in Map (technically a LinkedHashMap) can boost algorithmic speed. However, the performance is compromised due to the necessity of considering insertion order. We have independently implemented an optimized HashMap.
13
+
14
+ - `Stack`: In JS, simulating a Stack with an Array is acceptable, and its performance is on par with a genuine Stack.
15
+
16
+ ### Introducing Missing Native Data Structures in JS/TS
17
+
18
+ - `Heap / Priority Queue`: Algorithms with O(log n) time complexity have been pivotal in improving efficiency since the dawn of computers. A Heap supports insertion, deletion, and search with O(log n) time complexity, coupled with the ability to obtain the minimum / maximum value in O(1) time.
19
+
20
+ - `Red Black Tree`: Developers well-versed in databases, file systems, Linux virtual memory management, and network routing tables often have a nuanced understanding of Red-Black Trees. It stands out as the least operation-intensive among all balanced binary search trees, offering optimal performance balance in CRUD operations.
21
+
22
+ - `Linked List`: In scenarios where insertion or deletion of elements with O(1) time complexity is required at a specific index in an ordered collection, JS lacks a provided data structure. Hence, the need for a LinkedList to implement this functionality.
23
+
24
+ - `Trie`: Efficient for fast string queries and space-efficient string storage, yet not commonly found in the standard libraries of most programming languages.
25
+
26
+ - `Graph`: This data structure is not commonly found in the standard libraries of most languages, making it a non-issue in JS.
27
+
28
+ ## Advantages
29
+
30
+ ### Performance:
31
+
32
+ - The performance of some ours data structures has surpassed JS's built-in data structures (`Queue`, `Deque`, `HashMap`), while most are comparable to or even surpass those in other languages. Some are still undergoing refinement (`Graph`, `AVL Tree`).
33
+
34
+ ### Uniformity
35
+
36
+ - 1. Implementation or constraint of `forEach`, `filter`, `map`, `every`, `some`, `reduce`, `find`, `has`, `hasValue`, `get`, `print`, `isEmpty`, `clear`, `clone` methods in the base class.
37
+ - 2. Use of generators to uniformly implement `[Symbol.iterator]`, `entries`, `keys`, `values`. Delaying iterator execution prevents performance loss and provides control during traversal.
38
+ - 3. All deletion methods uniformly use the widely adopted `delete` in ES6, while addition methods uniformly use `add`. Compatibility with some specifications in Java.
39
+ - 4. The first parameter for all constructors is data, and the second parameter is configuration, maintaining uniformity. The first parameter accepts any iterable type for seamless conversion between data structures.
40
+ - 5. Uniform return types, for example, the `add` method consistently returns a boolean.
41
+
42
+ ### Convenience and Simplicity of APIs
43
+
44
+ - Inspired by ES6, Java, ESNext, TypeScript, Python, featuring methods like `forEach`, `filter`, `map`, `every`, `some`, `reduce`, `find`, `has`, `hasValue` and `get`.
45
+
46
+ ### Use of Commonly Understood Industry Standard Naming
47
+
48
+ - `enqueue`, `dequeue`, `push`, `pop`, `poll`, `push`, `unshift`, `shift`, `pop`, `isEmpty`, `clear`, `print`, `clone`.
49
+
50
+ ### Implementation of Customizable Features Whenever Possible
51
+
52
+ - Such as providing callback functions (lambda expressions) for all traversal methods.
53
+
54
+ ### Comprehensive Documentation
55
+
56
+ - The documentation not only explains the purpose of methods but also annotates time and space complexity across the entire series.
57
+
58
+ 像getter和setter是优于Java的getXxx和setXxx
59
+
60
+ Java中
61
+ 添加元素(类似 push):
62
+ add(E element): 将元素添加到列表的末尾。
63
+ add(int index, E element): 在指定的索引位置插入元素。
64
+
65
+ 移除元素(类似 pop):
66
+ remove(int index): 移除指定索引位置的元素。
67
+
68
+ 获取并移除首个元素(类似 shift):
69
+ remove(0): 移除索引为0的元素。
70
+
71
+ 在首位插入元素(类似 unshift):
72
+ add(0, E element): 在指定索引(0)处插入元素。
73
+
74
+
75
+ 大多数程序员更喜欢JS中的Array的push, pop, shift, unshift。
76
+
77
+ 原因有以下几点:
78
+
79
+ 命名更直观。JS中的push, pop, shift, unshift的命名更加直观,可以直接理解其操作的含义。而Java中的add和remove的命名则比较抽象,需要一定的理解才能理解其操作的含义。
80
+ 使用更方便。JS中的push, pop, shift, unshift的操作更加方便,只需要一个参数即可完成操作。而Java中的add和remove的操作则需要两个参数,第一个参数指定操作的索引,第二个参数指定操作的值。
81
+ 性能更高。JS中的push, pop, shift, unshift的性能更高,因为其操作只需要修改数组的长度即可完成。而Java中的add和remove的性能则较低,因为其操作需要移动数组中的元素。
@@ -68,7 +68,7 @@
68
68
 
69
69
  ### 使用通俗易懂业界常用命名
70
70
 
71
- - `enqueue`, `dequeue`, `push`, `pop`, `poll`, `addLast`, `addFirst`, `pollFirst`, `pollLast`, `isEmpty`, `clear`, `print`, `clone`
71
+ - `enqueue`, `dequeue`, `push`, `pop`, `poll`, `push`, `unshift`, `shift`, `pop`, `isEmpty`, `clear`, `print`, `clone`
72
72
 
73
73
  ### 尽量实现可定制化功能
74
74