data-structure-typed 1.37.3 → 1.37.4

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 (28) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/data-structures/binary-tree/avl-tree.d.ts +42 -34
  3. package/dist/data-structures/binary-tree/avl-tree.js +42 -34
  4. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +265 -168
  6. package/dist/data-structures/binary-tree/binary-tree.js +257 -170
  7. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  8. package/dist/data-structures/binary-tree/bst.d.ts +104 -59
  9. package/dist/data-structures/binary-tree/bst.js +105 -60
  10. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/data-structures/binary-tree/tree-multiset.d.ts +47 -39
  12. package/dist/data-structures/binary-tree/tree-multiset.js +47 -39
  13. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  14. package/lib/data-structures/binary-tree/avl-tree.d.ts +42 -34
  15. package/lib/data-structures/binary-tree/avl-tree.js +42 -34
  16. package/lib/data-structures/binary-tree/binary-tree.d.ts +265 -168
  17. package/lib/data-structures/binary-tree/binary-tree.js +257 -170
  18. package/lib/data-structures/binary-tree/bst.d.ts +104 -59
  19. package/lib/data-structures/binary-tree/bst.js +105 -60
  20. package/lib/data-structures/binary-tree/tree-multiset.d.ts +47 -39
  21. package/lib/data-structures/binary-tree/tree-multiset.js +47 -39
  22. package/package.json +5 -5
  23. package/src/data-structures/binary-tree/avl-tree.ts +42 -34
  24. package/src/data-structures/binary-tree/binary-tree.ts +270 -174
  25. package/src/data-structures/binary-tree/bst.ts +108 -66
  26. package/src/data-structures/binary-tree/tree-multiset.ts +47 -39
  27. package/umd/bundle.min.js +1 -1
  28. package/umd/bundle.min.js.map +1 -1
@@ -23,11 +23,12 @@ export class AVLTree extends BST {
23
23
  super(options);
24
24
  }
25
25
  /**
26
- * The `_swap` function swaps the location of two nodes in a binary tree.
27
- * @param {N} srcNode - The source node that you want to _swap with the destination node.
28
- * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
29
- * be swapped to.
30
- * @returns The `destNode` is being returned.
26
+ * The function swaps the key, value, and height properties between two nodes in a binary tree.
27
+ * @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
28
+ * with the `destNode`.
29
+ * @param {N} destNode - The `destNode` parameter represents the destination node where the values
30
+ * from the source node (`srcNode`) will be swapped to.
31
+ * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
31
32
  */
