data-structure-typed 1.49.5 → 1.49.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 (68) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +14 -23
  3. package/benchmark/report.html +14 -23
  4. package/benchmark/report.json +163 -256
  5. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
  6. package/dist/cjs/data-structures/binary-tree/avl-tree.js +55 -49
  7. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +153 -130
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js +192 -149
  10. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/bst.d.ts +83 -71
  12. package/dist/cjs/data-structures/binary-tree/bst.js +113 -89
  13. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.js +62 -59
  16. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +46 -39
  18. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +58 -51
  19. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  20. package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
  21. package/dist/cjs/types/common.d.ts +3 -3
  22. package/dist/cjs/types/common.js +2 -2
  23. package/dist/cjs/types/common.js.map +1 -1
  24. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
  25. package/dist/mjs/data-structures/binary-tree/avl-tree.js +55 -49
  26. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +153 -130
  27. package/dist/mjs/data-structures/binary-tree/binary-tree.js +192 -149
  28. package/dist/mjs/data-structures/binary-tree/bst.d.ts +83 -71
  29. package/dist/mjs/data-structures/binary-tree/bst.js +113 -89
  30. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
  31. package/dist/mjs/data-structures/binary-tree/rb-tree.js +62 -59
  32. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +46 -39
  33. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +58 -51
  34. package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
  35. package/dist/mjs/types/common.d.ts +3 -3
  36. package/dist/mjs/types/common.js +2 -2
  37. package/dist/umd/data-structure-typed.js +497 -419
  38. package/dist/umd/data-structure-typed.min.js +2 -2
  39. package/dist/umd/data-structure-typed.min.js.map +1 -1
  40. package/package.json +1 -1
  41. package/src/data-structures/binary-tree/avl-tree.ts +58 -53
  42. package/src/data-structures/binary-tree/binary-tree.ts +253 -205
  43. package/src/data-structures/binary-tree/bst.ts +125 -104
  44. package/src/data-structures/binary-tree/rb-tree.ts +66 -64
  45. package/src/data-structures/binary-tree/tree-multimap.ts +62 -56
  46. package/src/interfaces/binary-tree.ts +3 -3
  47. package/src/types/common.ts +3 -3
  48. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -12
  49. package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +37 -0
  50. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +6 -16
  51. package/test/performance/data-structures/binary-tree/bst.test.ts +5 -13
  52. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +5 -15
  53. package/test/performance/data-structures/comparison/comparison.test.ts +13 -36
  54. package/test/performance/data-structures/graph/directed-graph.test.ts +3 -14
  55. package/test/performance/data-structures/hash/hash-map.test.ts +11 -34
  56. package/test/performance/data-structures/heap/heap.test.ts +5 -18
  57. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +0 -1
  58. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +0 -2
  59. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +2 -4
  60. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +4 -14
  61. package/test/performance/data-structures/queue/queue.test.ts +8 -25
  62. package/test/performance/data-structures/stack/stack.test.ts +6 -18
  63. package/test/performance/data-structures/trie/trie.test.ts +2 -6
  64. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +6 -5
  65. package/test/unit/data-structures/binary-tree/bst.test.ts +17 -1
  66. package/test/performance/data-structures/binary-tree/overall.test.ts +0 -0
  67. package/test/performance/data-structures/matrix/matrix2d.test.ts +0 -0
  68. package/test/performance/data-structures/matrix/vector2d.test.ts +0 -0
