red-black-tree-typed 1.53.7 → 1.54.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 (119) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +52 -0
  3. package/dist/common/index.js +5 -0
  4. package/dist/data-structures/base/iterable-entry-base.js +4 -4
  5. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
  6. package/dist/data-structures/binary-tree/avl-tree-counter.js +407 -0
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -170
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +133 -328
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +103 -69
  10. package/dist/data-structures/binary-tree/avl-tree.js +130 -70
  11. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
  12. package/dist/data-structures/binary-tree/binary-indexed-tree.js +3 -0
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +268 -202
  14. package/dist/data-structures/binary-tree/binary-tree.js +311 -263
  15. package/dist/data-structures/binary-tree/bst.d.ts +193 -139
  16. package/dist/data-structures/binary-tree/bst.js +248 -164
  17. package/dist/data-structures/binary-tree/index.d.ts +3 -1
  18. package/dist/data-structures/binary-tree/index.js +3 -1
  19. package/dist/data-structures/binary-tree/red-black-tree.d.ts +286 -0
  20. package/dist/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +176 -107
  21. package/dist/data-structures/binary-tree/tree-counter.d.ts +212 -0
  22. package/dist/data-structures/binary-tree/tree-counter.js +444 -0
  23. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +78 -170
  24. package/dist/data-structures/binary-tree/tree-multi-map.js +145 -367
  25. package/dist/data-structures/graph/abstract-graph.js +2 -2
  26. package/dist/data-structures/graph/directed-graph.d.ts +3 -0
  27. package/dist/data-structures/graph/directed-graph.js +3 -0
  28. package/dist/data-structures/graph/map-graph.d.ts +3 -0
  29. package/dist/data-structures/graph/map-graph.js +3 -0
  30. package/dist/data-structures/graph/undirected-graph.d.ts +3 -0
  31. package/dist/data-structures/graph/undirected-graph.js +3 -0
  32. package/dist/data-structures/hash/hash-map.d.ts +31 -1
  33. package/dist/data-structures/hash/hash-map.js +35 -5
  34. package/dist/data-structures/heap/heap.d.ts +20 -3
  35. package/dist/data-structures/heap/heap.js +31 -11
  36. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +46 -11
  37. package/dist/data-structures/linked-list/doubly-linked-list.js +68 -21
  38. package/dist/data-structures/linked-list/singly-linked-list.d.ts +47 -11
  39. package/dist/data-structures/linked-list/singly-linked-list.js +73 -26
  40. package/dist/data-structures/linked-list/skip-linked-list.d.ts +3 -0
  41. package/dist/data-structures/linked-list/skip-linked-list.js +3 -0
  42. package/dist/data-structures/matrix/matrix.d.ts +3 -0
  43. package/dist/data-structures/matrix/matrix.js +3 -0
  44. package/dist/data-structures/matrix/navigator.d.ts +3 -0
  45. package/dist/data-structures/matrix/navigator.js +3 -0
  46. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
  47. package/dist/data-structures/priority-queue/max-priority-queue.js +3 -0
  48. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
  49. package/dist/data-structures/priority-queue/min-priority-queue.js +3 -0
  50. package/dist/data-structures/queue/deque.d.ts +37 -8
  51. package/dist/data-structures/queue/deque.js +73 -29
  52. package/dist/data-structures/queue/queue.d.ts +41 -1
  53. package/dist/data-structures/queue/queue.js +51 -9
  54. package/dist/data-structures/stack/stack.d.ts +27 -10
  55. package/dist/data-structures/stack/stack.js +39 -20
  56. package/dist/data-structures/trie/trie.d.ts +8 -7
  57. package/dist/data-structures/trie/trie.js +8 -7
  58. package/dist/index.d.ts +4 -4
  59. package/dist/index.js +4 -4
  60. package/dist/interfaces/binary-tree.d.ts +8 -8
  61. package/dist/types/data-structures/base/base.d.ts +1 -1
  62. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  63. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -4
  64. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -3
  65. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -3
  66. package/dist/types/data-structures/binary-tree/bst.d.ts +4 -4
  67. package/dist/types/data-structures/binary-tree/index.d.ts +3 -1
  68. package/dist/types/data-structures/binary-tree/index.js +3 -1
  69. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  70. package/dist/types/data-structures/binary-tree/red-black-tree.js +2 -0
  71. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  72. package/dist/types/data-structures/binary-tree/tree-counter.js +2 -0
  73. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -5
  74. package/package.json +3 -3
  75. package/src/common/index.ts +7 -1
  76. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  77. package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
  78. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +151 -370
  79. package/src/data-structures/binary-tree/avl-tree.ts +162 -105
  80. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
  81. package/src/data-structures/binary-tree/binary-tree.ts +488 -416
  82. package/src/data-structures/binary-tree/bst.ts +326 -251
  83. package/src/data-structures/binary-tree/index.ts +3 -1
  84. package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +219 -145
  85. package/src/data-structures/binary-tree/tree-counter.ts +504 -0
  86. package/src/data-structures/binary-tree/tree-multi-map.ts +159 -401
  87. package/src/data-structures/graph/abstract-graph.ts +2 -2
  88. package/src/data-structures/graph/directed-graph.ts +3 -0
  89. package/src/data-structures/graph/map-graph.ts +3 -0
  90. package/src/data-structures/graph/undirected-graph.ts +3 -0
  91. package/src/data-structures/hash/hash-map.ts +37 -7
  92. package/src/data-structures/heap/heap.ts +33 -10
  93. package/src/data-structures/linked-list/doubly-linked-list.ts +75 -21
  94. package/src/data-structures/linked-list/singly-linked-list.ts +80 -27
  95. package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
  96. package/src/data-structures/matrix/matrix.ts +3 -0
  97. package/src/data-structures/matrix/navigator.ts +3 -0
  98. package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
  99. package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
  100. package/src/data-structures/queue/deque.ts +72 -28
  101. package/src/data-structures/queue/queue.ts +50 -7
  102. package/src/data-structures/stack/stack.ts +39 -20
  103. package/src/data-structures/trie/trie.ts +8 -7
  104. package/src/index.ts +4 -4
  105. package/src/interfaces/binary-tree.ts +10 -21
  106. package/src/types/data-structures/base/base.ts +1 -1
  107. package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
  108. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -6
  109. package/src/types/data-structures/binary-tree/avl-tree.ts +0 -5
  110. package/src/types/data-structures/binary-tree/binary-tree.ts +0 -5
  111. package/src/types/data-structures/binary-tree/bst.ts +6 -6
  112. package/src/types/data-structures/binary-tree/index.ts +3 -1
  113. package/src/types/data-structures/binary-tree/red-black-tree.ts +5 -0
  114. package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
  115. package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -7
  116. package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -209
  117. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -6
  118. package/src/types/data-structures/binary-tree/rb-tree.ts +0 -10
  119. /package/dist/types/data-structures/binary-tree/{rb-tree.js → avl-tree-counter.js} +0 -0