32
33
  _swap(srcNode, destNode) {
33
34
  const { key, val, height } = destNode;
@@ -44,22 +45,25 @@ export class AVLTree extends BST {
44
45
  return destNode;
45
46
  }
46
47
  /**
47
- * The function creates a new AVL tree node with the given key and value.
48
- * @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
49
- * identify each node in the tree.
50
- * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
51
- * that will be stored in the node.
48
+ * The function creates a new AVL tree node with the specified key and value.
49
+ * @param {BinaryTreeNodeKey} key - The key parameter is the key value that will be associated with
50
+ * the new node. It is used to determine the position of the node in the binary search tree.
51
+ * @param [val] - The parameter `val` is an optional value that can be assigned to the node. It is of
52
+ * type `N['val']`, which means it can be any value that is assignable to the `val` property of the
53
+ * node type `N`.
52
54
  * @returns a new AVLTreeNode object with the specified key and value.
53
55
  */
54
56
  createNode(key, val) {
55
57
  return new AVLTreeNode(key, val);
56
58
  }
57
59
  /**
58
- * The function overrides the add method of a binary tree node and balances the tree after inserting a new node.
59
- * @param keyOrNode - The `keyOrNode` parameter is either a key or a node that needs to be added to the binary tree.
60
- * @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. It is of type
61
- * `N['val']`, which means it should be of the same type as the `val` property of the nodes in the binary tree.
62
- * @returns The method is returning the inserted node, or null or undefined if the insertion was not successful.
60
+ * The function overrides the add method of a binary tree node and balances the tree after inserting
61
+ * a new node.
62
+ * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
63
+ * `BinaryTreeNodeKey` or a `N` (which represents a node in the binary tree) or `null`.
64
+ * @param [val] - The `val` parameter is the value that you want to assign to the new node that you
65
+ * are adding to the binary search tree.
66
+ * @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
63
67
  */
64
68
  add(keyOrNode, val) {
65
69
  // TODO support node as a param
@@ -69,9 +73,11 @@ export class AVLTree extends BST {
69
73
  return inserted;
70
74
  }
71
75
  /**
72
- * The function overrides the delete method of a binary tree and performs additional operations to balance the tree after deletion.
76
+ * The function overrides the delete method of a binary tree and balances the tree after deleting a
77
+ * node if necessary.
78
+ * @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object
79
+ * (`N`) or a key value (`BinaryTreeNodeKey`).
73
80
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
74
- * @param nodeOrKey - The `nodeOrKey` parameter is either a node or a key that needs to be deleted from the binary tree.
75
81
  */
76
82
  delete(nodeOrKey) {
77
83
  const deletedResults = super.delete(nodeOrKey);
@@ -83,10 +89,10 @@ export class AVLTree extends BST {
83
89
  return deletedResults;
84
90
  }
85
91
  /**
86
- * The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the
87
- * height of its right subtree.
88
- * @param node - The parameter "node" is of type N, which represents a node in an AVL tree.
89
- * @returns The balance factor of the given AVL tree node.
92
+ * The function calculates the balance factor of a node in a binary tree.
93
+ * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
94
+ * @returns the balance factor of a given node. The balance factor is calculated by subtracting the
95
+ * height of the left subtree from the height of the right subtree.
90
96
  */
91
97
  _balanceFactor(node) {
92
98
  if (!node.right)
@@ -99,8 +105,9 @@ export class AVLTree extends BST {
99
105
  return node.right.height - node.left.height;
100
106
  }
101
107
  /**
102
- * The function updates the height of a node in an AVL tree based on the heights of its left and right subtrees.
103
- * @param node - The parameter `node` is an AVLTreeNode object, which represents a node in an AVL tree.
108
+ * The function updates the height of a node in a binary tree based on the heights of its left and
109
+ * right children.
110
+ * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
104
111
  */
105
112
  _updateHeight(node) {
106
113
  if (!node.left && !node.right)
@@ -115,9 +122,10 @@ export class AVLTree extends BST {
115
122
  node.height = 1 + Math.max(node.right.height, node.left.height);
116
123
  }
117
124
  /**
118
- * The `_balancePath` function balances the AVL tree by performing appropriate rotations based on the balance factor of
119
- * each node in the path from the given node to the root.
120
- * @param node - The `node` parameter is an AVLTreeNode object, which represents a node in an AVL tree.
125
+ * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
126
+ * to restore balance in an AVL tree after inserting a node.
127
+ * @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
128
+ * AVL tree that needs to be balanced.
121
129
  */
122
130
  _balancePath(node) {
123
131
  const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
@@ -159,8 +167,8 @@ export class AVLTree extends BST {
159
167
  }
160
168
  }
161
169
  /**
162
- * The `_balanceLL` function performs a left-left rotation on an AVL tree to balance it.
163
- * @param A - The parameter A is an AVLTreeNode object.
170
+ * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
171
+ * @param {N} A - A is a node in a binary tree.
164
172
  */
165
173
  _balanceLL(A) {
166
174
  const parentOfA = A.parent;
@@ -193,8 +201,8 @@ export class AVLTree extends BST {
193
201
  this._updateHeight(B);
194
202
  }
195
203
  /**
196
- * The `_balanceLR` function performs a left-right rotation to balance an AVL tree.
197
- * @param A - A is an AVLTreeNode object.
204
+ * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
205
+ * @param {N} A - A is a node in a binary tree.
198
206
  */
199
207
  _balanceLR(A) {
200
208
  const parentOfA = A.parent;
@@ -242,8 +250,8 @@ export class AVLTree extends BST {
242
250
  C && this._updateHeight(C);
243
251
  }
244
252
  /**
245
- * The `_balanceRR` function performs a right-right rotation on an AVL tree to balance it.
246
- * @param A - The parameter A is an AVLTreeNode object.
253
+ * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
254
+ * @param {N} A - A is a node in a binary tree.
247
255
  */
248
256
  _balanceRR(A) {
249
257
  const parentOfA = A.parent;
@@ -277,8 +285,8 @@ export class AVLTree extends BST {
277
285
  B && this._updateHeight(B);
278
286
  }
279
287
  /**
280
- * The `_balanceRL` function performs a right-left rotation to balance an AVL tree.
281
- * @param A - A is an AVLTreeNode object.
288
+ * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
289
+ * @param {N} A - A is a node in a binary tree.
282
290
  */
283
291
  _balanceRL(A) {
284
292
  const parentOfA = A.parent;