data-structure-typed 1.52.9 → 1.53.1

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 (65) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +13 -13
  3. package/benchmark/report.html +1 -37
  4. package/benchmark/report.json +24 -384
  5. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +21 -21
  6. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +64 -47
  7. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +20 -20
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.js +29 -27
  10. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +186 -144
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js +376 -265
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/bst.d.ts +56 -56
  15. package/dist/cjs/data-structures/binary-tree/bst.js +108 -78
  16. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +13 -13
  18. package/dist/cjs/data-structures/binary-tree/rb-tree.js +42 -36
  19. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +21 -21
  21. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +59 -49
  22. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  23. package/dist/cjs/data-structures/trie/trie.js +3 -3
  24. package/dist/cjs/interfaces/binary-tree.d.ts +5 -5
  25. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +13 -13
  26. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -3
  27. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +21 -21
  28. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +64 -46
  29. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +20 -20
  30. package/dist/mjs/data-structures/binary-tree/avl-tree.js +29 -26
  31. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +186 -144
  32. package/dist/mjs/data-structures/binary-tree/binary-tree.js +376 -264
  33. package/dist/mjs/data-structures/binary-tree/bst.d.ts +56 -56
  34. package/dist/mjs/data-structures/binary-tree/bst.js +108 -76
  35. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +13 -13
  36. package/dist/mjs/data-structures/binary-tree/rb-tree.js +42 -35
  37. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +21 -21
  38. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +59 -48
  39. package/dist/mjs/data-structures/trie/trie.js +3 -3
  40. package/dist/mjs/interfaces/binary-tree.d.ts +5 -5
  41. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +13 -13
  42. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +3 -3
  43. package/dist/umd/data-structure-typed.js +596 -468
  44. package/dist/umd/data-structure-typed.min.js +5 -5
  45. package/dist/umd/data-structure-typed.min.js.map +1 -1
  46. package/package.json +6 -6
  47. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +60 -54
  48. package/src/data-structures/binary-tree/avl-tree.ts +32 -35
  49. package/src/data-structures/binary-tree/binary-tree.ts +440 -360
  50. package/src/data-structures/binary-tree/bst.ts +144 -113
  51. package/src/data-structures/binary-tree/rb-tree.ts +44 -43
  52. package/src/data-structures/binary-tree/tree-multi-map.ts +57 -61
  53. package/src/data-structures/trie/trie.ts +3 -3
  54. package/src/interfaces/binary-tree.ts +6 -6
  55. package/src/types/data-structures/binary-tree/binary-tree.ts +13 -14
  56. package/src/types/data-structures/binary-tree/bst.ts +3 -3
  57. package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +2 -2
  58. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +9 -1
  59. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +115 -3
  60. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +109 -4
  61. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +183 -46
  62. package/test/unit/data-structures/binary-tree/bst.test.ts +340 -21
  63. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +19 -0
  64. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +141 -3
  65. package/test/utils/array.ts +15 -12