@@ -24,18 +24,18 @@ export class AVLTreeNode extends BSTNode {
24
24
  */
25
25
  export class AVLTree extends BST {
26
26
  /**
27
- * The constructor function initializes an AVLTree object with optional elements and options.
28
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
29
- * objects. It represents a collection of elements that will be added to the AVL tree during
27
+ * The constructor function initializes an AVLTree object with optional nodes and options.
28
+ * @param [nodes] - The `nodes` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
29
+ * objects. It represents a collection of nodes that will be added to the AVL tree during
30
30
  * initialization.
31
31
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
32
32
  * behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
33
33
  * provide only a subset of the properties defined in the `AVLTreeOptions` interface.
34
34
  */
35
- constructor(elements, options) {
35
+ constructor(nodes, options) {
36
36
  super([], options);
37
- if (elements)
38
- super.addMany(elements);
37
+ if (nodes)
38
+ super.addMany(nodes);
39
39
  }
40
40
  /**
41
41
  * The function creates a new AVL tree node with the specified key and value.
@@ -64,12 +64,12 @@ export class AVLTree extends BST {
64
64
  });
65
65
  }
66
66
  /**
67
- * The function checks if an exemplar is an instance of AVLTreeNode.
68
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
69
- * @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
67
+ * The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
68
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
69
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.
70
70
  */
71
- isNode(exemplar) {
72
- return exemplar instanceof AVLTreeNode;
71
+ isNode(keyOrNodeOrEntry) {
72
+ return keyOrNodeOrEntry instanceof AVLTreeNode;
73
73
  }
74
74
  /**
75
75
  * The function "isNotNodeInstance" checks if a potential key is a K.
@@ -81,12 +81,13 @@ export class AVLTree extends BST {
81
81
  return !(potentialKey instanceof AVLTreeNode);
82
82
  }
83
83
  /**
84
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
85
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
84
+ * Time Complexity: O(log n)
85
+ * Space Complexity: O(1)
86
+ * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
86
87
  */
87
88
  /**
88
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
89
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
89
+ * Time Complexity: O(log n)
90
+ * Space Complexity: O(1)
90
91
  *
91
92
  * The function overrides the add method of a binary tree node and balances the tree after inserting
92
93
  * a new node.
@@ -98,19 +99,19 @@ export class AVLTree extends BST {
98
99
  */
99
100
  add(keyOrNodeOrEntry, value) {
100
101
  if (keyOrNodeOrEntry === null)
101
- return undefined;
102
+ return false;
102
103
  const inserted = super.add(keyOrNodeOrEntry, value);
103
104
  if (inserted)
104
- this._balancePath(inserted);
105
+ this._balancePath(keyOrNodeOrEntry);
105
106
  return inserted;
106
107
  }
107
108
  /**
108
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
109
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
109
+ * Time Complexity: O(log n)
110
+ * Space Complexity: O(1)
110
111
  */
111
112
  /**
112
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
113
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
113
+ * Time Complexity: O(log n)
114
+ * Space Complexity: O(1)
114
115
  *
115
116
  * The function overrides the delete method of a binary tree, performs the deletion, and then
116
117
  * balances the tree if necessary.
@@ -164,12 +165,13 @@ export class AVLTree extends BST {
164
165
  return undefined;
165
166
  }
166
167
  /**
167
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
168
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
168
+ * Time Complexity: O(1)
169
+ * Space Complexity: O(1)
170
+ * constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
169
171
  */
170
172
  /**
171
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
172
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
173
+ * Time Complexity: O(1)
174
+ * Space Complexity: O(1)
173
175
  *
174
176
  * The function calculates the balance factor of a node in a binary tree.
175
177
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
@@ -187,12 +189,13 @@ export class AVLTree extends BST {
187
189
  return node.right.height - node.left.height;
188
190
  }
189
191
  /**
190
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
191
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
192
+ * Time Complexity: O(1)
193
+ * Space Complexity: O(1)
194
+ * constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
192
195
  */
193
196
  /**
194
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
195
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
197
+ * Time Complexity: O(1)
198
+ * Space Complexity: O(1)
196
199
  *
197
200
  * The function updates the height of a node in a binary tree based on the heights of its left and
198
201
  * right children.
@@ -211,12 +214,13 @@ export class AVLTree extends BST {
211
214
  node.height = 1 + Math.max(node.right.height, node.left.height);
212
215
  }
213
216
  /**
214
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
215
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
217
+ * Time Complexity: O(log n)
218
+ * Space Complexity: O(1)
219
+ * logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
216
220
  */
217
221
  /**
218
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
219
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
222
+ * Time Complexity: O(log n)
223
+ * Space Complexity: O(1)
220
224
  *
221
225
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
222
226
  * to restore balance in an AVL tree after inserting a node.
@@ -224,6 +228,7 @@ export class AVLTree extends BST {
224
228
  * AVL tree that needs to be balanced.
225
229
  */
226
230
  _balancePath(node) {
231
+ node = this.ensureNode(node);
227
232
  const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
228
233
  for (let i = 0; i < path.length; i++) {
229
234
  // second O(log n)
@@ -263,12 +268,13 @@ export class AVLTree extends BST {
263
268
  }
264
269
  }
265
270
  /**
266
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
267
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
271
+ * Time Complexity: O(1)
272
+ * Space Complexity: O(1)
273
+ * constant time, as these methods perform a fixed number of operations. constant space, as they only use a constant amount of memory.
268
274
  */
269
275
  /**
270
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
271
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
276
+ * Time Complexity: O(1)
277
+ * Space Complexity: O(1)
272
278
  *
273
279
  * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
274
280
  * @param {N} A - A is a node in a binary tree.
@@ -304,12 +310,12 @@ export class AVLTree extends BST {
304
310
  this._updateHeight(B);
305
311
  }
306
312
  /**
307
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
308
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
313
+ * Time Complexity: O(1)
314
+ * Space Complexity: O(1)
309
315
  */
310
316
  /**
311
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
312
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
317
+ * Time Complexity: O(1)
318
+ * Space Complexity: O(1)
313
319
  *
314
320
  * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
315
321
  * @param {N} A - A is a node in a binary tree.
@@ -360,12 +366,12 @@ export class AVLTree extends BST {
360
366
  C && this._updateHeight(C);
361
367
  }
362
368
  /**
363
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
364
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
369
+ * Time Complexity: O(1)
370
+ * Space Complexity: O(1)
365
371
  */
366
372
  /**
367
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
368
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
373
+ * Time Complexity: O(1)
374
+ * Space Complexity: O(1)
369
375
  *
370
376
  * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
371
377
  * @param {N} A - A is a node in a binary tree.
@@ -402,12 +408,12 @@ export class AVLTree extends BST {
402
408
  B && this._updateHeight(B);
403
409
  }
404
410
  /**
405
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
406
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
411
+ * Time Complexity: O(1)
412
+ * Space Complexity: O(1)
407
413
  */
408
414
  /**
409
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
410
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
415
+ * Time Complexity: O(1)
416
+ * Space Complexity: O(1)
411
417
  *
412
418
  * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
413
419
  * @param {N} A - A is a node in a binary tree.