min-heap-typed 1.53.9 → 1.54.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.
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
- package/dist/data-structures/binary-tree/avl-tree-counter.js +407 -0
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -189
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +133 -357
- package/dist/data-structures/binary-tree/avl-tree.d.ts +108 -78
- package/dist/data-structures/binary-tree/avl-tree.js +126 -79
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +243 -190
- package/dist/data-structures/binary-tree/binary-tree.js +273 -229
- package/dist/data-structures/binary-tree/bst.d.ts +141 -122
- package/dist/data-structures/binary-tree/bst.js +170 -134
- package/dist/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/data-structures/binary-tree/index.js +2 -0
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +84 -80
- package/dist/data-structures/binary-tree/red-black-tree.js +101 -79
- package/dist/data-structures/binary-tree/tree-counter.d.ts +212 -0
- package/dist/data-structures/binary-tree/tree-counter.js +444 -0
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +78 -186
- package/dist/data-structures/binary-tree/tree-multi-map.js +140 -388
- package/dist/data-structures/graph/directed-graph.d.ts +3 -0
- package/dist/data-structures/graph/directed-graph.js +3 -0
- package/dist/data-structures/graph/map-graph.d.ts +3 -0
- package/dist/data-structures/graph/map-graph.js +3 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +3 -0
- package/dist/data-structures/graph/undirected-graph.js +3 -0
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +3 -0
- package/dist/data-structures/linked-list/singly-linked-list.js +3 -0
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +3 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/data-structures/matrix/matrix.d.ts +3 -0
- package/dist/data-structures/matrix/matrix.js +3 -0
- package/dist/data-structures/matrix/navigator.d.ts +3 -0
- package/dist/data-structures/matrix/navigator.js +3 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +3 -0
- package/dist/data-structures/trie/trie.d.ts +0 -4
- package/dist/data-structures/trie/trie.js +0 -4
- package/dist/interfaces/binary-tree.d.ts +7 -6
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/avl-tree-counter.js +2 -0
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/index.js +2 -0
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +1 -3
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/tree-counter.js +2 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -3
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +148 -394
- package/src/data-structures/binary-tree/avl-tree.ts +152 -112
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-tree.ts +446 -379
- package/src/data-structures/binary-tree/bst.ts +224 -201
- package/src/data-structures/binary-tree/index.ts +2 -0
- package/src/data-structures/binary-tree/red-black-tree.ts +138 -114
- package/src/data-structures/binary-tree/tree-counter.ts +504 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +156 -428
- package/src/data-structures/graph/directed-graph.ts +3 -0
- package/src/data-structures/graph/map-graph.ts +3 -0
- package/src/data-structures/graph/undirected-graph.ts +3 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +3 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
- package/src/data-structures/matrix/matrix.ts +3 -0
- package/src/data-structures/matrix/navigator.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
- package/src/data-structures/trie/trie.ts +0 -4
- package/src/interfaces/binary-tree.ts +10 -11
- package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -4
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/bst.ts +5 -3
- package/src/types/data-structures/binary-tree/index.ts +2 -0
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -4
- package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -4
|
@@ -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
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @param {V} [value] - The
|
|
19
|
-
*
|
|
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.
|
|
24
|
+
this.parent = undefined;
|
|
25
|
+
this._left = undefined;
|
|
26
|
+
this._right = undefined;
|
|
24
27
|
}
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
54
|
-
*
|
|
55
|
-
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
|
|
56
|
-
* iterable
|
|
57
|
-
*
|
|
58
|
-
* @param [options] - The `options` parameter
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
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,77 +72,81 @@ 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
|
|
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
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
90
|
+
* Time Complexity: O(1)
|
|
91
|
+
* Space Complexity: O(1)
|
|
92
|
+
*
|
|
93
|
+
* The function creates a new AVL tree with the specified options and returns it.
|
|
94
|
+
* @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be
|
|
95
|
+
* passed to the `createTree` function. It is used to customize the behavior of the AVL tree that is
|
|
96
|
+
* being created.
|
|
97
|
+
* @returns a new AVLTree object.
|
|
89
98
|
*/
|
|
90
|
-
// @ts-ignore
|
|
91
99
|
createTree(options) {
|
|
92
100
|
return new AVLTree([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode, specifyComparable: this._specifyComparable, toEntryFn: this._toEntryFn, isReverse: this._isReverse }, options));
|
|
93
101
|
}
|
|
94
102
|
/**
|
|
103
|
+
* Time Complexity: O(1)
|
|
104
|
+
* Space Complexity: O(1)
|
|
105
|
+
*
|
|
95
106
|
* The function checks if the input is an instance of AVLTreeNode.
|
|
96
|
-
* @param {BTNRep<K, V,
|
|
97
|
-
* `
|
|
98
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
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
|
|
99
110
|
* an instance of the `AVLTreeNode` class.
|
|
100
111
|
*/
|
|
101
|
-
isNode(
|
|
102
|
-
return
|
|
112
|
+
isNode(keyNodeOrEntry) {
|
|
113
|
+
return keyNodeOrEntry instanceof AVLTreeNode;
|
|
103
114
|
}
|
|
104
115
|
/**
|
|
105
116
|
* Time Complexity: O(log n)
|
|
106
|
-
* Space Complexity: O(
|
|
117
|
+
* Space Complexity: O(log n)
|
|
107
118
|
*
|
|
108
119
|
* The function overrides the add method of a class and inserts a key-value pair into a data
|
|
109
120
|
* structure, then balances the path.
|
|
110
|
-
* @param {BTNRep<K, V,
|
|
111
|
-
* `
|
|
112
|
-
* `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>>`
|
|
113
123
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
114
124
|
* the key or node being added to the data structure.
|
|
115
125
|
* @returns The method is returning a boolean value.
|
|
116
126
|
*/
|
|
117
|
-
add(
|
|
118
|
-
if (
|
|
127
|
+
add(keyNodeOrEntry, value) {
|
|
128
|
+
if (keyNodeOrEntry === null)
|
|
119
129
|
return false;
|
|
120
|
-
const inserted = super.add(
|
|
130
|
+
const inserted = super.add(keyNodeOrEntry, value);
|
|
121
131
|
if (inserted)
|
|
122
|
-
this._balancePath(
|
|
132
|
+
this._balancePath(keyNodeOrEntry);
|
|
123
133
|
return inserted;
|
|
124
134
|
}
|
|
125
135
|
/**
|
|
126
136
|
* Time Complexity: O(log n)
|
|
127
|
-
* Space Complexity: O(
|
|
137
|
+
* Space Complexity: O(log n)
|
|
128
138
|
*
|
|
129
139
|
* The function overrides the delete method in a TypeScript class, performs deletion, and then
|
|
130
140
|
* balances the tree if necessary.
|
|
131
|
-
* @param {BTNRep<K, V,
|
|
141
|
+
* @param {BTNRep<K, V, AVLTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
132
142
|
* parameter in the `override delete` method can be one of the following types:
|
|
133
143
|
* @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
|
|
134
144
|
* method from the superclass (presumably a parent class) with the provided `predicate`, which could
|
|
135
145
|
* be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
|
|
136
146
|
* `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
|
|
137
147
|
*/
|
|
138
|
-
delete(
|
|
139
|
-
const deletedResults = super.delete(
|
|
148
|
+
delete(keyNodeOrEntry) {
|
|
149
|
+
const deletedResults = super.delete(keyNodeOrEntry);
|
|
140
150
|
for (const { needBalanced } of deletedResults) {
|
|
141
151
|
if (needBalanced) {
|
|
142
152
|
this._balancePath(needBalanced);
|
|
@@ -144,7 +154,26 @@ class AVLTree extends bst_1.BST {
|
|
|
144
154
|
}
|
|
145
155
|
return deletedResults;
|
|
146
156
|
}
|
|
147
|
-
|
|
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
|
+
*/
|
|
148
177
|
map(callback, options, thisArg) {
|
|
149
178
|
const newTree = new AVLTree([], options);
|
|
150
179
|
let index = 0;
|
|
@@ -153,16 +182,29 @@ class AVLTree extends bst_1.BST {
|
|
|
153
182
|
}
|
|
154
183
|
return newTree;
|
|
155
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
|
+
}
|
|
156
198
|
/**
|
|
157
199
|
* Time Complexity: O(1)
|
|
158
200
|
* Space Complexity: O(1)
|
|
159
201
|
*
|
|
160
202
|
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a
|
|
161
203
|
* binary search tree.
|
|
162
|
-
* @param {
|
|
163
|
-
* object (`
|
|
164
|
-
* @param {
|
|
165
|
-
* `R` or an instance of `BSTNOptKeyOrNode<K,
|
|
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>>`.
|
|
166
208
|
* @returns The method is returning the `destNodeEnsured` object if both `srcNodeEnsured` and
|
|
167
209
|
* `destNodeEnsured` are truthy. Otherwise, it returns `undefined`.
|
|
168
210
|
*/
|
|
@@ -192,7 +234,7 @@ class AVLTree extends bst_1.BST {
|
|
|
192
234
|
* Space Complexity: O(1)
|
|
193
235
|
*
|
|
194
236
|
* The function calculates the balance factor of a node in a binary tree.
|
|
195
|
-
* @param {
|
|
237
|
+
* @param {AVLTreeNode<K, V>} node - The parameter "node" is of type "AVLTreeNode<K, V>", which likely represents a node in a
|
|
196
238
|
* binary tree data structure.
|
|
197
239
|
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the
|
|
198
240
|
* height of the left subtree from the height of the right subtree.
|
|
@@ -213,7 +255,7 @@ class AVLTree extends bst_1.BST {
|
|
|
213
255
|
*
|
|
214
256
|
* The function updates the height of a node in a binary tree based on the heights of its left and
|
|
215
257
|
* right children.
|
|
216
|
-
* @param {
|
|
258
|
+
* @param {AVLTreeNode<K, V>} node - The parameter "node" represents a node in a binary tree data structure.
|
|
217
259
|
*/
|
|
218
260
|
_updateHeight(node) {
|
|
219
261
|
if (!node.left && !node.right)
|
|
@@ -232,12 +274,13 @@ class AVLTree extends bst_1.BST {
|
|
|
232
274
|
* Space Complexity: O(1)
|
|
233
275
|
*
|
|
234
276
|
* The `_balanceLL` function performs a left-left rotation to balance a binary search tree.
|
|
235
|
-
* @param {
|
|
277
|
+
* @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
|
|
236
278
|
*/
|
|
237
279
|
_balanceLL(A) {
|
|
238
280
|
const parentOfA = A.parent;
|
|
239
281
|
const B = A.left;
|
|
240
|
-
|
|
282
|
+
if (B !== null)
|
|
283
|
+
A.parent = B;
|
|
241
284
|
if (B && B.right) {
|
|
242
285
|
B.right.parent = A;
|
|
243
286
|
}
|
|
@@ -269,7 +312,7 @@ class AVLTree extends bst_1.BST {
|
|
|
269
312
|
* Space Complexity: O(1)
|
|
270
313
|
*
|
|
271
314
|
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
|
|
272
|
-
* @param {
|
|
315
|
+
* @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
|
|
273
316
|
*/
|
|
274
317
|
_balanceLR(A) {
|
|
275
318
|
const parentOfA = A.parent;
|
|
@@ -278,13 +321,14 @@ class AVLTree extends bst_1.BST {
|
|
|
278
321
|
if (B) {
|
|
279
322
|
C = B.right;
|
|
280
323
|
}
|
|
281
|
-
if (A)
|
|
324
|
+
if (A && C !== null)
|
|
282
325
|
A.parent = C;
|
|
283
|
-
if (B)
|
|
326
|
+
if (B && C !== null)
|
|
284
327
|
B.parent = C;
|
|
285
328
|
if (C) {
|
|
286
329
|
if (C.left) {
|
|
287
|
-
|
|
330
|
+
if (B !== null)
|
|
331
|
+
C.left.parent = B;
|
|
288
332
|
}
|
|
289
333
|
if (C.right) {
|
|
290
334
|
C.right.parent = A;
|
|
@@ -323,12 +367,13 @@ class AVLTree extends bst_1.BST {
|
|
|
323
367
|
* Space Complexity: O(1)
|
|
324
368
|
*
|
|
325
369
|
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
|
|
326
|
-
* @param {
|
|
370
|
+
* @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
|
|
327
371
|
*/
|
|
328
372
|
_balanceRR(A) {
|
|
329
373
|
const parentOfA = A.parent;
|
|
330
374
|
const B = A.right;
|
|
331
|
-
|
|
375
|
+
if (B !== null)
|
|
376
|
+
A.parent = B;
|
|
332
377
|
if (B) {
|
|
333
378
|
if (B.left) {
|
|
334
379
|
B.left.parent = A;
|
|
@@ -362,7 +407,7 @@ class AVLTree extends bst_1.BST {
|
|
|
362
407
|
* Space Complexity: O(1)
|
|
363
408
|
*
|
|
364
409
|
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
|
|
365
|
-
* @param {
|
|
410
|
+
* @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
|
|
366
411
|
*/
|
|
367
412
|
_balanceRL(A) {
|
|
368
413
|
const parentOfA = A.parent;
|
|
@@ -371,15 +416,17 @@ class AVLTree extends bst_1.BST {
|
|
|
371
416
|
if (B) {
|
|
372
417
|
C = B.left;
|
|
373
418
|
}
|
|
374
|
-
|
|
375
|
-
|
|
419
|
+
if (C !== null)
|
|
420
|
+
A.parent = C;
|
|
421
|
+
if (B && C !== null)
|
|
376
422
|
B.parent = C;
|
|
377
423
|
if (C) {
|
|
378
424
|
if (C.left) {
|
|
379
425
|
C.left.parent = A;
|
|
380
426
|
}
|
|
381
427
|
if (C.right) {
|
|
382
|
-
|
|
428
|
+
if (B !== null)
|
|
429
|
+
C.right.parent = B;
|
|
383
430
|
}
|
|
384
431
|
C.parent = parentOfA;
|
|
385
432
|
}
|
|
@@ -417,8 +464,8 @@ class AVLTree extends bst_1.BST {
|
|
|
417
464
|
*
|
|
418
465
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
419
466
|
* to restore balance in an AVL tree after inserting a node.
|
|
420
|
-
* @param {BTNRep<K, V,
|
|
421
|
-
* `BTNRep<K, V,
|
|
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>>`.
|
|
422
469
|
*/
|
|
423
470
|
_balancePath(node) {
|
|
424
471
|
node = this.ensureNode(node);
|
|
@@ -468,9 +515,9 @@ class AVLTree extends bst_1.BST {
|
|
|
468
515
|
*
|
|
469
516
|
* The function replaces an old node with a new node and sets the height of the new node to be the
|
|
470
517
|
* same as the old node.
|
|
471
|
-
* @param {
|
|
518
|
+
* @param {AVLTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
|
|
472
519
|
* the data structure.
|
|
473
|
-
* @param {
|
|
520
|
+
* @param {AVLTreeNode<K, V>} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
|
|
474
521
|
* the data structure.
|
|
475
522
|
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
476
523
|
* superclass, with the `oldNode` and `newNode` as arguments.
|
|
@@ -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
|