@@ -49,7 +49,7 @@ export class AVLTree extends BST {
49
49
  /**
50
50
  * This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
51
51
  * entries, or raw elements.
52
- * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
52
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
53
53
  * iterable object that can contain either keys, nodes, entries, or raw elements. These elements will
54
54
  * be used to initialize the AVLTree.
55
55
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
@@ -57,10 +57,10 @@ export class AVLTree extends BST {
57
57
  * keys), `allowDuplicates` (a boolean indicating whether duplicate keys are allowed), and
58
58
  * `nodeBuilder` (
59
59
  */
60
- constructor(keysOrNodesOrEntriesOrRaws = [], options) {
60
+ constructor(keysNodesEntriesOrRaws = [], options) {
61
61
  super([], options);
62
- if (keysOrNodesOrEntriesOrRaws)
63
- super.addMany(keysOrNodesOrEntriesOrRaws);
62
+ if (keysNodesEntriesOrRaws)
63
+ super.addMany(keysNodesEntriesOrRaws);
64
64
  }
65
65
  /**
66
66
  * The function creates a new AVL tree node with the given key and value.
@@ -72,7 +72,7 @@ export class AVLTree extends BST {
72
72
  * type NODE.
73
73
  */
74
74
  createNode(key, value) {
75
- return new AVLTreeNode(key, value);
75
+ return new AVLTreeNode(key, this._isMapMode ? undefined : value);
76
76
  }
77
77
  /**
78
78
  * The function creates a new AVL tree with the specified options and returns it.
@@ -84,6 +84,7 @@ export class AVLTree extends BST {
84
84
  createTree(options) {
85
85
  return new AVLTree([], {
86
86
  iterationType: this.iterationType,
87
+ isMapMode: this._isMapMode,
87
88
  comparator: this._comparator,
88
89
  toEntryFn: this._toEntryFn,
89
90
  ...options
@@ -91,13 +92,13 @@ export class AVLTree extends BST {
91
92
  }
92
93
  /**
93
94
  * The function checks if the input is an instance of AVLTreeNode.
94
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
95
- * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
96
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
95
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
96
+ * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
97
+ * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
97
98
  * an instance of the `AVLTreeNode` class.
98
99
  */
99
- isNode(keyOrNodeOrEntryOrRaw) {
100
- return keyOrNodeOrEntryOrRaw instanceof AVLTreeNode;
100
+ isNode(keyNodeEntryOrRaw) {
101
+ return keyNodeEntryOrRaw instanceof AVLTreeNode;
101
102
  }
102
103
  /**
103
104
  * Time Complexity: O(log n)
@@ -105,19 +106,19 @@ export class AVLTree extends BST {
105
106
  *
106
107
  * The function overrides the add method of a class and inserts a key-value pair into a data
107
108
  * structure, then balances the path.
108
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
109
- * `keyOrNodeOrEntryOrRaw` can accept values of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
109
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
110
+ * `keyNodeEntryOrRaw` can accept values of type `R`, `BTNRep<K, V, NODE>`, or
110
111
  * `RawElement`.
111
112
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
112
113
  * the key or node being added to the data structure.
113
114
  * @returns The method is returning a boolean value.
114
115
  */
115
- add(keyOrNodeOrEntryOrRaw, value) {
116
- if (keyOrNodeOrEntryOrRaw === null)
116
+ add(keyNodeEntryOrRaw, value) {
117
+ if (keyNodeEntryOrRaw === null)
117
118
  return false;
118
- const inserted = super.add(keyOrNodeOrEntryOrRaw, value);
119
+ const inserted = super.add(keyNodeEntryOrRaw, value);
119
120
  if (inserted)
120
- this._balancePath(keyOrNodeOrEntryOrRaw);
121
+ this._balancePath(keyNodeEntryOrRaw);
121
122
  return inserted;
122
123
  }
123
124
  /**
@@ -126,15 +127,15 @@ export class AVLTree extends BST {
126
127
  *
127
128
  * The function overrides the delete method in a TypeScript class, performs deletion, and then
128
129
  * balances the tree if necessary.
129
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
130
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
130
131
  * parameter in the `override delete` method can be one of the following types:
131
132
  * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
132
133
  * method from the superclass (presumably a parent class) with the provided `predicate`, which could
133
134
  * be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
134
135
  * `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
135
136
  */
136
- delete(keyOrNodeOrEntryOrRaw) {
137
- const deletedResults = super.delete(keyOrNodeOrEntryOrRaw);
137
+ delete(keyNodeEntryOrRaw) {
138
+ const deletedResults = super.delete(keyNodeEntryOrRaw);
138
139
  for (const { needBalanced } of deletedResults) {
139
140
  if (needBalanced) {
140
141
  this._balancePath(needBalanced);
@@ -148,10 +149,10 @@ export class AVLTree extends BST {
148
149
  *
149
150
  * The `_swapProperties` function swaps the key, value, and height properties between two nodes in a
150
151
  * binary search tree.
151
- * @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents either a node
152
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents either a node
152
153
  * object (`NODE`) or a key-value pair (`R`) that is being swapped with another node.
153
- * @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter is either an instance of
154
- * `R` or an instance of `BSTNKeyOrNode<K, NODE>`.
154
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter is either an instance of
155
+ * `R` or an instance of `BSTNOptKeyOrNode<K, NODE>`.
155
156
  * @returns The method is returning the `destNodeEnsured` object if both `srcNodeEnsured` and
156
157
  * `destNodeEnsured` are truthy. Otherwise, it returns `undefined`.
157
158
  */
@@ -164,10 +165,12 @@ export class AVLTree extends BST {
164
165
  if (tempNode) {
165
166
  tempNode.height = height;
166
167
  destNodeEnsured.key = srcNodeEnsured.key;
167
- destNodeEnsured.value = srcNodeEnsured.value;
168
+ if (!this._isMapMode)
169
+ destNodeEnsured.value = srcNodeEnsured.value;
168
170
  destNodeEnsured.height = srcNodeEnsured.height;
169
171
  srcNodeEnsured.key = tempNode.key;
170
- srcNodeEnsured.value = tempNode.value;
172
+ if (!this._isMapMode)
173
+ srcNodeEnsured.value = tempNode.value;
171
174
  srcNodeEnsured.height = tempNode.height;
172
175
  }
173
176
  return destNodeEnsured;
@@ -404,8 +407,8 @@ export class AVLTree extends BST {
404
407
  *
405
408
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
406
409
  * to restore balance in an AVL tree after inserting a node.
407
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} node - The `node` parameter can be of type `R` or
408
- * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
410
+ * @param {BTNRep<K, V, NODE> | R} node - The `node` parameter can be of type `R` or
411
+ * `BTNRep<K, V, NODE>`.
409
412
  */
410
413
  _balancePath(node) {
411
414
  node = this.ensureNode(node);