data-structure-typed 2.1.1 → 2.1.2

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 (51) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +19 -7
  3. package/dist/cjs/index.cjs +22 -22
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +22 -22
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +1 -1
  8. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
  9. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +1 -1
  10. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  11. package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
  12. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +2 -2
  13. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +1 -1
  14. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
  15. package/dist/types/data-structures/heap/heap.d.ts +4 -4
  16. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -1
  17. package/dist/types/interfaces/binary-tree.d.ts +1 -1
  18. package/dist/umd/data-structure-typed.js +87 -165
  19. package/dist/umd/data-structure-typed.js.map +1 -1
  20. package/dist/umd/data-structure-typed.min.js +2 -2
  21. package/dist/umd/data-structure-typed.min.js.map +1 -1
  22. package/jest.integration.config.js +7 -3
  23. package/package.json +11 -7
  24. package/src/data-structures/binary-tree/avl-tree-counter.ts +4 -4
  25. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
  26. package/src/data-structures/binary-tree/avl-tree.ts +2 -2
  27. package/src/data-structures/binary-tree/binary-tree.ts +4 -4
  28. package/src/data-structures/binary-tree/bst.ts +1 -1
  29. package/src/data-structures/binary-tree/red-black-tree.ts +2 -2
  30. package/src/data-structures/binary-tree/tree-counter.ts +4 -4
  31. package/src/data-structures/binary-tree/tree-multi-map.ts +1 -1
  32. package/src/data-structures/heap/heap.ts +5 -5
  33. package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
  34. package/src/interfaces/binary-tree.ts +1 -1
  35. package/test/integration/compile.test.mjs +159 -0
  36. package/test/integration/compile.test.ts +176 -0
  37. package/test/integration/heap.test.js +1 -1
  38. package/test/integration/index.html +1 -1
  39. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +3 -3
  40. package/{tsconfig-base.json → tsconfig.base.json} +0 -1
  41. package/tsconfig.test.json +1 -0
  42. package/{tsconfig-types.json → tsconfig.types.json} +1 -3
  43. package/tsup.config.js +2 -3
  44. package/dist/index.cjs +0 -13091
  45. package/dist/index.cjs.map +0 -1
  46. package/dist/index.js +0 -13013
  47. package/dist/index.js.map +0 -1
  48. package/test/integration/compile.js +0 -144
  49. package/test/integration/compile.mjs +0 -135
  50. package/test/integration/compile.ts +0 -171
  51. /package/{tsup.node.config.ts → tsup.node.config.js} +0 -0
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
- ## [v2.1.1](https://github.com/zrwusa/data-structure-typed/compare/v2.0.4...main) (upcoming)
11
+ ## [v2.1.2](https://github.com/zrwusa/data-structure-typed/compare/v2.0.4...main) (upcoming)
12
12
 
13
13
  ### Changes
14
14
 
package/README.md CHANGED
@@ -32,7 +32,6 @@ yarn add data-structure-typed
32
32
 
