data-structure-typed 1.12.11 → 1.15.0
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/README.md +278 -179
- package/dist/data-structures/binary-tree/avl-tree.d.ts +14 -5
- package/dist/data-structures/binary-tree/avl-tree.js +15 -6
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +11 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +11 -2
- package/dist/data-structures/binary-tree/binary-tree.d.ts +72 -18
- package/dist/data-structures/binary-tree/binary-tree.js +139 -62
- package/dist/data-structures/binary-tree/bst.d.ts +92 -5
- package/dist/data-structures/binary-tree/bst.js +89 -5
- package/dist/data-structures/binary-tree/segment-tree.d.ts +70 -2
- package/dist/data-structures/binary-tree/segment-tree.js +86 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +34 -3
- package/dist/data-structures/binary-tree/tree-multiset.js +35 -4
- package/dist/data-structures/graph/abstract-graph.d.ts +45 -5
- package/dist/data-structures/graph/abstract-graph.js +59 -11
- package/dist/data-structures/graph/directed-graph.d.ts +26 -4
- package/dist/data-structures/graph/directed-graph.js +38 -39
- package/dist/data-structures/graph/undirected-graph.d.ts +23 -0
- package/dist/data-structures/graph/undirected-graph.js +41 -3
- package/dist/data-structures/hash/coordinate-map.d.ts +12 -3
- package/dist/data-structures/hash/coordinate-map.js +21 -2
- package/dist/data-structures/hash/coordinate-set.d.ts +12 -3
- package/dist/data-structures/hash/coordinate-set.js +21 -2
- package/dist/data-structures/heap/heap.d.ts +25 -6
- package/dist/data-structures/heap/heap.js +46 -8
- package/dist/data-structures/heap/max-heap.d.ts +5 -2
- package/dist/data-structures/heap/max-heap.js +5 -2
- package/dist/data-structures/heap/min-heap.d.ts +5 -2
- package/dist/data-structures/heap/min-heap.js +5 -2
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +32 -9
- package/dist/data-structures/linked-list/doubly-linked-list.js +75 -8
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +267 -330
- package/dist/data-structures/linked-list/singly-linked-list.js +263 -275
- package/dist/data-structures/matrix/matrix.d.ts +5 -2
- package/dist/data-structures/matrix/matrix.js +5 -2
- package/dist/data-structures/matrix/matrix2d.d.ts +5 -2
- package/dist/data-structures/matrix/matrix2d.js +5 -2
- package/dist/data-structures/matrix/navigator.d.ts +5 -2
- package/dist/data-structures/matrix/vector2d.d.ts +5 -2
- package/dist/data-structures/matrix/vector2d.js +5 -2
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +5 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +5 -2
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +5 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +5 -2
- package/dist/data-structures/priority-queue/priority-queue.d.ts +14 -5
- package/dist/data-structures/priority-queue/priority-queue.js +20 -4
- package/dist/data-structures/queue/deque.d.ts +30 -16
- package/dist/data-structures/queue/deque.js +62 -12
- package/dist/data-structures/queue/queue.d.ts +4 -4
- package/dist/data-structures/queue/queue.js +4 -4
- package/dist/data-structures/stack/stack.d.ts +1 -1
- package/dist/data-structures/stack/stack.js +1 -1
- package/dist/data-structures/trie/trie.d.ts +6 -3
- package/dist/data-structures/trie/trie.js +7 -4
- package/dist/data-structures/types/abstract-graph.d.ts +2 -2
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/types/utils.d.ts +8 -10
- package/dist/utils/types/utils.js +0 -1
- package/dist/utils/utils.d.ts +18 -8
- package/dist/utils/utils.js +93 -47
- package/package.json +2 -2
- package/src/data-structures/binary-tree/aa-tree.ts +1 -1
- package/src/data-structures/binary-tree/binary-tree.ts +84 -14
- package/src/data-structures/binary-tree/segment-tree.ts +45 -13
- package/src/data-structures/graph/abstract-graph.ts +58 -15
- package/src/data-structures/graph/directed-graph.ts +14 -5
- package/src/data-structures/graph/undirected-graph.ts +23 -6
- package/src/data-structures/hash/coordinate-map.ts +13 -1
- package/src/data-structures/hash/coordinate-set.ts +13 -1
- package/src/data-structures/heap/heap.ts +31 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +68 -11
- package/src/data-structures/linked-list/singly-linked-list.ts +312 -334
- package/src/data-structures/priority-queue/priority-queue.ts +15 -2
- package/src/data-structures/queue/deque.ts +38 -8
- package/src/data-structures/types/abstract-graph.ts +3 -3
- package/tests/unit/data-structures/graph/directed-graph.test.ts +431 -8
- package/dist/utils/trampoline.d.ts +0 -14
- package/dist/utils/trampoline.js +0 -130
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
4
7
|
*/
|
|
5
8
|
import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTDeletedResult } from '../types';
|
|
6
9
|
import { BinaryTree, BinaryTreeNode, LoopType } from './binary-tree';
|
|
@@ -13,13 +16,17 @@ export declare class BSTNode<T> extends BinaryTreeNode<T> {
|
|
|
13
16
|
clone(): BSTNode<T>;
|
|
14
17
|
}
|
|
15
18
|
export declare class BST<T> extends BinaryTree<T> {
|
|
19
|
+
/**
|
|
20
|
+
* The constructor function accepts an optional options object and sets the comparator property if provided.
|
|
21
|
+
* @param [options] - An optional object that can contain the following properties:
|
|
22
|
+
*/
|
|
16
23
|
constructor(options?: {
|
|
17
24
|
comparator?: BSTComparator;
|
|
18
25
|
loopType?: LoopType;
|
|
19
26
|
});
|
|
20
27
|
createNode(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
|
|
21
28
|
/**
|
|
22
|
-
* The `
|
|
29
|
+
* The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
|
|
23
30
|
* the ID matches, and returns the inserted node.
|
|
24
31
|
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node. It is used to
|
|
25
32
|
* determine the position of the node in the binary search tree.
|
|
@@ -28,17 +35,97 @@ export declare class BST<T> extends BinaryTree<T> {
|
|
|
28
35
|
* @param {number} [count=1] - The `count` parameter represents the number of times the value should be inserted into
|
|
29
36
|
* the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
|
|
30
37
|
* inserted once.
|
|
31
|
-
* @returns The method `
|
|
38
|
+
* @returns The method `add` returns a `BSTNode<T>` object or `null`.
|
|
39
|
+
*/
|
|
40
|
+
add(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
|
|
41
|
+
/**
|
|
42
|
+
* The `get` function returns the first node in a binary search tree that matches the given property value or name.
|
|
43
|
+
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
44
|
+
* generic type `T`. It represents the value of the property that you want to search for in the binary search tree.
|
|
45
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
46
|
+
* specifies the property name to use for searching the binary search tree nodes. If not provided, it defaults to
|
|
47
|
+
* `'id'`.
|
|
48
|
+
* @returns The method is returning a BSTNode<T> object or null.
|
|
32
49
|
*/
|
|
33
|
-
put(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
|
|
34
50
|
get(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): BSTNode<T> | null;
|
|
51
|
+
/**
|
|
52
|
+
* The function returns the id of the rightmost node if the comparison between two values is less than, the id of the
|
|
53
|
+
* leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
|
|
54
|
+
* @returns The function `lastKey()` returns the ID of the rightmost node in a binary tree. If the comparison between
|
|
55
|
+
* the first two elements in the tree is less than, it returns the ID of the rightmost node. If the comparison is
|
|
56
|
+
* greater than, it returns the ID of the leftmost node. Otherwise, it also returns the ID of the rightmost node. If
|
|
57
|
+
* there are no nodes in
|
|
58
|
+
*/
|
|
35
59
|
lastKey(): number;
|
|
60
|
+
/**
|
|
61
|
+
* The `remove` function in this TypeScript code removes a node from a binary search tree and returns information about
|
|
62
|
+
* the deleted node and any nodes that need to be balanced.
|
|
63
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that needs to be removed
|
|
64
|
+
* from the binary search tree.
|
|
65
|
+
* @param {boolean} [ignoreCount] - A boolean flag indicating whether to ignore the count of the node being removed. If
|
|
66
|
+
* set to true, the count of the node will not be considered and the node will be removed regardless of its count. If
|
|
67
|
+
* set to false or not provided, the count of the node will be taken into account and the
|
|
68
|
+
* @returns an array of `BSTDeletedResult<T>` objects.
|
|
69
|
+
*/
|
|
36
70
|
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BSTDeletedResult<T>[];
|
|
71
|
+
/**
|
|
72
|
+
* The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
|
|
73
|
+
* option to specify the property name and whether to return only one node.
|
|
74
|
+
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
75
|
+
* generic type `T`. It represents the property value that you want to search for in the binary search tree.
|
|
76
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
77
|
+
* specifies the property of the nodes to compare with the `nodeProperty` parameter. If not provided, it defaults to
|
|
78
|
+
* `'id'`.
|
|
79
|
+
* @param {boolean} [onlyOne] - A boolean value indicating whether to return only one node that matches the given
|
|
80
|
+
* nodeProperty. If set to true, the function will stop traversing the tree and return the first matching node. If set
|
|
81
|
+
* to false or not provided, the function will return all nodes that match the given nodeProperty.
|
|
82
|
+
* @returns an array of BSTNode<T> objects.
|
|
83
|
+
*/
|
|
37
84
|
getNodes(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): BSTNode<T>[];
|
|
85
|
+
/**
|
|
86
|
+
* The `lesserSum` function calculates the sum of a specified property in all nodes with an ID less than a given ID in
|
|
87
|
+
* a binary search tree.
|
|
88
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node for which you want to
|
|
89
|
+
* calculate the lesser sum.
|
|
90
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
91
|
+
* specifies the property of the binary tree node to use for calculating the sum. If not provided, it defaults to 'id'.
|
|
92
|
+
* @returns The function `lesserSum` returns a number, which represents the sum of the values of the nodes in the
|
|
93
|
+
* binary search tree that have a property value lesser than the given `id`.
|
|
94
|
+
*/
|
|
38
95
|
lesserSum(id: BinaryTreeNodeId, propertyName?: BinaryTreeNodePropertyName): number;
|
|
96
|
+
/**
|
|
97
|
+
* The function `allGreaterNodesAdd` updates the value of a specified property for all nodes in a binary search tree
|
|
98
|
+
* that have a greater value than a given node.
|
|
99
|
+
* @param node - The `node` parameter is of type `BSTNode<T>`, which represents a node in a binary search tree. It
|
|
100
|
+
* contains properties such as `id` and `count`.
|
|
101
|
+
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
|
|
102
|
+
* each node should be increased.
|
|
103
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
|
|
104
|
+
* property of the BSTNode to be modified. It can be either 'id' or 'count'. If propertyName is not provided, it
|
|
105
|
+
* defaults to 'id'.
|
|
106
|
+
* @returns a boolean value.
|
|
107
|
+
*/
|
|
39
108
|
allGreaterNodesAdd(node: BSTNode<T>, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* The `balance` function takes a sorted array of nodes and builds a balanced binary search tree using either a
|
|
111
|
+
* recursive or iterative approach.
|
|
112
|
+
* @returns The `balance()` function returns a boolean value.
|
|
113
|
+
*/
|
|
40
114
|
balance(): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* The function `isAVLBalanced` checks if a binary search tree is balanced according to the AVL tree property.
|
|
117
|
+
* @returns The function `isAVLBalanced()` returns a boolean value. It returns `true` if the binary search tree (BST)
|
|
118
|
+
* is balanced according to the AVL tree property, and `false` otherwise.
|
|
119
|
+
*/
|
|
41
120
|
isAVLBalanced(): boolean;
|
|
42
121
|
protected _comparator: BSTComparator;
|
|
122
|
+
/**
|
|
123
|
+
* The function compares two binary tree node IDs using a comparator function and returns whether the first ID is
|
|
124
|
+
* greater than, less than, or equal to the second ID.
|
|
125
|
+
* @param {BinaryTreeNodeId} a - a is a BinaryTreeNodeId, which represents the identifier of a binary tree node.
|
|
126
|
+
* @param {BinaryTreeNodeId} b - The parameter "b" in the above code refers to a BinaryTreeNodeId.
|
|
127
|
+
* @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
|
|
128
|
+
* than), or CP.eq (equal).
|
|
129
|
+
*/
|
|
43
130
|
protected _compare(a: BinaryTreeNodeId, b: BinaryTreeNodeId): CP;
|
|
44
131
|
}
|
|
@@ -52,6 +52,10 @@ var BSTNode = /** @class */ (function (_super) {
|
|
|
52
52
|
exports.BSTNode = BSTNode;
|
|
53
53
|
var BST = /** @class */ (function (_super) {
|
|
54
54
|
__extends(BST, _super);
|
|
55
|
+
/**
|
|
56
|
+
* The constructor function accepts an optional options object and sets the comparator property if provided.
|
|
57
|
+
* @param [options] - An optional object that can contain the following properties:
|
|
58
|
+
*/
|
|
55
59
|
function BST(options) {
|
|
56
60
|
var _this = _super.call(this, options) || this;
|
|
57
61
|
_this._comparator = function (a, b) { return a - b; };
|
|
@@ -67,7 +71,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
67
71
|
return val !== null ? new BSTNode(id, val, count) : null;
|
|
68
72
|
};
|
|
69
73
|
/**
|
|
70
|
-
* The `
|
|
74
|
+
* The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
|
|
71
75
|
* the ID matches, and returns the inserted node.
|
|
72
76
|
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node. It is used to
|
|
73
77
|
* determine the position of the node in the binary search tree.
|
|
@@ -76,9 +80,9 @@ var BST = /** @class */ (function (_super) {
|
|
|
76
80
|
* @param {number} [count=1] - The `count` parameter represents the number of times the value should be inserted into
|
|
77
81
|
* the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
|
|
78
82
|
* inserted once.
|
|
79
|
-
* @returns The method `
|
|
83
|
+
* @returns The method `add` returns a `BSTNode<T>` object or `null`.
|
|
80
84
|
*/
|
|
81
|
-
BST.prototype.
|
|
85
|
+
BST.prototype.add = function (id, val, count) {
|
|
82
86
|
var _a;
|
|
83
87
|
if (count === void 0) { count = 1; }
|
|
84
88
|
var inserted = null;
|
|
@@ -152,11 +156,28 @@ var BST = /** @class */ (function (_super) {
|
|
|
152
156
|
}
|
|
153
157
|
return inserted;
|
|
154
158
|
};
|
|
159
|
+
/**
|
|
160
|
+
* The `get` function returns the first node in a binary search tree that matches the given property value or name.
|
|
161
|
+
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
162
|
+
* generic type `T`. It represents the value of the property that you want to search for in the binary search tree.
|
|
163
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
164
|
+
* specifies the property name to use for searching the binary search tree nodes. If not provided, it defaults to
|
|
165
|
+
* `'id'`.
|
|
166
|
+
* @returns The method is returning a BSTNode<T> object or null.
|
|
167
|
+
*/
|
|
155
168
|
BST.prototype.get = function (nodeProperty, propertyName) {
|
|
156
169
|
var _a;
|
|
157
170
|
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
158
171
|
return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;
|
|
159
172
|
};
|
|
173
|
+
/**
|
|
174
|
+
* The function returns the id of the rightmost node if the comparison between two values is less than, the id of the
|
|
175
|
+
* leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
|
|
176
|
+
* @returns The function `lastKey()` returns the ID of the rightmost node in a binary tree. If the comparison between
|
|
177
|
+
* the first two elements in the tree is less than, it returns the ID of the rightmost node. If the comparison is
|
|
178
|
+
* greater than, it returns the ID of the leftmost node. Otherwise, it also returns the ID of the rightmost node. If
|
|
179
|
+
* there are no nodes in
|
|
180
|
+
*/
|
|
160
181
|
BST.prototype.lastKey = function () {
|
|
161
182
|
var _a, _b, _c, _d, _e, _f;
|
|
162
183
|
if (this._compare(0, 1) === CP.lt)
|
|
@@ -166,6 +187,16 @@ var BST = /** @class */ (function (_super) {
|
|
|
166
187
|
else
|
|
167
188
|
return (_f = (_e = this.getRightMost()) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : 0;
|
|
168
189
|
};
|
|
190
|
+
/**
|
|
191
|
+
* The `remove` function in this TypeScript code removes a node from a binary search tree and returns information about
|
|
192
|
+
* the deleted node and any nodes that need to be balanced.
|
|
193
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that needs to be removed
|
|
194
|
+
* from the binary search tree.
|
|
195
|
+
* @param {boolean} [ignoreCount] - A boolean flag indicating whether to ignore the count of the node being removed. If
|
|
196
|
+
* set to true, the count of the node will not be considered and the node will be removed regardless of its count. If
|
|
197
|
+
* set to false or not provided, the count of the node will be taken into account and the
|
|
198
|
+
* @returns an array of `BSTDeletedResult<T>` objects.
|
|
199
|
+
*/
|
|
169
200
|
BST.prototype.remove = function (id, ignoreCount) {
|
|
170
201
|
var bstDeletedResult = [];
|
|
171
202
|
if (!this.root)
|
|
@@ -217,6 +248,19 @@ var BST = /** @class */ (function (_super) {
|
|
|
217
248
|
bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
|
|
218
249
|
return bstDeletedResult;
|
|
219
250
|
};
|
|
251
|
+
/**
|
|
252
|
+
* The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
|
|
253
|
+
* option to specify the property name and whether to return only one node.
|
|
254
|
+
* @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
255
|
+
* generic type `T`. It represents the property value that you want to search for in the binary search tree.
|
|
256
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
257
|
+
* specifies the property of the nodes to compare with the `nodeProperty` parameter. If not provided, it defaults to
|
|
258
|
+
* `'id'`.
|
|
259
|
+
* @param {boolean} [onlyOne] - A boolean value indicating whether to return only one node that matches the given
|
|
260
|
+
* nodeProperty. If set to true, the function will stop traversing the tree and return the first matching node. If set
|
|
261
|
+
* to false or not provided, the function will return all nodes that match the given nodeProperty.
|
|
262
|
+
* @returns an array of BSTNode<T> objects.
|
|
263
|
+
*/
|
|
220
264
|
BST.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {
|
|
221
265
|
var _this = this;
|
|
222
266
|
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
@@ -265,6 +309,16 @@ var BST = /** @class */ (function (_super) {
|
|
|
265
309
|
return result;
|
|
266
310
|
};
|
|
267
311
|
// --- start additional functions
|
|
312
|
+
/**
|
|
313
|
+
* The `lesserSum` function calculates the sum of a specified property in all nodes with an ID less than a given ID in
|
|
314
|
+
* a binary search tree.
|
|
315
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node for which you want to
|
|
316
|
+
* calculate the lesser sum.
|
|
317
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
318
|
+
* specifies the property of the binary tree node to use for calculating the sum. If not provided, it defaults to 'id'.
|
|
319
|
+
* @returns The function `lesserSum` returns a number, which represents the sum of the values of the nodes in the
|
|
320
|
+
* binary search tree that have a property value lesser than the given `id`.
|
|
321
|
+
*/
|
|
268
322
|
BST.prototype.lesserSum = function (id, propertyName) {
|
|
269
323
|
var _this = this;
|
|
270
324
|
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
@@ -343,6 +397,18 @@ var BST = /** @class */ (function (_super) {
|
|
|
343
397
|
}
|
|
344
398
|
return sum;
|
|
345
399
|
};
|
|
400
|
+
/**
|
|
401
|
+
* The function `allGreaterNodesAdd` updates the value of a specified property for all nodes in a binary search tree
|
|
402
|
+
* that have a greater value than a given node.
|
|
403
|
+
* @param node - The `node` parameter is of type `BSTNode<T>`, which represents a node in a binary search tree. It
|
|
404
|
+
* contains properties such as `id` and `count`.
|
|
405
|
+
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
|
|
406
|
+
* each node should be increased.
|
|
407
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
|
|
408
|
+
* property of the BSTNode to be modified. It can be either 'id' or 'count'. If propertyName is not provided, it
|
|
409
|
+
* defaults to 'id'.
|
|
410
|
+
* @returns a boolean value.
|
|
411
|
+
*/
|
|
346
412
|
BST.prototype.allGreaterNodesAdd = function (node, delta, propertyName) {
|
|
347
413
|
var _this = this;
|
|
348
414
|
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
@@ -391,6 +457,11 @@ var BST = /** @class */ (function (_super) {
|
|
|
391
457
|
return true;
|
|
392
458
|
}
|
|
393
459
|
};
|
|
460
|
+
/**
|
|
461
|
+
* The `balance` function takes a sorted array of nodes and builds a balanced binary search tree using either a
|
|
462
|
+
* recursive or iterative approach.
|
|
463
|
+
* @returns The `balance()` function returns a boolean value.
|
|
464
|
+
*/
|
|
394
465
|
BST.prototype.balance = function () {
|
|
395
466
|
var _this = this;
|
|
396
467
|
var sorted = this.DFS('in', 'node'), n = sorted.length;
|
|
@@ -403,7 +474,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
403
474
|
return;
|
|
404
475
|
var m = l + Math.floor((r - l) / 2);
|
|
405
476
|
var midNode = sorted[m];
|
|
406
|
-
_this.
|
|
477
|
+
_this.add(midNode.id, midNode.val, midNode.count);
|
|
407
478
|
buildBalanceBST_1(l, m - 1);
|
|
408
479
|
buildBalanceBST_1(m + 1, r);
|
|
409
480
|
};
|
|
@@ -419,7 +490,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
419
490
|
if (l <= r) {
|
|
420
491
|
var m = l + Math.floor((r - l) / 2);
|
|
421
492
|
var midNode = sorted[m];
|
|
422
|
-
this.
|
|
493
|
+
this.add(midNode.id, midNode.val, midNode.count);
|
|
423
494
|
stack.push([m + 1, r]);
|
|
424
495
|
stack.push([l, m - 1]);
|
|
425
496
|
}
|
|
@@ -428,6 +499,11 @@ var BST = /** @class */ (function (_super) {
|
|
|
428
499
|
return true;
|
|
429
500
|
}
|
|
430
501
|
};
|
|
502
|
+
/**
|
|
503
|
+
* The function `isAVLBalanced` checks if a binary search tree is balanced according to the AVL tree property.
|
|
504
|
+
* @returns The function `isAVLBalanced()` returns a boolean value. It returns `true` if the binary search tree (BST)
|
|
505
|
+
* is balanced according to the AVL tree property, and `false` otherwise.
|
|
506
|
+
*/
|
|
431
507
|
BST.prototype.isAVLBalanced = function () {
|
|
432
508
|
var _a, _b;
|
|
433
509
|
if (!this.root)
|
|
@@ -474,6 +550,14 @@ var BST = /** @class */ (function (_super) {
|
|
|
474
550
|
}
|
|
475
551
|
return balanced;
|
|
476
552
|
};
|
|
553
|
+
/**
|
|
554
|
+
* The function compares two binary tree node IDs using a comparator function and returns whether the first ID is
|
|
555
|
+
* greater than, less than, or equal to the second ID.
|
|
556
|
+
* @param {BinaryTreeNodeId} a - a is a BinaryTreeNodeId, which represents the identifier of a binary tree node.
|
|
557
|
+
* @param {BinaryTreeNodeId} b - The parameter "b" in the above code refers to a BinaryTreeNodeId.
|
|
558
|
+
* @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
|
|
559
|
+
* than), or CP.eq (equal).
|
|
560
|
+
*/
|
|
477
561
|
BST.prototype._compare = function (a, b) {
|
|
478
562
|
var compared = this._comparator(a, b);
|
|
479
563
|
if (compared > 0)
|
|
@@ -1,37 +1,105 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
4
7
|
*/
|
|
5
8
|
import type { SegmentTreeNodeVal } from '../types';
|
|
6
9
|
export declare class SegmentTreeNode {
|
|
7
10
|
constructor(start: number, end: number, sum: number, val?: SegmentTreeNodeVal | null);
|
|
8
11
|
protected _start: number;
|
|
9
12
|
get start(): number;
|
|
13
|
+
/**
|
|
14
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
15
|
+
*/
|
|
16
|
+
getStart(): number;
|
|
10
17
|
set start(v: number);
|
|
11
18
|
protected _end: number;
|
|
12
19
|
get end(): number;
|
|
20
|
+
/**
|
|
21
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
22
|
+
*/
|
|
23
|
+
getEnd(): number;
|
|
13
24
|
set end(v: number);
|
|
14
25
|
protected _val: SegmentTreeNodeVal | null;
|
|
15
26
|
get val(): SegmentTreeNodeVal | null;
|
|
27
|
+
/**
|
|
28
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
29
|
+
*/
|
|
30
|
+
getVal(): SegmentTreeNodeVal | null;
|
|
16
31
|
set val(v: SegmentTreeNodeVal | null);
|
|
17
32
|
protected _sum: number;
|
|
18
33
|
get sum(): number;
|
|
34
|
+
/**
|
|
35
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
36
|
+
*/
|
|
37
|
+
getSum(): number;
|
|
19
38
|
set sum(v: number);
|
|
20
39
|
protected _left: SegmentTreeNode | null;
|
|
21
40
|
get left(): SegmentTreeNode | null;
|
|
41
|
+
/**
|
|
42
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
43
|
+
*/
|
|
44
|
+
getLeft(): SegmentTreeNode | null;
|
|
22
45
|
set left(v: SegmentTreeNode | null);
|
|
23
46
|
protected _right: SegmentTreeNode | null;
|
|
24
47
|
get right(): SegmentTreeNode | null;
|
|
48
|
+
/**
|
|
49
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
50
|
+
*/
|
|
51
|
+
getRight(): SegmentTreeNode | null;
|
|
25
52
|
set right(v: SegmentTreeNode | null);
|
|
26
53
|
}
|
|
27
54
|
export declare class SegmentTree {
|
|
28
55
|
protected _values: number[];
|
|
29
56
|
protected _start: number;
|
|
30
57
|
protected _end: number;
|
|
58
|
+
/**
|
|
59
|
+
* The constructor initializes the values, start, end, and root properties of an object.
|
|
60
|
+
* @param {number[]} values - An array of numbers that will be used to build a binary search tree.
|
|
61
|
+
* @param {number} [start] - The `start` parameter is the index of the first element in the `values` array that should
|
|
62
|
+
* be included in the range. If no value is provided for `start`, it defaults to 0, which means the range starts from
|
|
63
|
+
* the beginning of the array.
|
|
64
|
+
* @param {number} [end] - The "end" parameter is the index of the last element in the "values" array that should be
|
|
65
|
+
* included in the range. If not provided, it defaults to the index of the last element in the "values" array.
|
|
66
|
+
*/
|
|
31
67
|
constructor(values: number[], start?: number, end?: number);
|
|
32
68
|
protected _root: SegmentTreeNode | null;
|
|
33
69
|
get root(): SegmentTreeNode | null;
|
|
70
|
+
/**
|
|
71
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
72
|
+
*/
|
|
73
|
+
getRoot(): SegmentTreeNode | null;
|
|
74
|
+
set root(v: SegmentTreeNode | null);
|
|
75
|
+
/**
|
|
76
|
+
* The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes
|
|
77
|
+
* for each segment.
|
|
78
|
+
* @param {number} start - The `start` parameter represents the starting index of the segment or range for which we are
|
|
79
|
+
* building the segment tree.
|
|
80
|
+
* @param {number} end - The `end` parameter represents the ending index of the segment or range for which we are
|
|
81
|
+
* building the segment tree.
|
|
82
|
+
* @returns a SegmentTreeNode object.
|
|
83
|
+
*/
|
|
34
84
|
build(start: number, end: number): SegmentTreeNode;
|
|
85
|
+
/**
|
|
86
|
+
* The function updates the value of a node in a segment tree and recalculates the sum of its children if they exist.
|
|
87
|
+
* @param {number} index - The index parameter represents the index of the node in the segment tree that needs to be
|
|
88
|
+
* updated.
|
|
89
|
+
* @param {number} sum - The `sum` parameter represents the new value that should be assigned to the `sum` property of
|
|
90
|
+
* the `SegmentTreeNode` at the specified `index`.
|
|
91
|
+
* @param {SegmentTreeNodeVal} [val] - The `val` parameter is an optional value that can be assigned to the `val`
|
|
92
|
+
* property of the `SegmentTreeNode` object. It is not currently used in the code, but you can uncomment the line `//
|
|
93
|
+
* cur.val = val;` and pass a value for `val` in the
|
|
94
|
+
* @returns The function does not return anything.
|
|
95
|
+
*/
|
|
35
96
|
updateNode(index: number, sum: number, val?: SegmentTreeNodeVal): void;
|
|
97
|
+
/**
|
|
98
|
+
* The function `querySumByRange` calculates the sum of values within a given range in a segment tree.
|
|
99
|
+
* @param {number} indexA - The starting index of the range for which you want to calculate the sum.
|
|
100
|
+
* @param {number} indexB - The parameter `indexB` represents the ending index of the range for which you want to
|
|
101
|
+
* calculate the sum.
|
|
102
|
+
* @returns The function `querySumByRange` returns a number.
|
|
103
|
+
*/
|
|
36
104
|
querySumByRange(indexA: number, indexB: number): number;
|
|
37
105
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* data-structure-typed
|
|
4
|
+
*
|
|
5
|
+
* @author Tyler Zeng
|
|
6
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
7
|
+
* @license MIT License
|
|
5
8
|
*/
|
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
10
|
exports.SegmentTree = exports.SegmentTreeNode = void 0;
|
|
@@ -28,6 +31,12 @@ var SegmentTreeNode = /** @class */ (function () {
|
|
|
28
31
|
enumerable: false,
|
|
29
32
|
configurable: true
|
|
30
33
|
});
|
|
34
|
+
/**
|
|
35
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
36
|
+
*/
|
|
37
|
+
SegmentTreeNode.prototype.getStart = function () {
|
|
38
|
+
return this._start;
|
|
39
|
+
};
|
|
31
40
|
Object.defineProperty(SegmentTreeNode.prototype, "end", {
|
|
32
41
|
get: function () {
|
|
33
42
|
return this._end;
|
|
@@ -38,6 +47,12 @@ var SegmentTreeNode = /** @class */ (function () {
|
|
|
38
47
|
enumerable: false,
|
|
39
48
|
configurable: true
|
|
40
49
|
});
|
|
50
|
+
/**
|
|
51
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
52
|
+
*/
|
|
53
|
+
SegmentTreeNode.prototype.getEnd = function () {
|
|
54
|
+
return this._end;
|
|
55
|
+
};
|
|
41
56
|
Object.defineProperty(SegmentTreeNode.prototype, "val", {
|
|
42
57
|
get: function () {
|
|
43
58
|
return this._val;
|
|
@@ -48,6 +63,12 @@ var SegmentTreeNode = /** @class */ (function () {
|
|
|
48
63
|
enumerable: false,
|
|
49
64
|
configurable: true
|
|
50
65
|
});
|
|
66
|
+
/**
|
|
67
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
68
|
+
*/
|
|
69
|
+
SegmentTreeNode.prototype.getVal = function () {
|
|
70
|
+
return this._val;
|
|
71
|
+
};
|
|
51
72
|
Object.defineProperty(SegmentTreeNode.prototype, "sum", {
|
|
52
73
|
get: function () {
|
|
53
74
|
return this._sum;
|
|
@@ -58,6 +79,12 @@ var SegmentTreeNode = /** @class */ (function () {
|
|
|
58
79
|
enumerable: false,
|
|
59
80
|
configurable: true
|
|
60
81
|
});
|
|
82
|
+
/**
|
|
83
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
84
|
+
*/
|
|
85
|
+
SegmentTreeNode.prototype.getSum = function () {
|
|
86
|
+
return this._sum;
|
|
87
|
+
};
|
|
61
88
|
Object.defineProperty(SegmentTreeNode.prototype, "left", {
|
|
62
89
|
get: function () {
|
|
63
90
|
return this._left;
|
|
@@ -68,6 +95,12 @@ var SegmentTreeNode = /** @class */ (function () {
|
|
|
68
95
|
enumerable: false,
|
|
69
96
|
configurable: true
|
|
70
97
|
});
|
|
98
|
+
/**
|
|
99
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
100
|
+
*/
|
|
101
|
+
SegmentTreeNode.prototype.getLeft = function () {
|
|
102
|
+
return this._left;
|
|
103
|
+
};
|
|
71
104
|
Object.defineProperty(SegmentTreeNode.prototype, "right", {
|
|
72
105
|
get: function () {
|
|
73
106
|
return this._right;
|
|
@@ -78,10 +111,25 @@ var SegmentTreeNode = /** @class */ (function () {
|
|
|
78
111
|
enumerable: false,
|
|
79
112
|
configurable: true
|
|
80
113
|
});
|
|
114
|
+
/**
|
|
115
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
116
|
+
*/
|
|
117
|
+
SegmentTreeNode.prototype.getRight = function () {
|
|
118
|
+
return this._right;
|
|
119
|
+
};
|
|
81
120
|
return SegmentTreeNode;
|
|
82
121
|
}());
|
|
83
122
|
exports.SegmentTreeNode = SegmentTreeNode;
|
|
84
123
|
var SegmentTree = /** @class */ (function () {
|
|
124
|
+
/**
|
|
125
|
+
* The constructor initializes the values, start, end, and root properties of an object.
|
|
126
|
+
* @param {number[]} values - An array of numbers that will be used to build a binary search tree.
|
|
127
|
+
* @param {number} [start] - The `start` parameter is the index of the first element in the `values` array that should
|
|
128
|
+
* be included in the range. If no value is provided for `start`, it defaults to 0, which means the range starts from
|
|
129
|
+
* the beginning of the array.
|
|
130
|
+
* @param {number} [end] - The "end" parameter is the index of the last element in the "values" array that should be
|
|
131
|
+
* included in the range. If not provided, it defaults to the index of the last element in the "values" array.
|
|
132
|
+
*/
|
|
85
133
|
function SegmentTree(values, start, end) {
|
|
86
134
|
this._values = [];
|
|
87
135
|
this._start = 0;
|
|
@@ -96,9 +144,27 @@ var SegmentTree = /** @class */ (function () {
|
|
|
96
144
|
get: function () {
|
|
97
145
|
return this._root;
|
|
98
146
|
},
|
|
147
|
+
set: function (v) {
|
|
148
|
+
this._root = v;
|
|
149
|
+
},
|
|
99
150
|
enumerable: false,
|
|
100
151
|
configurable: true
|
|
101
152
|
});
|
|
153
|
+
/**
|
|
154
|
+
* Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
|
|
155
|
+
*/
|
|
156
|
+
SegmentTree.prototype.getRoot = function () {
|
|
157
|
+
return this._root;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes
|
|
161
|
+
* for each segment.
|
|
162
|
+
* @param {number} start - The `start` parameter represents the starting index of the segment or range for which we are
|
|
163
|
+
* building the segment tree.
|
|
164
|
+
* @param {number} end - The `end` parameter represents the ending index of the segment or range for which we are
|
|
165
|
+
* building the segment tree.
|
|
166
|
+
* @returns a SegmentTreeNode object.
|
|
167
|
+
*/
|
|
102
168
|
SegmentTree.prototype.build = function (start, end) {
|
|
103
169
|
if (start === end) {
|
|
104
170
|
return new SegmentTreeNode(start, end, this._values[start]);
|
|
@@ -111,6 +177,17 @@ var SegmentTree = /** @class */ (function () {
|
|
|
111
177
|
cur.right = right;
|
|
112
178
|
return cur;
|
|
113
179
|
};
|
|
180
|
+
/**
|
|
181
|
+
* The function updates the value of a node in a segment tree and recalculates the sum of its children if they exist.
|
|
182
|
+
* @param {number} index - The index parameter represents the index of the node in the segment tree that needs to be
|
|
183
|
+
* updated.
|
|
184
|
+
* @param {number} sum - The `sum` parameter represents the new value that should be assigned to the `sum` property of
|
|
185
|
+
* the `SegmentTreeNode` at the specified `index`.
|
|
186
|
+
* @param {SegmentTreeNodeVal} [val] - The `val` parameter is an optional value that can be assigned to the `val`
|
|
187
|
+
* property of the `SegmentTreeNode` object. It is not currently used in the code, but you can uncomment the line `//
|
|
188
|
+
* cur.val = val;` and pass a value for `val` in the
|
|
189
|
+
* @returns The function does not return anything.
|
|
190
|
+
*/
|
|
114
191
|
SegmentTree.prototype.updateNode = function (index, sum, val) {
|
|
115
192
|
var root = this.root || null;
|
|
116
193
|
if (!root) {
|
|
@@ -139,6 +216,13 @@ var SegmentTree = /** @class */ (function () {
|
|
|
139
216
|
};
|
|
140
217
|
dfs(root, index, sum);
|
|
141
218
|
};
|
|
219
|
+
/**
|
|
220
|
+
* The function `querySumByRange` calculates the sum of values within a given range in a segment tree.
|
|
221
|
+
* @param {number} indexA - The starting index of the range for which you want to calculate the sum.
|
|
222
|
+
* @param {number} indexB - The parameter `indexB` represents the ending index of the range for which you want to
|
|
223
|
+
* calculate the sum.
|
|
224
|
+
* @returns The function `querySumByRange` returns a number.
|
|
225
|
+
*/
|
|
142
226
|
SegmentTree.prototype.querySumByRange = function (indexA, indexB) {
|
|
143
227
|
var root = this.root || null;
|
|
144
228
|
if (!root) {
|
|
@@ -1,11 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
4
7
|
*/
|
|
5
8
|
import { BST, BSTNode } from './bst';
|
|
6
9
|
import type { BinaryTreeNodeId, TreeMultiSetDeletedResult } from '../types';
|
|
7
10
|
export declare class TreeMultiSet<T> extends BST<T> {
|
|
11
|
+
/**
|
|
12
|
+
* The function creates a new BSTNode with the given id, value, and count.
|
|
13
|
+
* @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
|
|
14
|
+
* distinguish one node from another in the tree.
|
|
15
|
+
* @param {T} val - The `val` parameter represents the value that will be stored in the binary search tree node.
|
|
16
|
+
* @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
|
|
17
|
+
* occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
|
|
18
|
+
* @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
|
|
19
|
+
*/
|
|
8
20
|
createNode(id: BinaryTreeNodeId, val: T, count?: number): BSTNode<T>;
|
|
9
|
-
|
|
21
|
+
/**
|
|
22
|
+
* The function overrides the add method of the BinarySearchTree class in TypeScript.
|
|
23
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
|
|
24
|
+
* @param {T | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
|
|
25
|
+
* can be of type `T` (the generic type) or `null`.
|
|
26
|
+
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
|
|
27
|
+
* of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
|
|
28
|
+
* @returns The `add` method is returning a `BSTNode<T>` object or `null`.
|
|
29
|
+
*/
|
|
30
|
+
add(id: BinaryTreeNodeId, val: T | null, count?: number): BSTNode<T> | null;
|
|
31
|
+
/**
|
|
32
|
+
* The function overrides the remove method of the superclass and returns the result of calling the superclass's remove
|
|
33
|
+
* method.
|
|
34
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
|
|
35
|
+
* removed from the tree.
|
|
36
|
+
* @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean value that
|
|
37
|
+
* determines whether to update the left sum of all nodes in the tree after removing a node. If `isUpdateAllLeftSum` is
|
|
38
|
+
* set to `true`, the left sum of all nodes will be recalculated. If it
|
|
39
|
+
* @returns The method is returning an array of TreeMultiSetDeletedResult objects.
|
|
40
|
+
*/
|
|
10
41
|
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<T>[];
|
|
11
42
|
}
|