min-heap-typed 1.50.1 → 1.50.3
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/base/iterable-base.d.ts +120 -9
- package/dist/data-structures/base/iterable-base.js +143 -7
- package/dist/data-structures/binary-tree/avl-tree.d.ts +72 -47
- package/dist/data-structures/binary-tree/avl-tree.js +101 -72
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
- package/dist/data-structures/binary-tree/binary-tree.js +484 -376
- package/dist/data-structures/binary-tree/bst.d.ts +92 -79
- package/dist/data-structures/binary-tree/bst.js +68 -76
- package/dist/data-structures/binary-tree/rb-tree.d.ts +127 -57
- package/dist/data-structures/binary-tree/rb-tree.js +152 -99
- package/dist/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +72 -58
- package/dist/data-structures/binary-tree/tree-multimap.js +102 -85
- package/dist/data-structures/graph/abstract-graph.d.ts +1 -78
- package/dist/data-structures/graph/abstract-graph.js +3 -189
- package/dist/data-structures/graph/directed-graph.d.ts +73 -0
- package/dist/data-structures/graph/directed-graph.js +131 -0
- package/dist/data-structures/graph/map-graph.d.ts +8 -0
- package/dist/data-structures/graph/map-graph.js +14 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +76 -7
- package/dist/data-structures/graph/undirected-graph.js +151 -18
- package/dist/data-structures/hash/hash-map.d.ts +254 -28
- package/dist/data-structures/hash/hash-map.js +347 -78
- package/dist/data-structures/heap/heap.d.ts +95 -25
- package/dist/data-structures/heap/heap.js +95 -26
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +126 -63
- package/dist/data-structures/linked-list/doubly-linked-list.js +141 -77
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +154 -106
- package/dist/data-structures/linked-list/singly-linked-list.js +164 -115
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
- package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
- package/dist/data-structures/matrix/matrix.d.ts +35 -4
- package/dist/data-structures/matrix/matrix.js +50 -11
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/data-structures/queue/deque.d.ts +139 -35
- package/dist/data-structures/queue/deque.js +200 -62
- package/dist/data-structures/queue/queue.d.ts +103 -49
- package/dist/data-structures/queue/queue.js +111 -49
- package/dist/data-structures/stack/stack.d.ts +51 -21
- package/dist/data-structures/stack/stack.js +58 -22
- package/dist/data-structures/tree/tree.d.ts +57 -3
- package/dist/data-structures/tree/tree.js +77 -11
- package/dist/data-structures/trie/trie.d.ts +135 -34
- package/dist/data-structures/trie/trie.js +153 -33
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
- package/dist/types/utils/utils.d.ts +1 -0
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +184 -19
- package/src/data-structures/binary-tree/avl-tree.ts +134 -100
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +674 -671
- package/src/data-structures/binary-tree/bst.ts +127 -136
- package/src/data-structures/binary-tree/rb-tree.ts +199 -166
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multimap.ts +138 -115
- package/src/data-structures/graph/abstract-graph.ts +4 -211
- package/src/data-structures/graph/directed-graph.ts +152 -0
- package/src/data-structures/graph/map-graph.ts +15 -0
- package/src/data-structures/graph/undirected-graph.ts +171 -19
- package/src/data-structures/hash/hash-map.ts +389 -96
- package/src/data-structures/heap/heap.ts +97 -26
- package/src/data-structures/linked-list/doubly-linked-list.ts +156 -83
- package/src/data-structures/linked-list/singly-linked-list.ts +174 -120
- package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
- package/src/data-structures/matrix/matrix.ts +52 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
- package/src/data-structures/priority-queue/priority-queue.ts +8 -0
- package/src/data-structures/queue/deque.ts +225 -70
- package/src/data-structures/queue/queue.ts +118 -49
- package/src/data-structures/stack/stack.ts +63 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +173 -38
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/hash/hash-map.ts +4 -3
- package/src/types/utils/utils.ts +2 -0
|
@@ -10,9 +10,32 @@ exports.AVLTree = exports.AVLTreeNode = void 0;
|
|
|
10
10
|
*/
|
|
11
11
|
const bst_1 = require("./bst");
|
|
12
12
|
class AVLTreeNode extends bst_1.BSTNode {
|
|
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.
|
|
20
|
+
*/
|
|
13
21
|
constructor(key, value) {
|
|
14
22
|
super(key, value);
|
|
15
|
-
this.
|
|
23
|
+
this._height = 0;
|
|
24
|
+
}
|
|
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;
|
|
31
|
+
}
|
|
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;
|
|
16
39
|
}
|
|
17
40
|
}
|
|
18
41
|
exports.AVLTreeNode = AVLTreeNode;
|
|
@@ -28,7 +51,7 @@ exports.AVLTreeNode = AVLTreeNode;
|
|
|
28
51
|
class AVLTree extends bst_1.BST {
|
|
29
52
|
/**
|
|
30
53
|
* The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.
|
|
31
|
-
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V,
|
|
54
|
+
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, NODE>`
|
|
32
55
|
* objects. It represents a collection of nodes that will be added to the AVL tree during
|
|
33
56
|
* initialization.
|
|
34
57
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
@@ -46,7 +69,7 @@ class AVLTree extends bst_1.BST {
|
|
|
46
69
|
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
47
70
|
* @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
|
|
48
71
|
* type `V`, which means it can be any value that is assignable to the `value` property of the
|
|
49
|
-
* node type `
|
|
72
|
+
* node type `NODE`.
|
|
50
73
|
* @returns a new AVLTreeNode object with the specified key and value.
|
|
51
74
|
*/
|
|
52
75
|
createNode(key, value) {
|
|
@@ -64,7 +87,7 @@ class AVLTree extends bst_1.BST {
|
|
|
64
87
|
}
|
|
65
88
|
/**
|
|
66
89
|
* The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
|
|
67
|
-
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V,
|
|
90
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
68
91
|
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.
|
|
69
92
|
*/
|
|
70
93
|
isNode(keyOrNodeOrEntry) {
|
|
@@ -111,8 +134,8 @@ class AVLTree extends bst_1.BST {
|
|
|
111
134
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
112
135
|
* that is deleted from the binary tree. It is an optional parameter and if not provided, it will
|
|
113
136
|
* default to the `_defaultOneParamCallback` function. The `callback` function should have a single
|
|
114
|
-
* parameter of type `
|
|
115
|
-
* @returns The method is returning an array of `BinaryTreeDeleteResult<
|
|
137
|
+
* parameter of type `NODE
|
|
138
|
+
* @returns The method is returning an array of `BinaryTreeDeleteResult<NODE>`.
|
|
116
139
|
*/
|
|
117
140
|
delete(identifier, callback = this._defaultOneParamCallback) {
|
|
118
141
|
if (identifier instanceof AVLTreeNode)
|
|
@@ -128,9 +151,9 @@ class AVLTree extends bst_1.BST {
|
|
|
128
151
|
/**
|
|
129
152
|
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
|
|
130
153
|
* tree.
|
|
131
|
-
* @param {K |
|
|
132
|
-
* needs to be swapped with the destination node. It can be of type `K`, `
|
|
133
|
-
* @param {K |
|
|
154
|
+
* @param {K | NODE | undefined} srcNode - The `srcNode` parameter represents the source node that
|
|
155
|
+
* needs to be swapped with the destination node. It can be of type `K`, `NODE`, or `undefined`.
|
|
156
|
+
* @param {K | NODE | undefined} destNode - The `destNode` parameter represents the destination
|
|
134
157
|
* node where the values from the source node will be swapped to.
|
|
135
158
|
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
136
159
|
* if either `srcNode` or `destNode` is undefined.
|
|
@@ -157,14 +180,13 @@ class AVLTree extends bst_1.BST {
|
|
|
157
180
|
/**
|
|
158
181
|
* Time Complexity: O(1)
|
|
159
182
|
* Space Complexity: O(1)
|
|
160
|
-
* constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
|
|
161
183
|
*/
|
|
162
184
|
/**
|
|
163
185
|
* Time Complexity: O(1)
|
|
164
186
|
* Space Complexity: O(1)
|
|
165
187
|
*
|
|
166
188
|
* The function calculates the balance factor of a node in a binary tree.
|
|
167
|
-
* @param {
|
|
189
|
+
* @param {NODE} node - The parameter "node" represents a node in a binary tree data structure.
|
|
168
190
|
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the
|
|
169
191
|
* height of the left subtree from the height of the right subtree.
|
|
170
192
|
*/
|
|
@@ -181,7 +203,6 @@ class AVLTree extends bst_1.BST {
|
|
|
181
203
|
/**
|
|
182
204
|
* Time Complexity: O(1)
|
|
183
205
|
* Space Complexity: O(1)
|
|
184
|
-
* constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
|
|
185
206
|
*/
|
|
186
207
|
/**
|
|
187
208
|
* Time Complexity: O(1)
|
|
@@ -189,7 +210,7 @@ class AVLTree extends bst_1.BST {
|
|
|
189
210
|
*
|
|
190
211
|
* The function updates the height of a node in a binary tree based on the heights of its left and
|
|
191
212
|
* right children.
|
|
192
|
-
* @param {
|
|
213
|
+
* @param {NODE} node - The parameter "node" represents a node in a binary tree data structure.
|
|
193
214
|
*/
|
|
194
215
|
_updateHeight(node) {
|
|
195
216
|
if (!node.left && !node.right)
|
|
@@ -203,71 +224,16 @@ class AVLTree extends bst_1.BST {
|
|
|
203
224
|
else
|
|
204
225
|
node.height = 1 + Math.max(node.right.height, node.left.height);
|
|
205
226
|
}
|
|
206
|
-
/**
|
|
207
|
-
* Time Complexity: O(log n)
|
|
208
|
-
* Space Complexity: O(1)
|
|
209
|
-
* 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.
|
|
210
|
-
*/
|
|
211
|
-
/**
|
|
212
|
-
* Time Complexity: O(log n)
|
|
213
|
-
* Space Complexity: O(1)
|
|
214
|
-
*
|
|
215
|
-
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
216
|
-
* to restore balance in an AVL tree after inserting a node.
|
|
217
|
-
* @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
|
|
218
|
-
* AVL tree that needs to be balanced.
|
|
219
|
-
*/
|
|
220
|
-
_balancePath(node) {
|
|
221
|
-
node = this.ensureNode(node);
|
|
222
|
-
const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
|
|
223
|
-
for (let i = 0; i < path.length; i++) {
|
|
224
|
-
// second O(log n)
|
|
225
|
-
const A = path[i];
|
|
226
|
-
// Update Heights: After inserting a node, backtrack from the insertion point to the root node, updating the height of each node along the way.
|
|
227
|
-
this._updateHeight(A); // first O(1)
|
|
228
|
-
// Check Balance: Simultaneously with height updates, check if each node violates the balance property of an AVL tree.
|
|
229
|
-
// Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
|
|
230
|
-
switch (this._balanceFactor(A) // second O(1)
|
|
231
|
-
) {
|
|
232
|
-
case -2:
|
|
233
|
-
if (A && A.left) {
|
|
234
|
-
if (this._balanceFactor(A.left) <= 0) {
|
|
235
|
-
// second O(1)
|
|
236
|
-
// Left Rotation (LL Rotation): When the inserted node is in the left subtree of the left subtree, causing an imbalance.
|
|
237
|
-
this._balanceLL(A);
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
// Left-Right Rotation (LR Rotation): When the inserted node is in the right subtree of the left subtree, causing an imbalance.
|
|
241
|
-
this._balanceLR(A);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
break;
|
|
245
|
-
case +2:
|
|
246
|
-
if (A && A.right) {
|
|
247
|
-
if (this._balanceFactor(A.right) >= 0) {
|
|
248
|
-
// Right Rotation (RR Rotation): When the inserted node is in the right subtree of the right subtree, causing an imbalance.
|
|
249
|
-
this._balanceRR(A);
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
// Right-Left Rotation (RL Rotation): When the inserted node is in the left subtree of the right subtree, causing an imbalance.
|
|
253
|
-
this._balanceRL(A);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
// TODO So far, no sure if this is necessary that Recursive Repair: Once rotation operations are executed, it may cause imbalance issues at higher levels of the tree. Therefore, you need to recursively check and repair imbalance problems upwards until you reach the root node.
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
227
|
/**
|
|
261
228
|
* Time Complexity: O(1)
|
|
262
229
|
* Space Complexity: O(1)
|
|
263
|
-
* constant time, as these methods perform a fixed number of operations. constant space, as they only use a constant amount of memory.
|
|
264
230
|
*/
|
|
265
231
|
/**
|
|
266
232
|
* Time Complexity: O(1)
|
|
267
233
|
* Space Complexity: O(1)
|
|
268
234
|
*
|
|
269
235
|
* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
|
|
270
|
-
* @param {
|
|
236
|
+
* @param {NODE} A - A is a node in a binary tree.
|
|
271
237
|
*/
|
|
272
238
|
_balanceLL(A) {
|
|
273
239
|
const parentOfA = A.parent;
|
|
@@ -308,7 +274,7 @@ class AVLTree extends bst_1.BST {
|
|
|
308
274
|
* Space Complexity: O(1)
|
|
309
275
|
*
|
|
310
276
|
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
|
|
311
|
-
* @param {
|
|
277
|
+
* @param {NODE} A - A is a node in a binary tree.
|
|
312
278
|
*/
|
|
313
279
|
_balanceLR(A) {
|
|
314
280
|
const parentOfA = A.parent;
|
|
@@ -364,7 +330,7 @@ class AVLTree extends bst_1.BST {
|
|
|
364
330
|
* Space Complexity: O(1)
|
|
365
331
|
*
|
|
366
332
|
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
|
|
367
|
-
* @param {
|
|
333
|
+
* @param {NODE} A - A is a node in a binary tree.
|
|
368
334
|
*/
|
|
369
335
|
_balanceRR(A) {
|
|
370
336
|
const parentOfA = A.parent;
|
|
@@ -406,7 +372,7 @@ class AVLTree extends bst_1.BST {
|
|
|
406
372
|
* Space Complexity: O(1)
|
|
407
373
|
*
|
|
408
374
|
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
|
|
409
|
-
* @param {
|
|
375
|
+
* @param {NODE} A - A is a node in a binary tree.
|
|
410
376
|
*/
|
|
411
377
|
_balanceRL(A) {
|
|
412
378
|
const parentOfA = A.parent;
|
|
@@ -453,6 +419,69 @@ class AVLTree extends bst_1.BST {
|
|
|
453
419
|
B && this._updateHeight(B);
|
|
454
420
|
C && this._updateHeight(C);
|
|
455
421
|
}
|
|
422
|
+
/**
|
|
423
|
+
* Time Complexity: O(log n)
|
|
424
|
+
* Space Complexity: O(1)
|
|
425
|
+
* 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.
|
|
426
|
+
*/
|
|
427
|
+
/**
|
|
428
|
+
* Time Complexity: O(log n)
|
|
429
|
+
* Space Complexity: O(1)
|
|
430
|
+
*
|
|
431
|
+
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
432
|
+
* to restore balance in an AVL tree after inserting a node.
|
|
433
|
+
* @param {NODE} node - The `node` parameter in the `_balancePath` function represents the node in the
|
|
434
|
+
* AVL tree that needs to be balanced.
|
|
435
|
+
*/
|
|
436
|
+
_balancePath(node) {
|
|
437
|
+
node = this.ensureNode(node);
|
|
438
|
+
const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
|
|
439
|
+
for (let i = 0; i < path.length; i++) {
|
|
440
|
+
// second O(log n)
|
|
441
|
+
const A = path[i];
|
|
442
|
+
// Update Heights: After inserting a node, backtrack from the insertion point to the root node, updating the height of each node along the way.
|
|
443
|
+
this._updateHeight(A); // first O(1)
|
|
444
|
+
// Check Balance: Simultaneously with height updates, check if each node violates the balance property of an AVL tree.
|
|
445
|
+
// Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
|
|
446
|
+
switch (this._balanceFactor(A) // second O(1)
|
|
447
|
+
) {
|
|
448
|
+
case -2:
|
|
449
|
+
if (A && A.left) {
|
|
450
|
+
if (this._balanceFactor(A.left) <= 0) {
|
|
451
|
+
// second O(1)
|
|
452
|
+
// Left Rotation (LL Rotation): When the inserted node is in the left subtree of the left subtree, causing an imbalance.
|
|
453
|
+
this._balanceLL(A);
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
// Left-Right Rotation (LR Rotation): When the inserted node is in the right subtree of the left subtree, causing an imbalance.
|
|
457
|
+
this._balanceLR(A);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
break;
|
|
461
|
+
case +2:
|
|
462
|
+
if (A && A.right) {
|
|
463
|
+
if (this._balanceFactor(A.right) >= 0) {
|
|
464
|
+
// Right Rotation (RR Rotation): When the inserted node is in the right subtree of the right subtree, causing an imbalance.
|
|
465
|
+
this._balanceRR(A);
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
// Right-Left Rotation (RL Rotation): When the inserted node is in the left subtree of the right subtree, causing an imbalance.
|
|
469
|
+
this._balanceRL(A);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
// TODO So far, no sure if this is necessary that Recursive Repair: Once rotation operations are executed, it may cause imbalance issues at higher levels of the tree. Therefore, you need to recursively check and repair imbalance problems upwards until you reach the root node.
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* The function replaces an old node with a new node while preserving the height of the old node.
|
|
478
|
+
* @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace with the
|
|
479
|
+
* `newNode`.
|
|
480
|
+
* @param {NODE} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
|
|
481
|
+
* the data structure.
|
|
482
|
+
* @returns the result of calling the `_replaceNode` method on the superclass, passing in the
|
|
483
|
+
* `oldNode` and `newNode` as arguments.
|
|
484
|
+
*/
|
|
456
485
|
_replaceNode(oldNode, newNode) {
|
|
457
486
|
newNode.height = oldNode.height;
|
|
458
487
|
return super._replaceNode(oldNode, newNode);
|
|
@@ -12,12 +12,34 @@ export declare class BinaryIndexedTree {
|
|
|
12
12
|
max: number;
|
|
13
13
|
});
|
|
14
14
|
protected _freqMap: Record<number, number>;
|
|
15
|
+
/**
|
|
16
|
+
* The function returns the frequency map of numbers.
|
|
17
|
+
* @returns The `_freqMap` property, which is a record with number keys and number values, is being
|
|
18
|
+
* returned.
|
|
19
|
+
*/
|
|
15
20
|
get freqMap(): Record<number, number>;
|
|
16
21
|
protected _msb: number;
|
|
22
|
+
/**
|
|
23
|
+
* The function returns the value of the _msb property.
|
|
24
|
+
* @returns The `_msb` property of the object.
|
|
25
|
+
*/
|
|
17
26
|
get msb(): number;
|
|
18
27
|
protected _negativeCount: number;
|
|
28
|
+
/**
|
|
29
|
+
* The function returns the value of the _negativeCount property.
|
|
30
|
+
* @returns The method is returning the value of the variable `_negativeCount`, which is of type
|
|
31
|
+
* `number`.
|
|
32
|
+
*/
|
|
19
33
|
get negativeCount(): number;
|
|
34
|
+
/**
|
|
35
|
+
* The above function returns the value of the protected variable `_freq`.
|
|
36
|
+
* @returns The frequency value stored in the protected variable `_freq`.
|
|
37
|
+
*/
|
|
20
38
|
get freq(): number;
|
|
39
|
+
/**
|
|
40
|
+
* The above function returns the maximum value.
|
|
41
|
+
* @returns The maximum value stored in the variable `_max`.
|
|
42
|
+
*/
|
|
21
43
|
get max(): number;
|
|
22
44
|
/**
|
|
23
45
|
* The function "readSingle" reads a single number from a specified index.
|
|
@@ -23,18 +23,40 @@ class BinaryIndexedTree {
|
|
|
23
23
|
this._msb = (0, utils_1.getMSB)(max);
|
|
24
24
|
this._negativeCount = frequency < 0 ? max : 0;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* The function returns the frequency map of numbers.
|
|
28
|
+
* @returns The `_freqMap` property, which is a record with number keys and number values, is being
|
|
29
|
+
* returned.
|
|
30
|
+
*/
|
|
26
31
|
get freqMap() {
|
|
27
32
|
return this._freqMap;
|
|
28
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* The function returns the value of the _msb property.
|
|
36
|
+
* @returns The `_msb` property of the object.
|
|
37
|
+
*/
|
|
29
38
|
get msb() {
|
|
30
39
|
return this._msb;
|
|
31
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* The function returns the value of the _negativeCount property.
|
|
43
|
+
* @returns The method is returning the value of the variable `_negativeCount`, which is of type
|
|
44
|
+
* `number`.
|
|
45
|
+
*/
|
|
32
46
|
get negativeCount() {
|
|
33
47
|
return this._negativeCount;
|
|
34
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* The above function returns the value of the protected variable `_freq`.
|
|
51
|
+
* @returns The frequency value stored in the protected variable `_freq`.
|
|
52
|
+
*/
|
|
35
53
|
get freq() {
|
|
36
54
|
return this._freq;
|
|
37
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* The above function returns the maximum value.
|
|
58
|
+
* @returns The maximum value stored in the variable `_max`.
|
|
59
|
+
*/
|
|
38
60
|
get max() {
|
|
39
61
|
return this._max;
|
|
40
62
|
}
|