data-structure-typed 1.18.5 → 1.18.7
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/abstract-binary-tree.d.ts +357 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +1480 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +8 -6
- package/dist/data-structures/binary-tree/avl-tree.js +7 -5
- package/dist/data-structures/binary-tree/binary-tree.d.ts +19 -337
- package/dist/data-structures/binary-tree/binary-tree.js +40 -1441
- package/dist/data-structures/binary-tree/bst.d.ts +31 -17
- package/dist/data-structures/binary-tree/bst.js +57 -40
- package/dist/data-structures/binary-tree/index.d.ts +1 -0
- package/dist/data-structures/binary-tree/index.js +1 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +30 -1
- package/dist/data-structures/binary-tree/rb-tree.js +29 -20
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +21 -25
- package/dist/data-structures/binary-tree/tree-multiset.js +40 -31
- package/dist/data-structures/graph/abstract-graph.d.ts +20 -21
- package/dist/data-structures/graph/abstract-graph.js +24 -19
- package/dist/data-structures/graph/directed-graph.d.ts +12 -13
- package/dist/data-structures/graph/directed-graph.js +21 -25
- package/dist/data-structures/graph/undirected-graph.d.ts +15 -19
- package/dist/data-structures/graph/undirected-graph.js +16 -29
- package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +101 -0
- package/dist/data-structures/interfaces/abstract-binary-tree.js +2 -0
- package/dist/data-structures/interfaces/abstract-graph.d.ts +1 -4
- package/dist/data-structures/interfaces/avl-tree.d.ts +16 -1
- package/dist/data-structures/interfaces/binary-tree.d.ts +4 -25
- package/dist/data-structures/interfaces/bst.d.ts +18 -1
- package/dist/data-structures/interfaces/directed-graph.d.ts +4 -1
- package/dist/data-structures/interfaces/index.d.ts +1 -1
- package/dist/data-structures/interfaces/index.js +1 -1
- package/dist/data-structures/interfaces/rb-tree.d.ts +9 -0
- package/dist/data-structures/interfaces/rb-tree.js +2 -0
- package/dist/data-structures/interfaces/undirected-graph.d.ts +4 -1
- package/dist/data-structures/types/abstract-binary-tree.d.ts +32 -0
- package/dist/data-structures/types/abstract-binary-tree.js +21 -0
- package/dist/data-structures/types/avl-tree.d.ts +2 -4
- package/dist/data-structures/types/binary-tree.d.ts +2 -10
- package/dist/data-structures/types/bst.d.ts +10 -5
- package/dist/data-structures/types/bst.js +7 -0
- package/dist/data-structures/types/helpers.d.ts +8 -0
- package/dist/data-structures/types/helpers.js +2 -0
- package/dist/data-structures/types/index.d.ts +3 -0
- package/dist/data-structures/types/index.js +3 -0
- package/dist/data-structures/types/rb-tree.d.ts +6 -0
- package/dist/data-structures/types/rb-tree.js +8 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -3
- package/dist/utils/utils.js +62 -0
- package/docs/assets/search.js +1 -1
- package/docs/classes/AVLTree.html +316 -204
- package/docs/classes/AVLTreeNode.html +141 -81
- package/docs/classes/AaTree.html +27 -10
- package/docs/classes/AbstractBinaryTree.html +2118 -0
- package/docs/classes/AbstractBinaryTreeNode.html +524 -0
- package/docs/classes/AbstractEdge.html +37 -20
- package/docs/classes/AbstractGraph.html +152 -144
- package/docs/classes/AbstractVertex.html +34 -17
- package/docs/classes/ArrayDeque.html +40 -23
- package/docs/classes/BST.html +294 -187
- package/docs/classes/BSTNode.html +144 -82
- package/docs/classes/BTree.html +27 -10
- package/docs/classes/BinaryIndexedTree.html +35 -18
- package/docs/classes/BinaryTree.html +597 -500
- package/docs/classes/BinaryTreeNode.html +189 -168
- package/docs/classes/Character.html +30 -13
- package/docs/classes/CoordinateMap.html +35 -18
- package/docs/classes/CoordinateSet.html +34 -17
- package/docs/classes/Deque.html +60 -43
- package/docs/classes/DirectedEdge.html +41 -24
- package/docs/classes/DirectedGraph.html +208 -247
- package/docs/classes/DirectedVertex.html +32 -15
- package/docs/classes/DoublyLinkedList.html +63 -46
- package/docs/classes/DoublyLinkedListNode.html +37 -20
- package/docs/classes/HashTable.html +27 -10
- package/docs/classes/Heap.html +41 -24
- package/docs/classes/HeapItem.html +34 -17
- package/docs/classes/Matrix2D.html +42 -25
- package/docs/classes/MatrixNTI2D.html +30 -13
- package/docs/classes/MaxHeap.html +41 -24
- package/docs/classes/MaxPriorityQueue.html +60 -43
- package/docs/classes/MinHeap.html +41 -24
- package/docs/classes/MinPriorityQueue.html +60 -43
- package/docs/classes/Navigator.html +36 -19
- package/docs/classes/ObjectDeque.html +51 -34
- package/docs/classes/Pair.html +27 -10
- package/docs/classes/PriorityQueue.html +58 -41
- package/docs/classes/Queue.html +40 -23
- package/docs/classes/RBTree.html +2388 -0
- package/docs/classes/RBTreeNode.html +516 -0
- package/docs/classes/SegmentTree.html +43 -26
- package/docs/classes/SegmentTreeNode.html +46 -29
- package/docs/classes/SinglyLinkedList.html +60 -43
- package/docs/classes/SinglyLinkedListNode.html +34 -17
- package/docs/classes/SkipLinkedList.html +27 -10
- package/docs/classes/SplayTree.html +27 -10
- package/docs/classes/Stack.html +38 -21
- package/docs/classes/TreeMap.html +27 -10
- package/docs/classes/TreeMultiSet.html +332 -224
- package/docs/classes/TreeMultiSetNode.html +499 -0
- package/docs/classes/TreeNode.html +42 -25
- package/docs/classes/TreeSet.html +27 -10
- package/docs/classes/Trie.html +39 -22
- package/docs/classes/TrieNode.html +37 -20
- package/docs/classes/TwoThreeTree.html +27 -10
- package/docs/classes/UndirectedEdge.html +38 -21
- package/docs/classes/UndirectedGraph.html +179 -227
- package/docs/classes/UndirectedVertex.html +32 -15
- package/docs/classes/Vector2D.html +54 -37
- package/docs/enums/CP.html +33 -16
- package/docs/enums/FamilyPosition.html +45 -28
- package/docs/enums/LoopType.html +39 -22
- package/docs/{interfaces/IBinaryTree.html → enums/RBColor.html} +51 -54
- package/docs/enums/TopologicalProperty.html +30 -13
- package/docs/index.html +26 -9
- package/docs/interfaces/IAVLTree.html +1378 -0
- package/docs/interfaces/IAVLTreeNode.html +405 -0
- package/docs/interfaces/IAbstractBinaryTree.html +1124 -0
- package/docs/interfaces/{IBinaryTreeNode.html → IAbstractBinaryTreeNode.html} +76 -75
- package/docs/interfaces/{IGraph.html → IAbstractGraph.html} +67 -94
- package/docs/interfaces/IBST.html +1271 -0
- package/docs/interfaces/IBSTNode.html +408 -0
- package/docs/interfaces/IDirectedGraph.html +344 -20
- package/docs/interfaces/IUNDirectedGraph.html +337 -12
- package/docs/modules.html +52 -18
- package/docs/types/{AVLTreeDeleted.html → AVLTreeOptions.html} +32 -24
- package/docs/types/{ResultsByProperty.html → AbstractBinaryTreeNodeProperties.html} +32 -15
- package/docs/types/AbstractBinaryTreeNodeProperty.html +152 -0
- package/docs/types/AbstractBinaryTreeOptions.html +156 -0
- package/docs/types/AbstractRecursiveBinaryTreeNode.html +152 -0
- package/docs/types/BSTComparator.html +27 -10
- package/docs/types/{TreeMultiSetDeletedResult.html → BSTOptions.html} +32 -22
- package/docs/types/BinaryTreeDeletedResult.html +159 -0
- package/docs/types/BinaryTreeNodeId.html +27 -10
- package/docs/types/BinaryTreeNodePropertyName.html +27 -10
- package/docs/types/{BinaryTreeDeleted.html → BinaryTreeOptions.html} +32 -24
- package/docs/types/DFSOrderPattern.html +27 -10
- package/docs/types/DijkstraResult.html +27 -10
- package/docs/types/Direction.html +27 -10
- package/docs/types/EdgeId.html +27 -10
- package/docs/types/HeapOptions.html +27 -10
- package/docs/types/IdObject.html +157 -0
- package/docs/types/{ResultByProperty.html → KeyValObject.html} +36 -19
- package/docs/types/NavigatorParams.html +27 -10
- package/docs/types/NodeOrPropertyName.html +27 -10
- package/docs/types/PriorityQueueComparator.html +27 -10
- package/docs/types/PriorityQueueDFSOrderPattern.html +27 -10
- package/docs/types/PriorityQueueOptions.html +27 -10
- package/docs/types/{BSTDeletedResult.html → RBTreeOptions.html} +32 -24
- package/docs/types/RecursiveAVLTreeNode.html +27 -10
- package/docs/types/RecursiveBSTNode.html +27 -10
- package/docs/types/RecursiveBinaryTreeNode.html +27 -10
- package/docs/types/RecursiveTreeMultiSetNode.html +152 -0
- package/docs/types/SegmentTreeNodeVal.html +27 -10
- package/docs/types/TopologicalStatus.html +27 -10
- package/docs/types/TreeMultiSetOptions.html +152 -0
- package/docs/types/Turning.html +27 -10
- package/docs/types/VertexId.html +27 -10
- package/package.json +2 -2
|
@@ -5,26 +5,40 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator,
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
8
|
+
import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, RecursiveBSTNode } from '../types';
|
|
9
|
+
import { BinaryTreeDeletedResult, BSTOptions, CP } from '../types';
|
|
10
|
+
import { BinaryTree, BinaryTreeNode } from './binary-tree';
|
|
11
|
+
import { IBST, IBSTNode } from '../interfaces';
|
|
12
|
+
export declare class BSTNode<T, FAMILY extends BSTNode<T, FAMILY> = RecursiveBSTNode<T>> extends BinaryTreeNode<T, FAMILY> implements IBSTNode<T, FAMILY> {
|
|
13
|
+
/**
|
|
14
|
+
* The function creates a new binary search tree node with the specified id, value, and count.
|
|
15
|
+
* @param {BinaryTreeNodeId} id - The id parameter is the identifier for the binary tree node. It is used to uniquely
|
|
16
|
+
* identify each node in the tree.
|
|
17
|
+
* @param {T} [val] - The "val" parameter represents the value that will be stored in the binary tree node. It is an
|
|
18
|
+
* optional parameter, meaning it can be omitted when calling the "createNode" function.
|
|
19
|
+
* @param {number} [count] - The `count` parameter represents the number of occurrences of the value in the binary
|
|
20
|
+
* search tree node. It is an optional parameter, so it can be omitted when calling the `createNode` method.
|
|
21
|
+
* @returns The method is returning a new instance of the BSTNode class, casted as the FAMILY type.
|
|
22
|
+
*/
|
|
23
|
+
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
17
24
|
}
|
|
18
|
-
export declare class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BinaryTree<N> implements
|
|
25
|
+
export declare class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BinaryTree<N> implements IBST<N> {
|
|
19
26
|
/**
|
|
20
27
|
* The constructor function accepts an optional options object and sets the comparator property if provided.
|
|
21
28
|
* @param [options] - An optional object that can contain the following properties:
|
|
22
29
|
*/
|
|
23
|
-
constructor(options?:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
constructor(options?: BSTOptions);
|
|
31
|
+
/**
|
|
32
|
+
* The function creates a new binary search tree node with the given id, value, and count.
|
|
33
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
|
|
34
|
+
* `BinaryTreeNodeId`.
|
|
35
|
+
* @param {N['val'] | null} [val] - The `val` parameter is the value that will be stored in the node. It can be of any
|
|
36
|
+
* type `N['val']` or `null`.
|
|
37
|
+
* @param {number} [count] - The `count` parameter is an optional parameter that represents the number of occurrences
|
|
38
|
+
* of a particular value in the binary search tree node.
|
|
39
|
+
* @returns a new instance of the BSTNode class, casted as type N.
|
|
40
|
+
*/
|
|
41
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
28
42
|
/**
|
|
29
43
|
* The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
|
|
30
44
|
* the ID matches, and returns the inserted node.
|
|
@@ -56,7 +70,7 @@ export declare class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> exten
|
|
|
56
70
|
* greater than, it returns the ID of the leftmost node. Otherwise, it also returns the ID of the rightmost node. If
|
|
57
71
|
* there are no nodes in
|
|
58
72
|
*/
|
|
59
|
-
lastKey():
|
|
73
|
+
lastKey(): BinaryTreeNodeId;
|
|
60
74
|
/**
|
|
61
75
|
* The `remove` function in this TypeScript code removes a node from a binary search tree and returns information about
|
|
62
76
|
* the deleted node and any nodes that need to be balanced.
|
|
@@ -67,7 +81,7 @@ export declare class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> exten
|
|
|
67
81
|
* set to false or not provided, the count of the node will be taken into account and the
|
|
68
82
|
* @returns an array of `BSTDeletedResult<N>` objects.
|
|
69
83
|
*/
|
|
70
|
-
remove(id: BinaryTreeNodeId, ignoreCount?: boolean):
|
|
84
|
+
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
71
85
|
/**
|
|
72
86
|
* The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
|
|
73
87
|
* option to specify the property name and whether to return only one node.
|
|
@@ -31,19 +31,27 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
31
31
|
return ar;
|
|
32
32
|
};
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.BST = exports.BSTNode =
|
|
34
|
+
exports.BST = exports.BSTNode = void 0;
|
|
35
|
+
var types_1 = require("../types");
|
|
35
36
|
var binary_tree_1 = require("./binary-tree");
|
|
36
|
-
var CP;
|
|
37
|
-
(function (CP) {
|
|
38
|
-
CP[CP["lt"] = -1] = "lt";
|
|
39
|
-
CP[CP["eq"] = 0] = "eq";
|
|
40
|
-
CP[CP["gt"] = 1] = "gt";
|
|
41
|
-
})(CP || (exports.CP = CP = {}));
|
|
42
37
|
var BSTNode = /** @class */ (function (_super) {
|
|
43
38
|
__extends(BSTNode, _super);
|
|
44
39
|
function BSTNode() {
|
|
45
40
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
46
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* The function creates a new binary search tree node with the specified id, value, and count.
|
|
44
|
+
* @param {BinaryTreeNodeId} id - The id parameter is the identifier for the binary tree node. It is used to uniquely
|
|
45
|
+
* identify each node in the tree.
|
|
46
|
+
* @param {T} [val] - The "val" parameter represents the value that will be stored in the binary tree node. It is an
|
|
47
|
+
* optional parameter, meaning it can be omitted when calling the "createNode" function.
|
|
48
|
+
* @param {number} [count] - The `count` parameter represents the number of occurrences of the value in the binary
|
|
49
|
+
* search tree node. It is an optional parameter, so it can be omitted when calling the `createNode` method.
|
|
50
|
+
* @returns The method is returning a new instance of the BSTNode class, casted as the FAMILY type.
|
|
51
|
+
*/
|
|
52
|
+
BSTNode.prototype.createNode = function (id, val, count) {
|
|
53
|
+
return new BSTNode(id, (val === undefined ? id : val), count);
|
|
54
|
+
};
|
|
47
55
|
return BSTNode;
|
|
48
56
|
}(binary_tree_1.BinaryTreeNode));
|
|
49
57
|
exports.BSTNode = BSTNode;
|
|
@@ -64,9 +72,18 @@ var BST = /** @class */ (function (_super) {
|
|
|
64
72
|
}
|
|
65
73
|
return _this;
|
|
66
74
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
/**
|
|
76
|
+
* The function creates a new binary search tree node with the given id, value, and count.
|
|
77
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
|
|
78
|
+
* `BinaryTreeNodeId`.
|
|
79
|
+
* @param {N['val'] | null} [val] - The `val` parameter is the value that will be stored in the node. It can be of any
|
|
80
|
+
* type `N['val']` or `null`.
|
|
81
|
+
* @param {number} [count] - The `count` parameter is an optional parameter that represents the number of occurrences
|
|
82
|
+
* of a particular value in the binary search tree node.
|
|
83
|
+
* @returns a new instance of the BSTNode class, casted as type N.
|
|
84
|
+
*/
|
|
85
|
+
BST.prototype.createNode = function (id, val, count) {
|
|
86
|
+
return new BSTNode(id, val === undefined ? id : val, count);
|
|
70
87
|
};
|
|
71
88
|
/**
|
|
72
89
|
* The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
|
|
@@ -83,7 +100,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
83
100
|
BST.prototype.add = function (id, val, count) {
|
|
84
101
|
if (count === void 0) { count = 1; }
|
|
85
102
|
var inserted = null;
|
|
86
|
-
var newNode = this.
|
|
103
|
+
var newNode = this.createNode(id, val, count);
|
|
87
104
|
if (this.root === null) {
|
|
88
105
|
this._setRoot(newNode);
|
|
89
106
|
this._setSize(this.size + 1);
|
|
@@ -95,7 +112,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
95
112
|
var traversing = true;
|
|
96
113
|
while (traversing) {
|
|
97
114
|
if (cur !== null && newNode !== null) {
|
|
98
|
-
if (this._compare(cur.id, id) === CP.eq) {
|
|
115
|
+
if (this._compare(cur.id, id) === types_1.CP.eq) {
|
|
99
116
|
if (newNode) {
|
|
100
117
|
cur.count += newNode.count;
|
|
101
118
|
this._setCount(this.count + newNode.count);
|
|
@@ -105,12 +122,12 @@ var BST = /** @class */ (function (_super) {
|
|
|
105
122
|
traversing = false;
|
|
106
123
|
inserted = cur;
|
|
107
124
|
}
|
|
108
|
-
else if (this._compare(cur.id, id) === CP.gt) {
|
|
125
|
+
else if (this._compare(cur.id, id) === types_1.CP.gt) {
|
|
109
126
|
// Traverse left of the node
|
|
110
127
|
if (cur.left === undefined) {
|
|
111
128
|
if (newNode) {
|
|
112
129
|
newNode.parent = cur;
|
|
113
|
-
newNode.familyPosition =
|
|
130
|
+
newNode.familyPosition = types_1.FamilyPosition.LEFT;
|
|
114
131
|
}
|
|
115
132
|
//Add to the left of the current node
|
|
116
133
|
cur.left = newNode;
|
|
@@ -125,12 +142,12 @@ var BST = /** @class */ (function (_super) {
|
|
|
125
142
|
cur = cur.left;
|
|
126
143
|
}
|
|
127
144
|
}
|
|
128
|
-
else if (this._compare(cur.id, id) === CP.lt) {
|
|
145
|
+
else if (this._compare(cur.id, id) === types_1.CP.lt) {
|
|
129
146
|
// Traverse right of the node
|
|
130
147
|
if (cur.right === undefined) {
|
|
131
148
|
if (newNode) {
|
|
132
149
|
newNode.parent = cur;
|
|
133
|
-
newNode.familyPosition =
|
|
150
|
+
newNode.familyPosition = types_1.FamilyPosition.RIGHT;
|
|
134
151
|
}
|
|
135
152
|
//Add to the right of the current node
|
|
136
153
|
cur.right = newNode;
|
|
@@ -177,9 +194,9 @@ var BST = /** @class */ (function (_super) {
|
|
|
177
194
|
*/
|
|
178
195
|
BST.prototype.lastKey = function () {
|
|
179
196
|
var _a, _b, _c, _d, _e, _f;
|
|
180
|
-
if (this._compare(0, 1) === CP.lt)
|
|
197
|
+
if (this._compare(0, 1) === types_1.CP.lt)
|
|
181
198
|
return (_b = (_a = this.getRightMost()) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : 0;
|
|
182
|
-
else if (this._compare(0, 1) === CP.gt)
|
|
199
|
+
else if (this._compare(0, 1) === types_1.CP.gt)
|
|
183
200
|
return (_d = (_c = this.getLeftMost()) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : 0;
|
|
184
201
|
else
|
|
185
202
|
return (_f = (_e = this.getRightMost()) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : 0;
|
|
@@ -215,10 +232,10 @@ var BST = /** @class */ (function (_super) {
|
|
|
215
232
|
}
|
|
216
233
|
else {
|
|
217
234
|
switch (curr.familyPosition) {
|
|
218
|
-
case
|
|
235
|
+
case types_1.FamilyPosition.LEFT:
|
|
219
236
|
parent.left = curr.right;
|
|
220
237
|
break;
|
|
221
|
-
case
|
|
238
|
+
case types_1.FamilyPosition.RIGHT:
|
|
222
239
|
parent.right = curr.right;
|
|
223
240
|
break;
|
|
224
241
|
}
|
|
@@ -264,16 +281,16 @@ var BST = /** @class */ (function (_super) {
|
|
|
264
281
|
if (!this.root)
|
|
265
282
|
return [];
|
|
266
283
|
var result = [];
|
|
267
|
-
if (this.loopType ===
|
|
284
|
+
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
268
285
|
var _traverse_1 = function (cur) {
|
|
269
286
|
if (_this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
|
|
270
287
|
return;
|
|
271
288
|
if (!cur.left && !cur.right)
|
|
272
289
|
return;
|
|
273
290
|
if (propertyName === 'id') {
|
|
274
|
-
if (_this._compare(cur.id, nodeProperty) === CP.gt)
|
|
291
|
+
if (_this._compare(cur.id, nodeProperty) === types_1.CP.gt)
|
|
275
292
|
cur.left && _traverse_1(cur.left);
|
|
276
|
-
if (_this._compare(cur.id, nodeProperty) === CP.lt)
|
|
293
|
+
if (_this._compare(cur.id, nodeProperty) === types_1.CP.lt)
|
|
277
294
|
cur.right && _traverse_1(cur.right);
|
|
278
295
|
}
|
|
279
296
|
else {
|
|
@@ -291,9 +308,9 @@ var BST = /** @class */ (function (_super) {
|
|
|
291
308
|
if (this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
|
|
292
309
|
return result;
|
|
293
310
|
if (propertyName === 'id') {
|
|
294
|
-
if (this._compare(cur.id, nodeProperty) === CP.gt)
|
|
311
|
+
if (this._compare(cur.id, nodeProperty) === types_1.CP.gt)
|
|
295
312
|
cur.left && queue.push(cur.left);
|
|
296
|
-
if (this._compare(cur.id, nodeProperty) === CP.lt)
|
|
313
|
+
if (this._compare(cur.id, nodeProperty) === types_1.CP.lt)
|
|
297
314
|
cur.right && queue.push(cur.right);
|
|
298
315
|
}
|
|
299
316
|
else {
|
|
@@ -337,15 +354,15 @@ var BST = /** @class */ (function (_super) {
|
|
|
337
354
|
return needSum;
|
|
338
355
|
};
|
|
339
356
|
var sum = 0;
|
|
340
|
-
if (this.loopType ===
|
|
357
|
+
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
341
358
|
var _traverse_2 = function (cur) {
|
|
342
359
|
var compared = _this._compare(cur.id, id);
|
|
343
|
-
if (compared === CP.eq) {
|
|
360
|
+
if (compared === types_1.CP.eq) {
|
|
344
361
|
if (cur.right)
|
|
345
362
|
sum += _this.subTreeSum(cur.right, propertyName);
|
|
346
363
|
return;
|
|
347
364
|
}
|
|
348
|
-
else if (compared === CP.lt) {
|
|
365
|
+
else if (compared === types_1.CP.lt) {
|
|
349
366
|
if (cur.left)
|
|
350
367
|
sum += _this.subTreeSum(cur.left, propertyName);
|
|
351
368
|
sum += getSumByPropertyName(cur);
|
|
@@ -369,12 +386,12 @@ var BST = /** @class */ (function (_super) {
|
|
|
369
386
|
var cur = queue.shift();
|
|
370
387
|
if (cur) {
|
|
371
388
|
var compared = this._compare(cur.id, id);
|
|
372
|
-
if (compared === CP.eq) {
|
|
389
|
+
if (compared === types_1.CP.eq) {
|
|
373
390
|
if (cur.right)
|
|
374
391
|
sum += this.subTreeSum(cur.right, propertyName);
|
|
375
392
|
return sum;
|
|
376
393
|
}
|
|
377
|
-
else if (compared === CP.lt) { // todo maybe a bug
|
|
394
|
+
else if (compared === types_1.CP.lt) { // todo maybe a bug
|
|
378
395
|
if (cur.left)
|
|
379
396
|
sum += this.subTreeSum(cur.left, propertyName);
|
|
380
397
|
sum += getSumByPropertyName(cur);
|
|
@@ -424,15 +441,15 @@ var BST = /** @class */ (function (_super) {
|
|
|
424
441
|
break;
|
|
425
442
|
}
|
|
426
443
|
};
|
|
427
|
-
if (this.loopType ===
|
|
444
|
+
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
428
445
|
var _traverse_3 = function (cur) {
|
|
429
446
|
var compared = _this._compare(cur.id, node.id);
|
|
430
447
|
_sumByPropertyName(cur);
|
|
431
448
|
if (!cur.left && !cur.right)
|
|
432
449
|
return;
|
|
433
|
-
if (cur.left && compared === CP.gt)
|
|
450
|
+
if (cur.left && compared === types_1.CP.gt)
|
|
434
451
|
_traverse_3(cur.left);
|
|
435
|
-
else if (cur.right && compared === CP.gt)
|
|
452
|
+
else if (cur.right && compared === types_1.CP.gt)
|
|
436
453
|
_traverse_3(cur.right);
|
|
437
454
|
};
|
|
438
455
|
_traverse_3(this.root);
|
|
@@ -445,9 +462,9 @@ var BST = /** @class */ (function (_super) {
|
|
|
445
462
|
if (cur) {
|
|
446
463
|
var compared = this._compare(cur.id, node.id);
|
|
447
464
|
_sumByPropertyName(cur);
|
|
448
|
-
if (cur.left && compared === CP.gt)
|
|
465
|
+
if (cur.left && compared === types_1.CP.gt)
|
|
449
466
|
queue.push(cur.left);
|
|
450
|
-
else if (cur.right && compared === CP.gt)
|
|
467
|
+
else if (cur.right && compared === types_1.CP.gt)
|
|
451
468
|
queue.push(cur.right);
|
|
452
469
|
}
|
|
453
470
|
}
|
|
@@ -465,7 +482,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
465
482
|
this.clear();
|
|
466
483
|
if (sorted.length < 1)
|
|
467
484
|
return false;
|
|
468
|
-
if (this.loopType ===
|
|
485
|
+
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
469
486
|
var buildBalanceBST_1 = function (l, r) {
|
|
470
487
|
if (l > r)
|
|
471
488
|
return;
|
|
@@ -506,7 +523,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
506
523
|
if (!this.root)
|
|
507
524
|
return true;
|
|
508
525
|
var balanced = true;
|
|
509
|
-
if (this.loopType ===
|
|
526
|
+
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
510
527
|
var _height_1 = function (cur) {
|
|
511
528
|
if (!cur)
|
|
512
529
|
return 0;
|
|
@@ -558,11 +575,11 @@ var BST = /** @class */ (function (_super) {
|
|
|
558
575
|
BST.prototype._compare = function (a, b) {
|
|
559
576
|
var compared = this._comparator(a, b);
|
|
560
577
|
if (compared > 0)
|
|
561
|
-
return CP.gt;
|
|
578
|
+
return types_1.CP.gt;
|
|
562
579
|
else if (compared < 0)
|
|
563
|
-
return CP.lt;
|
|
580
|
+
return types_1.CP.lt;
|
|
564
581
|
else
|
|
565
|
-
return CP.eq;
|
|
582
|
+
return types_1.CP.eq;
|
|
566
583
|
};
|
|
567
584
|
return BST;
|
|
568
585
|
}(binary_tree_1.BinaryTree));
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./abstract-binary-tree"), exports);
|
|
17
18
|
__exportStar(require("./binary-tree"), exports);
|
|
18
19
|
__exportStar(require("./bst"), exports);
|
|
19
20
|
__exportStar(require("./binary-indexed-tree"), exports);
|
|
@@ -1 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
import { BinaryTreeNodeId, RBColor, RBTreeOptions } from '../types';
|
|
2
|
+
import { IRBTree, IRBTreeNode } from '../interfaces/rb-tree';
|
|
3
|
+
import { BST, BSTNode } from './bst';
|
|
4
|
+
export declare class RBTreeNode<T, FAMILY extends RBTreeNode<T, FAMILY>> extends BSTNode<T, FAMILY> implements IRBTreeNode<T, FAMILY> {
|
|
5
|
+
constructor(id: number, val: T, count?: number);
|
|
6
|
+
private _color;
|
|
7
|
+
get color(): RBColor;
|
|
8
|
+
set color(value: RBColor);
|
|
9
|
+
/**
|
|
10
|
+
* The function creates a new RBTreeNode with the given id, value, and count and returns it as a FAMILY object.
|
|
11
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
|
|
12
|
+
* identify each node in the tree.
|
|
13
|
+
* @param {T | null} [val] - The "val" parameter represents the value to be stored in the node. It can be of type T
|
|
14
|
+
* (generic type) or null.
|
|
15
|
+
* @param {number} [count] - The `count` parameter represents the number of occurrences of the value in the binary tree
|
|
16
|
+
* node.
|
|
17
|
+
* @returns The method is returning a new instance of the RBTreeNode class, casted as a FAMILY type.
|
|
18
|
+
*/
|
|
19
|
+
createNode(id: BinaryTreeNodeId, val?: T | null, count?: number): FAMILY;
|
|
20
|
+
}
|
|
21
|
+
export declare class RBTree<N extends RBTreeNode<N['val'], N>> extends BST<N> implements IRBTree<N> {
|
|
22
|
+
constructor(options?: RBTreeOptions);
|
|
23
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
24
|
+
insert(id: number, val: N | null): void;
|
|
25
|
+
private leftRotate;
|
|
26
|
+
private rightRotate;
|
|
27
|
+
private insertFixup;
|
|
28
|
+
private deleteFixup;
|
|
29
|
+
private transplant;
|
|
30
|
+
}
|
|
@@ -15,23 +15,17 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var RBNode = /** @class */ (function (_super) {
|
|
25
|
-
__extends(RBNode, _super);
|
|
26
|
-
// override createNode(id: BinaryTreeNodeId, val: T | null, count?: number): RBNode<T> | null {
|
|
27
|
-
// return val !== null ? new RBNode<T>(id, val, count) : null;
|
|
28
|
-
// }
|
|
29
|
-
function RBNode(id, val, count) {
|
|
18
|
+
exports.RBTree = exports.RBTreeNode = void 0;
|
|
19
|
+
var types_1 = require("../types");
|
|
20
|
+
var bst_1 = require("./bst");
|
|
21
|
+
var RBTreeNode = /** @class */ (function (_super) {
|
|
22
|
+
__extends(RBTreeNode, _super);
|
|
23
|
+
function RBTreeNode(id, val, count) {
|
|
30
24
|
var _this = _super.call(this, id, val, count) || this;
|
|
31
|
-
_this._color = RBColor.
|
|
25
|
+
_this._color = types_1.RBColor.RED;
|
|
32
26
|
return _this;
|
|
33
27
|
}
|
|
34
|
-
Object.defineProperty(
|
|
28
|
+
Object.defineProperty(RBTreeNode.prototype, "color", {
|
|
35
29
|
get: function () {
|
|
36
30
|
return this._color;
|
|
37
31
|
},
|
|
@@ -41,16 +35,30 @@ var RBNode = /** @class */ (function (_super) {
|
|
|
41
35
|
enumerable: false,
|
|
42
36
|
configurable: true
|
|
43
37
|
});
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
/**
|
|
39
|
+
* The function creates a new RBTreeNode with the given id, value, and count and returns it as a FAMILY object.
|
|
40
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
|
|
41
|
+
* identify each node in the tree.
|
|
42
|
+
* @param {T | null} [val] - The "val" parameter represents the value to be stored in the node. It can be of type T
|
|
43
|
+
* (generic type) or null.
|
|
44
|
+
* @param {number} [count] - The `count` parameter represents the number of occurrences of the value in the binary tree
|
|
45
|
+
* node.
|
|
46
|
+
* @returns The method is returning a new instance of the RBTreeNode class, casted as a FAMILY type.
|
|
47
|
+
*/
|
|
48
|
+
RBTreeNode.prototype.createNode = function (id, val, count) {
|
|
49
|
+
return new RBTreeNode(id, val, count);
|
|
50
|
+
};
|
|
51
|
+
return RBTreeNode;
|
|
52
|
+
}(bst_1.BSTNode));
|
|
53
|
+
exports.RBTreeNode = RBTreeNode;
|
|
46
54
|
var RBTree = /** @class */ (function (_super) {
|
|
47
55
|
__extends(RBTree, _super);
|
|
48
56
|
function RBTree(options) {
|
|
49
57
|
return _super.call(this, options) || this;
|
|
50
58
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
RBTree.prototype.createNode = function (id, val, count) {
|
|
60
|
+
return new RBTreeNode(id, val, count);
|
|
61
|
+
};
|
|
54
62
|
// private override _root: BinaryTreeNode<N> | null = null;
|
|
55
63
|
//
|
|
56
64
|
// override get root(): BinaryTreeNode<N> | null {
|
|
@@ -69,4 +77,5 @@ var RBTree = /** @class */ (function (_super) {
|
|
|
69
77
|
RBTree.prototype.transplant = function (u, v) {
|
|
70
78
|
};
|
|
71
79
|
return RBTree;
|
|
72
|
-
}(
|
|
80
|
+
}(bst_1.BST));
|
|
81
|
+
exports.RBTree = RBTree;
|
|
@@ -6,9 +6,26 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
|
-
import type { BinaryTreeNodeId,
|
|
10
|
-
import {
|
|
11
|
-
export declare class
|
|
9
|
+
import type { BinaryTreeNodeId, RecursiveTreeMultiSetNode, TreeMultiSetOptions } from '../types';
|
|
10
|
+
import { IBST, IBSTNode } from '../interfaces';
|
|
11
|
+
export declare class TreeMultiSetNode<T, FAMILY extends TreeMultiSetNode<T, FAMILY> = RecursiveTreeMultiSetNode<T>> extends BSTNode<T, FAMILY> implements IBSTNode<T, FAMILY> {
|
|
12
|
+
/**
|
|
13
|
+
* The function creates a new node in a binary tree with an optional value and count.
|
|
14
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
|
|
15
|
+
* identify each node in the tree.
|
|
16
|
+
* @param {T} [val] - The `val` parameter represents the value to be stored in the node. It is an optional parameter,
|
|
17
|
+
* meaning it can be omitted when calling the `createNode` method.
|
|
18
|
+
* @param {number} [count] - The `count` parameter represents the number of occurrences of the value in the binary tree
|
|
19
|
+
* node. It is an optional parameter, so it can be omitted when calling the `createNode` method.
|
|
20
|
+
* @returns The method is returning a new instance of the TreeMultiSetNode class, casted as the FAMILY type.
|
|
21
|
+
*/
|
|
22
|
+
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The only distinction between a TreeMultiSet and a BST lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
26
|
+
*/
|
|
27
|
+
export declare class TreeMultiSet<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BST<N> implements IBST<N> {
|
|
28
|
+
constructor(options?: TreeMultiSetOptions);
|
|
12
29
|
/**
|
|
13
30
|
* The function creates a new BSTNode with the given id, value, and count.
|
|
14
31
|
* @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
|
|
@@ -18,26 +35,5 @@ export declare class TreeMultiSet<N extends BSTNode<N['val'], N> = BSTNode<numbe
|
|
|
18
35
|
* occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
|
|
19
36
|
* @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
|
|
20
37
|
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The function overrides the add method of the BinarySearchTree class in TypeScript.
|
|
24
|
-
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
|
|
25
|
-
* @param {N | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
|
|
26
|
-
* can be of type `N` (the generic type) or `null`.
|
|
27
|
-
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
|
|
28
|
-
* of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
|
|
29
|
-
* @returns The `add` method is returning a `BSTNode<N>` object or `null`.
|
|
30
|
-
*/
|
|
31
|
-
add(id: BinaryTreeNodeId, val: N | null, count?: number): N | null;
|
|
32
|
-
/**
|
|
33
|
-
* The function overrides the remove method of the superclass and returns the result of calling the superclass's remove
|
|
34
|
-
* method.
|
|
35
|
-
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
|
|
36
|
-
* removed from the tree.
|
|
37
|
-
* @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean value that
|
|
38
|
-
* determines whether to update the left sum of all nodes in the tree after removing a node. If `isUpdateAllLeftSum` is
|
|
39
|
-
* set to `true`, the left sum of all nodes will be recalculated. If it
|
|
40
|
-
* @returns The method is returning an array of TreeMultiSetDeletedResult objects.
|
|
41
|
-
*/
|
|
42
|
-
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): TreeMultiSetDeletedResult<N>[];
|
|
38
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
43
39
|
}
|
|
@@ -14,8 +14,19 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
17
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.TreeMultiSet = void 0;
|
|
29
|
+
exports.TreeMultiSet = exports.TreeMultiSetNode = void 0;
|
|
19
30
|
/**
|
|
20
31
|
* data-structure-typed
|
|
21
32
|
*
|
|
@@ -24,10 +35,34 @@ exports.TreeMultiSet = void 0;
|
|
|
24
35
|
* @license MIT License
|
|
25
36
|
*/
|
|
26
37
|
var bst_1 = require("./bst");
|
|
38
|
+
var TreeMultiSetNode = /** @class */ (function (_super) {
|
|
39
|
+
__extends(TreeMultiSetNode, _super);
|
|
40
|
+
function TreeMultiSetNode() {
|
|
41
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The function creates a new node in a binary tree with an optional value and count.
|
|
45
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
|
|
46
|
+
* identify each node in the tree.
|
|
47
|
+
* @param {T} [val] - The `val` parameter represents the value to be stored in the node. It is an optional parameter,
|
|
48
|
+
* meaning it can be omitted when calling the `createNode` method.
|
|
49
|
+
* @param {number} [count] - The `count` parameter represents the number of occurrences of the value in the binary tree
|
|
50
|
+
* node. It is an optional parameter, so it can be omitted when calling the `createNode` method.
|
|
51
|
+
* @returns The method is returning a new instance of the TreeMultiSetNode class, casted as the FAMILY type.
|
|
52
|
+
*/
|
|
53
|
+
TreeMultiSetNode.prototype.createNode = function (id, val, count) {
|
|
54
|
+
return new TreeMultiSetNode(id, (val === undefined ? id : val), count);
|
|
55
|
+
};
|
|
56
|
+
return TreeMultiSetNode;
|
|
57
|
+
}(bst_1.BSTNode));
|
|
58
|
+
exports.TreeMultiSetNode = TreeMultiSetNode;
|
|
59
|
+
/**
|
|
60
|
+
* The only distinction between a TreeMultiSet and a BST lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
61
|
+
*/
|
|
27
62
|
var TreeMultiSet = /** @class */ (function (_super) {
|
|
28
63
|
__extends(TreeMultiSet, _super);
|
|
29
|
-
function TreeMultiSet() {
|
|
30
|
-
return _super
|
|
64
|
+
function TreeMultiSet(options) {
|
|
65
|
+
return _super.call(this, __assign(__assign({}, options), { isDuplicatedVal: true })) || this;
|
|
31
66
|
}
|
|
32
67
|
/**
|
|
33
68
|
* The function creates a new BSTNode with the given id, value, and count.
|
|
@@ -38,34 +73,8 @@ var TreeMultiSet = /** @class */ (function (_super) {
|
|
|
38
73
|
* occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
|
|
39
74
|
* @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
|
|
40
75
|
*/
|
|
41
|
-
TreeMultiSet.prototype.
|
|
42
|
-
|
|
43
|
-
return node;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* The function overrides the add method of the BinarySearchTree class in TypeScript.
|
|
47
|
-
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
|
|
48
|
-
* @param {N | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
|
|
49
|
-
* can be of type `N` (the generic type) or `null`.
|
|
50
|
-
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
|
|
51
|
-
* of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
|
|
52
|
-
* @returns The `add` method is returning a `BSTNode<N>` object or `null`.
|
|
53
|
-
*/
|
|
54
|
-
TreeMultiSet.prototype.add = function (id, val, count) {
|
|
55
|
-
return _super.prototype.add.call(this, id, val, count);
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* The function overrides the remove method of the superclass and returns the result of calling the superclass's remove
|
|
59
|
-
* method.
|
|
60
|
-
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
|
|
61
|
-
* removed from the tree.
|
|
62
|
-
* @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean value that
|
|
63
|
-
* determines whether to update the left sum of all nodes in the tree after removing a node. If `isUpdateAllLeftSum` is
|
|
64
|
-
* set to `true`, the left sum of all nodes will be recalculated. If it
|
|
65
|
-
* @returns The method is returning an array of TreeMultiSetDeletedResult objects.
|
|
66
|
-
*/
|
|
67
|
-
TreeMultiSet.prototype.remove = function (id, isUpdateAllLeftSum) {
|
|
68
|
-
return _super.prototype.remove.call(this, id, isUpdateAllLeftSum);
|
|
76
|
+
TreeMultiSet.prototype.createNode = function (id, val, count) {
|
|
77
|
+
return new TreeMultiSetNode(id, val === undefined ? id : val, count);
|
|
69
78
|
};
|
|
70
79
|
return TreeMultiSet;
|
|
71
80
|
}(bst_1.BST));
|