33
33
  [Playground](https://stackblitz.com/edit/data-structure-typed-playground?file=src%2Fmain.ts)
34
34
 
35
-
36
35
  ```js
37
36
  import {
38
37
  Heap, Graph, Queue, Deque, PriorityQueue, BST, Trie, DoublyLinkedList,
@@ -50,7 +49,7 @@ npm i heap-typed --save
50
49
  ## Why
51
50
 
52
51
  Do you envy C++ with [STL]() (std::), Python with [collections](), and Java with [java.util]() ? Well, no need to envy
53
- anymore! JavaScript and TypeScript now have [data-structure-typed]().**`Benchmark`** compared with C++ STL.
52
+ anymore! JavaScript and TypeScript now have [data-structure-typed]().**`Benchmark`** compared with C++ STL.
54
53
  **`API standards`** aligned with ES6 and Java. **`Usability`** is comparable to Python
55
54
 
56
55
 
@@ -214,8 +213,6 @@ Performance surpasses that of native JS/TS
214
213
  </tr>
215
214
  </table>
216
215
 
217
-
218
-
219
216
  ### Conciseness and uniformity
220
217
 
221
218
  In [java.utils](), you need to memorize a table for all sequential data structures(Queue, Deque, LinkedList),
@@ -801,7 +798,6 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', '
801
798
 
802
799
  ```
803
800
 
804
-
805
801
  [//]: # (No deletion!!! Start of Example Replace Section)
806
802
 
807
803
 
@@ -832,9 +828,10 @@ macOS Big Sur
832
828
  Version 11.7.9
833
829
 
834
830
  ***Our performance testing is conducted directly on the TypeScript source code. The actual performance of the compiled JavaScript code is generally 3 times higher. We have compared it with C++, and it is only 30% slower than C++.***
835
- Try it
831
+ Try it
836
832
 
837
833
  Just run
834
+
838
835
  ```shell
839
836
  pnpm perf:rbtree
840
837
  ```
@@ -847,7 +844,8 @@ pnpm perf:rbtree
847
844
  ```
848
845
 
849
846
  [//]: # (No deletion!!! Start of Replace Section)
850
- <h2>comparison</h2><table><thead><tr><th>test name</th><th>time taken (ms)</th><th>sample mean (secs)</th><th>sample deviation</th></tr></thead><tbody><tr><td>SRC PQ 1,000,000 add</td><td>36.30</td><td>0.04</td><td>0.01</td></tr><tr><td>CJS PQ 100,000 add</td><td>2.76</td><td>0.00</td><td>1.11e-4</td></tr><tr><td>MJS PQ 100,000 add</td><td>14.33</td><td>0.01</td><td>2.60e-4</td></tr><tr><td>CPT PQ 100,000 add</td><td>4.81</td><td>0.00</td><td>1.36e-4</td></tr><tr><td>SRC PQ 100,000 add & poll</td><td>22.57</td><td>0.02</td><td>4.66e-4</td></tr><tr><td>CJS PQ 100,000 add & poll</td><td>22.84</td><td>0.02</td><td>6.65e-4</td></tr><tr><td>MJS PQ 100,000 add & poll</td><td>23.43</td><td>0.02</td><td>0.00</td></tr><tr><td>CPT PQ 1,000,000 add & pop</td><td>181.14</td><td>0.18</td><td>0.03</td></tr><tr><td>CPT OM 100,000 add</td><td>26.64</td><td>0.03</td><td>0.00</td></tr><tr><td>CPT HM 100,000 set</td><td>5.90</td><td>0.01</td><td>8.46e-4</td></tr><tr><td>CPT HM 100,000 set & get</td><td>6.69</td><td>0.01</td><td>7.52e-4</td></tr><tr><td>CPT LL 1,000,000 unshift</td><td>19.78</td><td>0.02</td><td>0.01</td></tr><tr><td>CPT PQ 100,000 add & pop</td><td>14.36</td><td>0.01</td><td>0.00</td></tr><tr><td>CPT DQ 1,000,000 push</td><td>8.11</td><td>0.01</td><td>5.23e-4</td></tr><tr><td>CPT Q 1,000,000 push</td><td>30.25</td><td>0.03</td><td>0.01</td></tr><tr><td>CPT ST 1,000,000 push</td><td>27.10</td><td>0.03</td><td>0.00</td></tr><tr><td>CPT ST 1,000,000 push & pop</td><td>30.19</td><td>0.03</td><td>0.00</td></tr></tbody></table>[//]: # (No deletion!!! End of Replace Section)
847
+ <h2>comparison</h2><table><thead><tr><th>test name</th><th>time taken (ms)</th><th>sample mean (secs)</th><th>sample deviation</th></tr></thead><tbody><tr><td>SRC PQ 1,000,000 add</td><td>36.30</td><td>0.04</td><td>0.01</td></tr><tr><td>CJS PQ 100,000 add</td><td>2.76</td><td>0.00</td><td>1.11e-4</td></tr><tr><td>MJS PQ 100,000 add</td><td>14.33</td><td>0.01</td><td>2.60e-4</td></tr><tr><td>CPT PQ 100,000 add</td><td>4.81</td><td>0.00</td><td>1.36e-4</td></tr><tr><td>SRC PQ 100,000 add & poll</td><td>22.57</td><td>0.02</td><td>4.66e-4</td></tr><tr><td>CJS PQ 100,000 add & poll</td><td>22.84</td><td>0.02</td><td>6.65e-4</td></tr><tr><td>MJS PQ 100,000 add & poll</td><td>23.43</td><td>0.02</td><td>0.00</td></tr><tr><td>CPT PQ 1,000,000 add & pop</td><td>181.14</td><td>0.18</td><td>0.03</td></tr><tr><td>CPT OM 100,000 add</td><td>26.64</td><td>0.03</td><td>0.00</td></tr><tr><td>CPT HM 100,000 set</td><td>5.90</td><td>0.01</td><td>8.46e-4</td></tr><tr><td>CPT HM 100,000 set & get</td><td>
848
+ 6.69</td><td>0.01</td><td>7.52e-4</td></tr><tr><td>CPT LL 1,000,000 unshift</td><td>19.78</td><td>0.02</td><td>0.01</td></tr><tr><td>CPT PQ 100,000 add & pop</td><td>14.36</td><td>0.01</td><td>0.00</td></tr><tr><td>CPT DQ 1,000,000 push</td><td>8.11</td><td>0.01</td><td>5.23e-4</td></tr><tr><td>CPT Q 1,000,000 push</td><td>30.25</td><td>0.03</td><td>0.01</td></tr><tr><td>CPT ST 1,000,000 push</td><td>27.10</td><td>0.03</td><td>0.00</td></tr><tr><td>CPT ST 1,000,000 push & pop</td><td>30.19</td><td>0.03</td><td>0.00</td></tr></tbody></table>[//]: # (No deletion!!! End of Replace Section)
851
849
 
852
850
  ## The corresponding relationships between data structures in different language standard libraries.
853
851
 
@@ -1182,6 +1180,20 @@ Copy the line below into the head tag in an HTML document.
1182
1180
 
1183
1181
  #### development
1184
1182
 
1183
+ ##### ES Module
1184
+
1185
+ ```html
1186
+
1187
+ <script type="module">
1188
+ import { BST } from "https://cdn.jsdelivr.net/npm/data-structure-typed/dist/esm/index.mjs";
1189
+
1190
+ const bst = new BST([2, 1, 6, 7, 5, 3, 4, 8, 9]);
1191
+ bst.print();
1192
+ </script>
1193
+ ```
1194
+
1195
+ ##### UMD
1196
+
1185
1197
  ```html
1186
1198
 
1187
1199
  <script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.js'></script>
@@ -2059,7 +2059,7 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
2059
2059
  * @param value - Value to wrap in a node.
2060
2060
  * @returns A new SinglyLinkedListNode instance.
2061
2061
  */
2062
- _createNode(value) {
2062
+ createNode(value) {
2063
2063
  return new SinglyLinkedListNode(value);
2064
2064
  }
2065
2065
  /**
@@ -2079,7 +2079,7 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
2079
2079
  */
2080
2080
  _ensureNode(elementOrNode) {
2081
2081
  if (this.isNode(elementOrNode)) return elementOrNode;
2082
- return this._createNode(elementOrNode);
2082
+ return this.createNode(elementOrNode);
2083
2083
  }
2084
2084
  /**
2085
2085
  * (Protected) Normalize input into a node predicate.
@@ -4812,7 +4812,7 @@ var _FibonacciHeap = class _FibonacciHeap {
4812
4812
  * @returns This heap.
4813
4813
  */
4814
4814
  push(element) {
4815
- const node = this._createNode(element);
4815
+ const node = this.createNode(element);
4816
4816
  node.left = node;
4817
4817
  node.right = node;
4818
4818
  this.mergeWithRoot(node);
@@ -4911,7 +4911,7 @@ var _FibonacciHeap = class _FibonacciHeap {
4911
4911
  this._size += heapToMerge.size;
4912
4912
  heapToMerge.clear();
4913
4913
  }
4914
- _createNode(element) {
4914
+ createNode(element) {
4915
4915
  return new FibonacciHeapNode(element);
4916
4916
  }
4917
4917
  isEmpty() {
@@ -7071,7 +7071,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7071
7071
  * @param [value] - The value for the new node (used if not in Map mode).
7072
7072
  * @returns The newly created node.
7073
7073
  */
7074
- _createNode(key, value) {
7074
+ createNode(key, value) {
7075
7075
  return new BinaryTreeNode(key, this._isMapMode ? void 0 : value);
7076
7076
  }
7077
7077
  /**
@@ -8241,9 +8241,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8241
8241
  if (key === void 0) return [void 0, void 0];
8242
8242
  else if (key === null) return [null, void 0];
8243
8243
  const finalValue = value != null ? value : entryValue;
8244
- return [this._createNode(key, finalValue), finalValue];
8244
+ return [this.createNode(key, finalValue), finalValue];
8245
8245
  }
8246
- return [this._createNode(keyNodeOrEntry, value), value];
8246
+ return [this.createNode(keyNodeOrEntry, value), value];
8247
8247
  }
8248
8248
  /**
8249
8249
  * (Protected) Helper for cloning. Performs a BFS and adds all nodes to the new tree.
@@ -8328,7 +8328,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8328
8328
  destNode = this.ensureNode(destNode);
8329
8329
  if (srcNode && destNode) {
8330
8330
  const { key, value } = destNode;
8331
- const tempNode = this._createNode(key, value);
8331
+ const tempNode = this.createNode(key, value);
8332
8332
  if (tempNode) {
8333
8333
  destNode.key = srcNode.key;
8334
8334
  if (!this._isMapMode) destNode.value = srcNode.value;
@@ -8594,7 +8594,7 @@ var _BST = class _BST extends BinaryTree {
8594
8594
  * @param [value] - The value for the new node (used if not in Map mode).
8595
8595
  * @returns The newly created BSTNode.
8596
8596
  */
8597
- _createNode(key, value) {
8597
+ createNode(key, value) {
8598
8598
  return new BSTNode(key, this._isMapMode ? void 0 : value);
8599
8599
  }
8600
8600
  /**
@@ -9830,7 +9830,7 @@ var _AVLTree = class _AVLTree extends BST {
9830
9830
  * @param [value] - The value for the new node.
9831
9831
  * @returns The newly created AVLTreeNode.
9832
9832
  */
9833
- _createNode(key, value) {
9833
+ createNode(key, value) {
9834
9834
  return new AVLTreeNode(key, this._isMapMode ? void 0 : value);
9835
9835
  }
9836
9836
  /**
@@ -9961,7 +9961,7 @@ var _AVLTree = class _AVLTree extends BST {
9961
9961
  const destNodeEnsured = this.ensureNode(destNode);
9962
9962
  if (srcNodeEnsured && destNodeEnsured) {
9963
9963
  const { key, value, height } = destNodeEnsured;
9964
- const tempNode = this._createNode(key, value);
9964
+ const tempNode = this.createNode(key, value);
9965
9965
  if (tempNode) {
9966
9966
  tempNode.height = height;
9967
9967
  destNodeEnsured.key = srcNodeEnsured.key;
@@ -10286,7 +10286,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10286
10286
  * @param color - See parameter type for details.
10287
10287
  * @returns A new RedBlackTreeNode instance.
10288
10288
  */
10289
- _createNode(key, value, color = "BLACK") {
10289
+ createNode(key, value, color = "BLACK") {
10290
10290
  return new RedBlackTreeNode(key, this._isMapMode ? void 0 : value, color);
10291
10291
  }
10292
10292
  /**
@@ -10723,7 +10723,7 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
10723
10723
  this.addMany(keysNodesEntriesOrRaws);
10724
10724
  }
10725
10725
  }
10726
- _createNode(key, value = []) {
10726
+ createNode(key, value = []) {
10727
10727
  return new AVLTreeMultiMapNode(key, this._isMapMode ? [] : value);
10728
10728
  }
10729
10729
  /**
@@ -10942,7 +10942,7 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
10942
10942
  this.addMany(keysNodesEntriesOrRaws);
10943
10943
  }
10944
10944
  }
10945
- _createNode(key, value = []) {
10945
+ createNode(key, value = []) {
10946
10946
  return new TreeMultiMapNode(key, this._isMapMode ? [] : value);
10947
10947
  }
10948
10948
  /**
@@ -11153,7 +11153,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
11153
11153
  this.dfs((node) => sum += node ? node.count : 0);
11154
11154
  return sum;
11155
11155
  }
11156
- _createNode(key, value, color = "BLACK", count) {
11156
+ createNode(key, value, color = "BLACK", count) {
11157
11157
  return new TreeCounterNode(key, this._isMapMode ? void 0 : value, count, color);
11158
11158
  }
11159
11159
  /**
@@ -11388,9 +11388,9 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
11388
11388
  const [key, entryValue] = keyNodeOrEntry;
11389
11389
  if (key === void 0 || key === null) return [void 0, void 0];
11390
11390
  const finalValue = value != null ? value : entryValue;
11391
- return [this._createNode(key, finalValue, "BLACK", count), finalValue];
11391
+ return [this.createNode(key, finalValue, "BLACK", count), finalValue];
11392
11392
  }
11393
- return [this._createNode(keyNodeOrEntry, value, "BLACK", count), value];
11393
+ return [this.createNode(keyNodeOrEntry, value, "BLACK", count), value];
11394
11394
  }
11395
11395
  /**
11396
11396
  * (Protected) Swap keys/values/counters between the source and destination nodes.
@@ -11404,7 +11404,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
11404
11404
  destNode = this.ensureNode(destNode);
11405
11405
  if (srcNode && destNode) {
11406
11406
  const { key, value, count, color } = destNode;
11407
- const tempNode = this._createNode(key, value, color, count);
11407
+ const tempNode = this.createNode(key, value, color, count);
11408
11408
  if (tempNode) {
11409
11409
  tempNode.color = color;
11410
11410
  destNode.key = srcNode.key;
@@ -11521,7 +11521,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
11521
11521
  this.dfs((node) => sum += node.count);
11522
11522
  return sum;
11523
11523
  }
11524
- _createNode(key, value, count) {
11524
+ createNode(key, value, count) {
11525
11525
  return new AVLTreeCounterNode(key, this._isMapMode ? void 0 : value, count);
11526
11526
  }
11527
11527
  /**
@@ -11721,9 +11721,9 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
11721
11721
  const [key, entryValue] = keyNodeOrEntry;
11722
11722
  if (key === void 0 || key === null) return [void 0, void 0];
11723
11723
  const finalValue = value != null ? value : entryValue;
11724
- return [this._createNode(key, finalValue, count), finalValue];
11724
+ return [this.createNode(key, finalValue, count), finalValue];
11725
11725
  }
11726
- return [this._createNode(keyNodeOrEntry, value, count), value];
11726
+ return [this.createNode(keyNodeOrEntry, value, count), value];
11727
11727
  }
11728
11728
  /**
11729
11729
  * (Protected) Swap keys/values/counters between the source and destination nodes.
@@ -11737,7 +11737,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
11737
11737
  destNode = this.ensureNode(destNode);
11738
11738
  if (srcNode && destNode) {
11739
11739
  const { key, value, count, height } = destNode;
11740
- const tempNode = this._createNode(key, value, count);
11740
+ const tempNode = this.createNode(key, value, count);
11741
11741
  if (tempNode) {
11742
11742
  tempNode.height = height;
11743
11743
  destNode.key = srcNode.key;