@@ -11,31 +11,37 @@ exports.AVLTree = exports.AVLTreeNode = void 0;
11
11
  const bst_1 = require("./bst");
12
12
  class AVLTreeNode extends bst_1.BSTNode {
13
13
  /**
14
- * The constructor function initializes a new instance of a class with a key and an optional value,
15
- * and sets the height property to 0.
16
- * @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
17
- * constructor. It is used to initialize the key property of the object being created.
18
- * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
19
- * value associated with the key in the constructor.
14
+ * This TypeScript constructor function initializes an instance with a key and an optional value.
15
+ * @param {K} key - The `key` parameter is typically used to uniquely identify an object or element
16
+ * within a data structure. It serves as a reference or identifier for accessing or manipulating the
17
+ * associated value or data.
18
+ * @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
19
+ * have to be provided when creating an instance of the class. If a value is not provided, it will
20
+ * default to `undefined`.
20
21
  */
21
22
  constructor(key, value) {
22
23
  super(key, value);
23
- this._height = 0;
24
+ this.parent = undefined;
25
+ this._left = undefined;
26
+ this._right = undefined;
24
27
  }
25
- /**
26
- * The function returns the value of the height property.
27
- * @returns The height of the object.
28
- */
29
- get height() {
30
- return this._height;
28
+ get left() {
29
+ return this._left;
31
30
  }
32
- /**
33
- * The above function sets the value of the height property.
34
- * @param {number} value - The value parameter is a number that represents the new height value to be
35
- * set.
36
- */
37
- set height(value) {
38
- this._height = value;
31
+ set left(v) {
32
+ if (v) {
33
+ v.parent = this;
34
+ }
35
+ this._left = v;
36
+ }
37
+ get right() {
38
+ return this._right;
39
+ }
40
+ set right(v) {
41
+ if (v) {
42
+ v.parent = this;
43
+ }
44
+ this._right = v;
39
45
  }
40
46
  }
41
47
  exports.AVLTreeNode = AVLTreeNode;
@@ -50,15 +56,15 @@ exports.AVLTreeNode = AVLTreeNode;
50
56
  */
51
57
  class AVLTree extends bst_1.BST {
52
58
  /**
53
- * This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
54
- * entries, or raw elements.
55
- * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
56
- * iterable object that can contain either keys, nodes, entries, or raw elements. These elements will
57
- * be used to initialize the AVLTree.
58
- * @param [options] - The `options` parameter is an optional object that can be used to customize the
59
- * behavior of the AVLTree. It can include properties such as `compareFn` (a function used to compare
60
- * keys), `allowDuplicates` (a boolean indicating whether duplicate keys are allowed), and
61
- * `nodeBuilder` (
59
+ * This TypeScript constructor initializes an AVLTree with keys, nodes, entries, or raw data provided
60
+ * in an iterable format.
61
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
62
+ * iterable that can contain either `BTNRep<K, V, AVLTreeNode<K, V>>` objects or `R` objects. It is
63
+ * used to initialize the AVLTree with key-value pairs or raw data entries. If provided
64
+ * @param [options] - The `options` parameter in the constructor is of type `AVLTreeOptions<K, V,
65
+ * R>`. It is an optional parameter that allows you to specify additional options for configuring the
66
+ * AVL tree. These options could include things like custom comparators, initial capacity, or any
67
+ * other configuration settings specific
62
68
  */
63
69
  constructor(keysNodesEntriesOrRaws = [], options) {
64
70
  super([], options);
@@ -66,18 +72,24 @@ class AVLTree extends bst_1.BST {
66
72
  super.addMany(keysNodesEntriesOrRaws);
67
73
  }
68
74
  /**
75
+ * Time Complexity: O(1)
76
+ * Space Complexity: O(1)
77
+ *
69
78
  * The function creates a new AVL tree node with the given key and value.
70
79
  * @param {K} key - The key parameter is of type K, which represents the key of the node being
71
80
  * created.
72
81
  * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
73
82
  * value associated with the key in the node being created.
74
83
  * @returns The method is returning a new instance of the AVLTreeNode class, casted as the generic
75
- * type NODE.
84
+ * type AVLTreeNode<K, V>.
76
85
  */
77
86
  createNode(key, value) {
78
87
  return new AVLTreeNode(key, this._isMapMode ? undefined : value);
79
88
  }
80
89
  /**
90
+ * Time Complexity: O(1)
91
+ * Space Complexity: O(1)
92
+ *
81
93
  * The function creates a new AVL tree with the specified options and returns it.
82
94
  * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be
83
95
  * passed to the `createTree` function. It is used to customize the behavior of the AVL tree that is
@@ -85,54 +97,56 @@ class AVLTree extends bst_1.BST {
85
97
  * @returns a new AVLTree object.
86
98
  */
87
99
  createTree(options) {
88
- return new AVLTree([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode, extractComparable: this._extractComparable, toEntryFn: this._toEntryFn, isReverse: this._isReverse }, options));
100
+ return new AVLTree([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode, specifyComparable: this._specifyComparable, toEntryFn: this._toEntryFn, isReverse: this._isReverse }, options));
89
101
  }
90
102
  /**
103
+ * Time Complexity: O(1)
104
+ * Space Complexity: O(1)
105
+ *
91
106
  * The function checks if the input is an instance of AVLTreeNode.
92
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
93
- * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
94
- * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
107
+ * @param {BTNRep<K, V, AVLTreeNode<K, V>>} keyNodeOrEntry - The parameter
108
+ * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, AVLTreeNode<K, V>>`.
109
+ * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
95
110
  * an instance of the `AVLTreeNode` class.
96
111
  */
97
- isNode(keyNodeEntryOrRaw) {
98
- return keyNodeEntryOrRaw instanceof AVLTreeNode;
112
+ isNode(keyNodeOrEntry) {
113
+ return keyNodeOrEntry instanceof AVLTreeNode;
99
114
  }
100
115
  /**
101
116
  * Time Complexity: O(log n)
102
- * Space Complexity: O(1)
117
+ * Space Complexity: O(log n)
103
118
  *
104
119
  * The function overrides the add method of a class and inserts a key-value pair into a data
105
120
  * structure, then balances the path.
106
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
107
- * `keyNodeEntryOrRaw` can accept values of type `R`, `BTNRep<K, V, NODE>`, or
108
- * `RawElement`.
121
+ * @param {BTNRep<K, V, AVLTreeNode<K, V>>} keyNodeOrEntry - The parameter
122
+ * `keyNodeOrEntry` can accept values of type `R`, `BTNRep<K, V, AVLTreeNode<K, V>>`
109
123
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
110
124
  * the key or node being added to the data structure.
111
125
  * @returns The method is returning a boolean value.
112
126
  */
113
- add(keyNodeEntryOrRaw, value) {
114
- if (keyNodeEntryOrRaw === null)
127
+ add(keyNodeOrEntry, value) {
128
+ if (keyNodeOrEntry === null)
115
129
  return false;
116
- const inserted = super.add(keyNodeEntryOrRaw, value);
130
+ const inserted = super.add(keyNodeOrEntry, value);
117
131
  if (inserted)
118
- this._balancePath(keyNodeEntryOrRaw);
132
+ this._balancePath(keyNodeOrEntry);
119
133
  return inserted;
120
134
  }
121
135
  /**
122
136
  * Time Complexity: O(log n)
123
- * Space Complexity: O(1)
137
+ * Space Complexity: O(log n)
124
138
  *
125
139
  * The function overrides the delete method in a TypeScript class, performs deletion, and then
126
140
  * balances the tree if necessary.
127
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
141
+ * @param {BTNRep<K, V, AVLTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
128
142
  * parameter in the `override delete` method can be one of the following types:
129
143
  * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
130
144
  * method from the superclass (presumably a parent class) with the provided `predicate`, which could
131
145
  * be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
132
146
  * `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
133
147
  */
134
- delete(keyNodeEntryOrRaw) {
135
- const deletedResults = super.delete(keyNodeEntryOrRaw);
148
+ delete(keyNodeOrEntry) {
149
+ const deletedResults = super.delete(keyNodeOrEntry);
136
150
  for (const { needBalanced } of deletedResults) {
137
151
  if (needBalanced) {
138
152
  this._balancePath(needBalanced);
@@ -140,16 +154,57 @@ class AVLTree extends bst_1.BST {
140
154
  }
141
155
  return deletedResults;
142
156
  }
157
+ /**
158
+ * Time Complexity: O(n)
159
+ * Space Complexity: O(n)
160
+ *
161
+ * The `map` function in TypeScript overrides the default map behavior of an AVLTree data structure
162
+ * by applying a callback function to each entry and creating a new AVLTree with the results.
163
+ * @param callback - A function that will be called for each entry in the AVLTree. It takes four
164
+ * arguments: the key, the value (which can be undefined), the index of the entry, and a reference to
165
+ * the AVLTree itself.
166
+ * @param [options] - The `options` parameter in the `override map` function is of type
167
+ * `AVLTreeOptions<MK, MV, MR>`. It is an optional parameter that allows you to specify additional
168
+ * options for the AVL tree being created during the mapping process. These options could include
169
+ * custom comparators, initial
170
+ * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
171
+ * the value of `this` when executing the `callback` function. It allows you to set the context
172
+ * (value of `this`) within the callback function. This can be useful when you want to access
173
+ * properties or
174
+ * @returns The `map` method is returning a new AVLTree instance (`newTree`) with the entries
175
+ * modified by the provided callback function.
176
+ */
177
+ map(callback, options, thisArg) {
178
+ const newTree = new AVLTree([], options);
179
+ let index = 0;
180
+ for (const [key, value] of this) {
181
+ newTree.add(callback.call(thisArg, key, value, index++, this));
182
+ }
183
+ return newTree;
184
+ }
185
+ /**
186
+ * Time Complexity: O(n)
187
+ * Space Complexity: O(n)
188
+ *
189
+ * The function `clone` overrides the default cloning behavior to create a deep copy of a tree
190
+ * structure.
191
+ * @returns A cloned tree object is being returned.
192
+ */
193
+ clone() {
194
+ const cloned = this.createTree();
195
+ this._clone(cloned);
196
+ return cloned;
197
+ }
143
198
  /**
144
199
  * Time Complexity: O(1)
145
200
  * Space Complexity: O(1)
146
201
  *
147
202
  * The `_swapProperties` function swaps the key, value, and height properties between two nodes in a
148
203
  * binary search tree.
149
- * @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents either a node
150
- * object (`NODE`) or a key-value pair (`R`) that is being swapped with another node.
151
- * @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter is either an instance of
152
- * `R` or an instance of `BSTNOptKeyOrNode<K, NODE>`.
204
+ * @param {BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>} srcNode - The `srcNode` parameter represents either a node
205
+ * object (`AVLTreeNode<K, V>`) or a key-value pair (`R`) that is being swapped with another node.
206
+ * @param {BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>} destNode - The `destNode` parameter is either an instance of
207
+ * `R` or an instance of `BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>`.
153
208
  * @returns The method is returning the `destNodeEnsured` object if both `srcNodeEnsured` and
154
209
  * `destNodeEnsured` are truthy. Otherwise, it returns `undefined`.
155
210
  */
@@ -179,7 +234,7 @@ class AVLTree extends bst_1.BST {
179
234
  * Space Complexity: O(1)
180
235
  *
181
236
  * The function calculates the balance factor of a node in a binary tree.
182
- * @param {NODE} node - The parameter "node" is of type "NODE", which likely represents a node in a
237
+ * @param {AVLTreeNode<K, V>} node - The parameter "node" is of type "AVLTreeNode<K, V>", which likely represents a node in a
183
238
  * binary tree data structure.
184
239
  * @returns the balance factor of a given node. The balance factor is calculated by subtracting the
185
240
  * height of the left subtree from the height of the right subtree.
@@ -200,7 +255,7 @@ class AVLTree extends bst_1.BST {
200
255
  *
201
256
  * The function updates the height of a node in a binary tree based on the heights of its left and
202
257
  * right children.
203
- * @param {NODE} node - The parameter "node" represents a node in a binary tree data structure.
258
+ * @param {AVLTreeNode<K, V>} node - The parameter "node" represents a node in a binary tree data structure.
204
259
  */
205
260
  _updateHeight(node) {
206
261
  if (!node.left && !node.right)
@@ -219,12 +274,13 @@ class AVLTree extends bst_1.BST {
219
274
  * Space Complexity: O(1)
220
275
  *
221
276
  * The `_balanceLL` function performs a left-left rotation to balance a binary search tree.
222
- * @param {NODE} A - A is a node in a binary tree.
277
+ * @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
223
278
  */
224
279
  _balanceLL(A) {
225
280
  const parentOfA = A.parent;
226
281
  const B = A.left;
227
- A.parent = B;
282
+ if (B !== null)
283
+ A.parent = B;
228
284
  if (B && B.right) {
229
285
  B.right.parent = A;
230
286
  }
@@ -256,7 +312,7 @@ class AVLTree extends bst_1.BST {
256
312
  * Space Complexity: O(1)
257
313
  *
258
314
  * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
259
- * @param {NODE} A - A is a node in a binary tree.
315
+ * @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
260
316
  */
261
317
  _balanceLR(A) {
262
318
  const parentOfA = A.parent;
@@ -265,13 +321,14 @@ class AVLTree extends bst_1.BST {
265
321
  if (B) {
266
322
  C = B.right;
267
323
  }
268
- if (A)
324
+ if (A && C !== null)
269
325
  A.parent = C;
270
- if (B)
326
+ if (B && C !== null)
271
327
  B.parent = C;
272
328
  if (C) {
273
329
  if (C.left) {
274
- C.left.parent = B;
330
+ if (B !== null)
331
+ C.left.parent = B;
275
332
  }
276
333
  if (C.right) {
277
334
  C.right.parent = A;
@@ -310,12 +367,13 @@ class AVLTree extends bst_1.BST {
310
367
  * Space Complexity: O(1)
311
368
  *
312
369
  * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
313
- * @param {NODE} A - A is a node in a binary tree.
370
+ * @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
314
371
  */
315
372
  _balanceRR(A) {
316
373
  const parentOfA = A.parent;
317
374
  const B = A.right;
318
- A.parent = B;
375
+ if (B !== null)
376
+ A.parent = B;
319
377
  if (B) {
320
378
  if (B.left) {
321
379
  B.left.parent = A;
@@ -349,7 +407,7 @@ class AVLTree extends bst_1.BST {
349
407
  * Space Complexity: O(1)
350
408
  *
351
409
  * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
352
- * @param {NODE} A - A is a node in a binary tree.
410
+ * @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
353
411
  */
354
412
  _balanceRL(A) {
355
413
  const parentOfA = A.parent;
@@ -358,15 +416,17 @@ class AVLTree extends bst_1.BST {
358
416
  if (B) {
359
417
  C = B.left;
360
418
  }
361
- A.parent = C;
362
- if (B)
419
+ if (C !== null)
420
+ A.parent = C;
421
+ if (B && C !== null)
363
422
  B.parent = C;
364
423
  if (C) {
365
424
  if (C.left) {
366
425
  C.left.parent = A;
367
426
  }
368
427
  if (C.right) {
369
- C.right.parent = B;
428
+ if (B !== null)
429
+ C.right.parent = B;
370
430
  }
371
431
  C.parent = parentOfA;
372
432
  }
@@ -404,8 +464,8 @@ class AVLTree extends bst_1.BST {
404
464
  *
405
465
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
406
466
  * to restore balance in an AVL tree after inserting a node.
407
- * @param {BTNRep<K, V, NODE> | R} node - The `node` parameter can be of type `R` or
408
- * `BTNRep<K, V, NODE>`.
467
+ * @param {BTNRep<K, V, AVLTreeNode<K, V>>} node - The `node` parameter can be of type `R` or
468
+ * `BTNRep<K, V, AVLTreeNode<K, V>>`.
409
469
  */
410
470
  _balancePath(node) {
411
471
  node = this.ensureNode(node);
@@ -455,9 +515,9 @@ class AVLTree extends bst_1.BST {
455
515
  *
456
516
  * The function replaces an old node with a new node and sets the height of the new node to be the
457
517
  * same as the old node.
458
- * @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
518
+ * @param {AVLTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
459
519
  * the data structure.
460
- * @param {NODE} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
520
+ * @param {AVLTreeNode<K, V>} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
461
521
  * the data structure.
462
522
  * @returns The method is returning the result of calling the `_replaceNode` method from the
463
523
  * superclass, with the `oldNode` and `newNode` as arguments.
@@ -1,3 +1,6 @@
1
+ /**
2
+ *
3
+ */
1
4
  export declare class BinaryIndexedTree {
2
5
  protected readonly _freq: number;
3
6
  protected readonly _max: number;
@@ -9,6 +9,9 @@ exports.BinaryIndexedTree = void 0;
9
9
  * @license MIT License
10
10
  */
11
11
  const utils_1 = require("../../utils");
12
+ /**
13
+ *
14
+ */
12
15
  class BinaryIndexedTree {
13
16
  /**
14
17
  * The constructor initializes the properties of an object, including default frequency, maximum