data-structure-typed 1.17.4 → 1.18.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/dist/data-structures/binary-tree/avl-tree.js +4 -4
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +10 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +41 -68
- package/dist/data-structures/binary-tree/binary-tree.js +126 -103
- package/dist/data-structures/binary-tree/bst.js +18 -19
- package/dist/data-structures/binary-tree/segment-tree.d.ts +17 -39
- package/dist/data-structures/binary-tree/segment-tree.js +34 -47
- package/dist/data-structures/graph/abstract-graph.d.ts +3 -16
- package/dist/data-structures/graph/abstract-graph.js +3 -24
- package/dist/data-structures/graph/directed-graph.d.ts +3 -11
- package/dist/data-structures/graph/directed-graph.js +2 -14
- package/dist/data-structures/graph/undirected-graph.d.ts +1 -5
- package/dist/data-structures/graph/undirected-graph.js +3 -9
- package/dist/data-structures/hash/coordinate-map.d.ts +1 -5
- package/dist/data-structures/hash/coordinate-map.js +3 -9
- package/dist/data-structures/hash/coordinate-set.d.ts +1 -5
- package/dist/data-structures/hash/coordinate-set.js +3 -9
- package/dist/data-structures/hash/hash-table.d.ts +2 -1
- package/dist/data-structures/hash/hash-table.js +7 -0
- package/dist/data-structures/hash/pair.d.ts +2 -1
- package/dist/data-structures/hash/pair.js +7 -0
- package/dist/data-structures/hash/tree-map.d.ts +2 -1
- package/dist/data-structures/hash/tree-map.js +7 -0
- package/dist/data-structures/hash/tree-set.d.ts +2 -1
- package/dist/data-structures/hash/tree-set.js +7 -0
- package/dist/data-structures/heap/heap.d.ts +0 -14
- package/dist/data-structures/heap/heap.js +3 -27
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -2
- package/dist/data-structures/linked-list/doubly-linked-list.js +12 -18
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -1
- package/dist/data-structures/linked-list/singly-linked-list.js +12 -15
- package/dist/data-structures/tree/tree.d.ts +12 -4
- package/dist/data-structures/tree/tree.js +44 -12
- package/dist/data-structures/trie/trie.d.ts +3 -3
- package/dist/data-structures/trie/trie.js +10 -10
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/AVLTree.html +370 -224
- package/docs/classes/AVLTreeNode.html +24 -202
- package/docs/classes/AaTree.html +5 -2
- package/docs/classes/AbstractEdge.html +32 -57
- package/docs/classes/AbstractGraph.html +35 -32
- package/docs/classes/AbstractVertex.html +10 -25
- package/docs/classes/ArrayDeque.html +18 -15
- package/docs/classes/BST.html +363 -217
- package/docs/classes/BSTNode.html +24 -202
- package/docs/classes/BTree.html +5 -2
- package/docs/classes/BinaryIndexedTree.html +43 -10
- package/docs/classes/BinaryTree.html +385 -182
- package/docs/classes/BinaryTreeNode.html +64 -165
- package/docs/classes/Character.html +8 -5
- package/docs/classes/CoordinateMap.html +36 -41
- package/docs/classes/CoordinateSet.html +35 -40
- package/docs/classes/Deque.html +38 -57
- package/docs/classes/DirectedEdge.html +44 -82
- package/docs/classes/DirectedGraph.html +50 -47
- package/docs/classes/DirectedVertex.html +10 -26
- package/docs/classes/DoublyLinkedList.html +41 -58
- package/docs/classes/DoublyLinkedListNode.html +15 -12
- package/docs/classes/HashTable.html +153 -0
- package/docs/classes/Heap.html +19 -97
- package/docs/classes/HeapItem.html +12 -9
- package/docs/classes/Matrix2D.html +20 -17
- package/docs/classes/MatrixNTI2D.html +8 -5
- package/docs/classes/MaxHeap.html +19 -102
- package/docs/classes/MaxPriorityQueue.html +38 -35
- package/docs/classes/MinHeap.html +19 -102
- package/docs/classes/MinPriorityQueue.html +38 -35
- package/docs/classes/Navigator.html +14 -11
- package/docs/classes/ObjectDeque.html +29 -26
- package/docs/classes/Pair.html +153 -0
- package/docs/classes/PriorityQueue.html +36 -33
- package/docs/classes/Queue.html +18 -15
- package/docs/classes/RBTree.html +5 -2
- package/docs/classes/SegmentTree.html +116 -46
- package/docs/classes/SegmentTreeNode.html +49 -129
- package/docs/classes/SinglyLinkedList.html +38 -45
- package/docs/classes/SinglyLinkedListNode.html +12 -9
- package/docs/classes/SkipLinkedList.html +5 -2
- package/docs/classes/SplayTree.html +5 -2
- package/docs/classes/Stack.html +16 -13
- package/docs/classes/TreeMap.html +153 -0
- package/docs/classes/TreeMultiSet.html +363 -217
- package/docs/classes/TreeNode.html +112 -24
- package/docs/classes/TreeSet.html +153 -0
- package/docs/classes/Trie.html +17 -14
- package/docs/classes/TrieNode.html +20 -17
- package/docs/classes/TwoThreeTree.html +5 -2
- package/docs/classes/UndirectedEdge.html +44 -56
- package/docs/classes/UndirectedGraph.html +49 -54
- package/docs/classes/UndirectedVertex.html +10 -26
- package/docs/classes/Vector2D.html +32 -29
- package/docs/enums/CP.html +8 -5
- package/docs/enums/FamilyPosition.html +8 -5
- package/docs/enums/LoopType.html +7 -4
- package/docs/index.html +8 -1
- package/docs/interfaces/AVLTreeDeleted.html +7 -4
- package/docs/interfaces/HeapOptions.html +6 -3
- package/docs/interfaces/IDirectedGraph.html +11 -8
- package/docs/interfaces/IGraph.html +23 -20
- package/docs/interfaces/NavigatorParams.html +9 -6
- package/docs/interfaces/PriorityQueueOptions.html +8 -5
- package/docs/modules.html +8 -2
- package/docs/types/BSTComparator.html +5 -2
- package/docs/types/BSTDeletedResult.html +5 -2
- package/docs/types/BinaryTreeDeleted.html +5 -2
- package/docs/types/BinaryTreeNodeId.html +5 -2
- package/docs/types/BinaryTreeNodePropertyName.html +5 -2
- package/docs/types/DFSOrderPattern.html +5 -2
- package/docs/types/DijkstraResult.html +5 -2
- package/docs/types/Direction.html +5 -2
- package/docs/types/NodeOrPropertyName.html +5 -2
- package/docs/types/PriorityQueueComparator.html +5 -2
- package/docs/types/PriorityQueueDFSOrderPattern.html +5 -2
- package/docs/types/ResultByProperty.html +5 -2
- package/docs/types/ResultsByProperty.html +5 -2
- package/docs/types/SegmentTreeNodeVal.html +5 -2
- package/docs/types/SpecifyOptional.html +5 -2
- package/docs/types/Thunk.html +5 -2
- package/docs/types/ToThunkFn.html +5 -2
- package/docs/types/TopologicalStatus.html +5 -2
- package/docs/types/TreeMultiSetDeletedResult.html +5 -2
- package/docs/types/TrlAsyncFn.html +5 -2
- package/docs/types/TrlFn.html +5 -2
- package/docs/types/Turning.html +5 -2
- package/docs/types/VertexId.html +5 -2
- package/notes/note.md +5 -1
- package/package.json +2 -2
- package/tsconfig.json +2 -2
- package/docs/types/DoublyLinkedListGetBy.html +0 -125
|
@@ -187,7 +187,7 @@ var AVLTree = /** @class */ (function (_super) {
|
|
|
187
187
|
B.parent = parentOfA;
|
|
188
188
|
if (A === this.root) {
|
|
189
189
|
if (B)
|
|
190
|
-
this.
|
|
190
|
+
this._setRoot(B);
|
|
191
191
|
}
|
|
192
192
|
else {
|
|
193
193
|
if ((parentOfA === null || parentOfA === void 0 ? void 0 : parentOfA.left) === A) {
|
|
@@ -232,7 +232,7 @@ var AVLTree = /** @class */ (function (_super) {
|
|
|
232
232
|
}
|
|
233
233
|
if (A === this.root) {
|
|
234
234
|
if (C)
|
|
235
|
-
this.
|
|
235
|
+
this._setRoot(C);
|
|
236
236
|
}
|
|
237
237
|
else {
|
|
238
238
|
if (parentOfA) {
|
|
@@ -271,7 +271,7 @@ var AVLTree = /** @class */ (function (_super) {
|
|
|
271
271
|
}
|
|
272
272
|
if (A === this.root) {
|
|
273
273
|
if (B)
|
|
274
|
-
this.
|
|
274
|
+
this._setRoot(B);
|
|
275
275
|
}
|
|
276
276
|
else {
|
|
277
277
|
if (parentOfA) {
|
|
@@ -315,7 +315,7 @@ var AVLTree = /** @class */ (function (_super) {
|
|
|
315
315
|
}
|
|
316
316
|
if (A === this.root) {
|
|
317
317
|
if (C)
|
|
318
|
-
this.
|
|
318
|
+
this._setRoot(C);
|
|
319
319
|
}
|
|
320
320
|
else {
|
|
321
321
|
if (parentOfA) {
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
export declare class BinaryIndexedTree {
|
|
9
|
-
private readonly _sumTree;
|
|
10
9
|
/**
|
|
11
10
|
* The constructor initializes an array with a specified length and fills it with zeros.
|
|
12
11
|
* @param {number} n - The parameter `n` represents the size of the array that will be used to store the sum tree. The
|
|
@@ -14,6 +13,8 @@ export declare class BinaryIndexedTree {
|
|
|
14
13
|
* The size of the sum tree array is `n + 1` because
|
|
15
14
|
*/
|
|
16
15
|
constructor(n: number);
|
|
16
|
+
private _sumTree;
|
|
17
|
+
get sumTree(): number[];
|
|
17
18
|
static lowBit(x: number): number;
|
|
18
19
|
/**
|
|
19
20
|
* The update function updates the values in a binary indexed tree by adding a delta value to the specified index and
|
|
@@ -41,4 +42,5 @@ export declare class BinaryIndexedTree {
|
|
|
41
42
|
* @returns the sum of the elements in the range specified by the start and end indices.
|
|
42
43
|
*/
|
|
43
44
|
getRangeSum(start: number, end: number): number;
|
|
45
|
+
protected _setSumTree(value: number[]): void;
|
|
44
46
|
}
|
|
@@ -18,6 +18,13 @@ var BinaryIndexedTree = /** @class */ (function () {
|
|
|
18
18
|
function BinaryIndexedTree(n) {
|
|
19
19
|
this._sumTree = new Array(n + 1).fill(0);
|
|
20
20
|
}
|
|
21
|
+
Object.defineProperty(BinaryIndexedTree.prototype, "sumTree", {
|
|
22
|
+
get: function () {
|
|
23
|
+
return this._sumTree;
|
|
24
|
+
},
|
|
25
|
+
enumerable: false,
|
|
26
|
+
configurable: true
|
|
27
|
+
});
|
|
21
28
|
BinaryIndexedTree.lowBit = function (x) {
|
|
22
29
|
return x & (-x);
|
|
23
30
|
};
|
|
@@ -63,6 +70,9 @@ var BinaryIndexedTree = /** @class */ (function () {
|
|
|
63
70
|
throw 'Index out of bounds';
|
|
64
71
|
return this.getPrefixSum(end) - this.getPrefixSum(start);
|
|
65
72
|
};
|
|
73
|
+
BinaryIndexedTree.prototype._setSumTree = function (value) {
|
|
74
|
+
this._sumTree = value;
|
|
75
|
+
};
|
|
66
76
|
return BinaryIndexedTree;
|
|
67
77
|
}());
|
|
68
78
|
exports.BinaryIndexedTree = BinaryIndexedTree;
|
|
@@ -23,75 +23,34 @@ export declare enum LoopType {
|
|
|
23
23
|
}
|
|
24
24
|
export declare class BinaryTreeNode<T> {
|
|
25
25
|
constructor(id: BinaryTreeNodeId, val: T, count?: number);
|
|
26
|
-
|
|
26
|
+
private _id;
|
|
27
27
|
get id(): BinaryTreeNodeId;
|
|
28
28
|
set id(v: BinaryTreeNodeId);
|
|
29
|
-
|
|
29
|
+
private _val;
|
|
30
30
|
get val(): T;
|
|
31
31
|
set val(v: T);
|
|
32
|
-
|
|
32
|
+
private _left?;
|
|
33
33
|
get left(): BinaryTreeNode<T> | null | undefined;
|
|
34
34
|
set left(v: BinaryTreeNode<T> | null | undefined);
|
|
35
|
-
|
|
35
|
+
private _right?;
|
|
36
36
|
get right(): BinaryTreeNode<T> | null | undefined;
|
|
37
37
|
set right(v: BinaryTreeNode<T> | null | undefined);
|
|
38
|
-
|
|
38
|
+
private _parent;
|
|
39
39
|
get parent(): BinaryTreeNode<T> | null | undefined;
|
|
40
40
|
set parent(v: BinaryTreeNode<T> | null | undefined);
|
|
41
|
-
|
|
41
|
+
private _familyPosition;
|
|
42
42
|
get familyPosition(): FamilyPosition;
|
|
43
43
|
set familyPosition(v: FamilyPosition);
|
|
44
|
-
|
|
44
|
+
private _count;
|
|
45
45
|
get count(): number;
|
|
46
46
|
set count(v: number);
|
|
47
|
-
|
|
47
|
+
private _height;
|
|
48
48
|
get height(): number;
|
|
49
49
|
set height(v: number);
|
|
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
|
-
getId(): BinaryTreeNodeId;
|
|
54
|
-
/**
|
|
55
|
-
* 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.
|
|
56
|
-
*/
|
|
57
|
-
getVal(): T;
|
|
58
|
-
/**
|
|
59
|
-
* 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.
|
|
60
|
-
*/
|
|
61
|
-
getLeft(): BinaryTreeNode<T> | null | undefined;
|
|
62
|
-
/**
|
|
63
|
-
* 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.
|
|
64
|
-
*/
|
|
65
|
-
getRight(): BinaryTreeNode<T> | null | undefined;
|
|
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
|
-
getParent(): BinaryTreeNode<T> | null | undefined;
|
|
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
|
-
getFamilyPosition(): FamilyPosition;
|
|
74
|
-
/**
|
|
75
|
-
* 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.
|
|
76
|
-
*/
|
|
77
|
-
getCount(): number;
|
|
78
|
-
/**
|
|
79
|
-
* 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.
|
|
80
|
-
*/
|
|
81
|
-
getHeight(): number;
|
|
82
50
|
swapLocation(swapNode: BinaryTreeNode<T>): BinaryTreeNode<T>;
|
|
83
51
|
clone(): BinaryTreeNode<T>;
|
|
84
52
|
}
|
|
85
53
|
export declare class BinaryTree<T> {
|
|
86
|
-
protected _loopType: LoopType;
|
|
87
|
-
protected _visitedId: BinaryTreeNodeId[];
|
|
88
|
-
protected _visitedVal: Array<T>;
|
|
89
|
-
protected _visitedNode: BinaryTreeNode<T>[];
|
|
90
|
-
protected _visitedCount: number[];
|
|
91
|
-
protected _visitedLeftSum: number[];
|
|
92
|
-
private readonly _autoIncrementId;
|
|
93
|
-
private _maxId;
|
|
94
|
-
private readonly _isDuplicatedVal;
|
|
95
54
|
/**
|
|
96
55
|
* The constructor function accepts an optional options object and sets the values of loopType, autoIncrementId, and
|
|
97
56
|
* isDuplicatedVal based on the provided options.
|
|
@@ -102,28 +61,30 @@ export declare class BinaryTree<T> {
|
|
|
102
61
|
autoIncrementId?: boolean;
|
|
103
62
|
isDuplicatedVal?: boolean;
|
|
104
63
|
});
|
|
105
|
-
|
|
64
|
+
private _loopType;
|
|
65
|
+
get loopType(): LoopType;
|
|
66
|
+
private _visitedId;
|
|
67
|
+
get visitedId(): BinaryTreeNodeId[];
|
|
68
|
+
private _visitedVal;
|
|
69
|
+
get visitedVal(): Array<T>;
|
|
70
|
+
private _visitedNode;
|
|
71
|
+
get visitedNode(): BinaryTreeNode<T>[];
|
|
72
|
+
private _visitedCount;
|
|
73
|
+
get visitedCount(): number[];
|
|
74
|
+
private _visitedLeftSum;
|
|
75
|
+
get visitedLeftSum(): number[];
|
|
76
|
+
private _autoIncrementId;
|
|
77
|
+
get autoIncrementId(): boolean;
|
|
78
|
+
private _maxId;
|
|
79
|
+
get maxId(): number;
|
|
80
|
+
private _isDuplicatedVal;
|
|
81
|
+
get isDuplicatedVal(): boolean;
|
|
82
|
+
private _root;
|
|
106
83
|
get root(): BinaryTreeNode<T> | null;
|
|
107
|
-
|
|
108
|
-
protected _size: number;
|
|
84
|
+
private _size;
|
|
109
85
|
get size(): number;
|
|
110
|
-
|
|
111
|
-
protected _count: number;
|
|
86
|
+
private _count;
|
|
112
87
|
get count(): number;
|
|
113
|
-
protected set count(v: number);
|
|
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 Getters (using the same name as the property) while utilizing separate method names for Setters.
|
|
116
|
-
* @returns The method is returning either a BinaryTreeNode object of type T or null.
|
|
117
|
-
*/
|
|
118
|
-
getRoot(): BinaryTreeNode<T> | null;
|
|
119
|
-
/**
|
|
120
|
-
* 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.
|
|
121
|
-
*/
|
|
122
|
-
getSize(): number;
|
|
123
|
-
/**
|
|
124
|
-
* 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.
|
|
125
|
-
*/
|
|
126
|
-
getCount(): number;
|
|
127
88
|
/**
|
|
128
89
|
* The function creates a new binary tree node with the given id, value, and count, or returns null if the value is
|
|
129
90
|
* null.
|
|
@@ -347,6 +308,18 @@ export declare class BinaryTree<T> {
|
|
|
347
308
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
|
|
348
309
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
|
|
349
310
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
311
|
+
protected _setLoopType(value: LoopType): void;
|
|
312
|
+
protected _setVisitedId(value: BinaryTreeNodeId[]): void;
|
|
313
|
+
protected _setVisitedVal(value: Array<T>): void;
|
|
314
|
+
protected _setVisitedNode(value: BinaryTreeNode<T>[]): void;
|
|
315
|
+
protected setVisitedCount(value: number[]): void;
|
|
316
|
+
protected _setVisitedLeftSum(value: number[]): void;
|
|
317
|
+
protected _setAutoIncrementId(value: boolean): void;
|
|
318
|
+
protected _setMaxId(value: number): void;
|
|
319
|
+
protected _setIsDuplicatedVal(value: boolean): void;
|
|
320
|
+
protected _setRoot(v: BinaryTreeNode<T> | null): void;
|
|
321
|
+
protected _setSize(v: number): void;
|
|
322
|
+
protected _setCount(v: number): void;
|
|
350
323
|
/**
|
|
351
324
|
* The function resets the values of several arrays used for tracking visited nodes and their properties.
|
|
352
325
|
*/
|
|
@@ -42,7 +42,7 @@ var FamilyPosition;
|
|
|
42
42
|
FamilyPosition[FamilyPosition["root"] = 0] = "root";
|
|
43
43
|
FamilyPosition[FamilyPosition["left"] = 1] = "left";
|
|
44
44
|
FamilyPosition[FamilyPosition["right"] = 2] = "right";
|
|
45
|
-
})(FamilyPosition
|
|
45
|
+
})(FamilyPosition || (exports.FamilyPosition = FamilyPosition = {}));
|
|
46
46
|
/**
|
|
47
47
|
* Enum representing different loop types.
|
|
48
48
|
*
|
|
@@ -53,7 +53,7 @@ var LoopType;
|
|
|
53
53
|
(function (LoopType) {
|
|
54
54
|
LoopType[LoopType["iterative"] = 1] = "iterative";
|
|
55
55
|
LoopType[LoopType["recursive"] = 2] = "recursive";
|
|
56
|
-
})(LoopType
|
|
56
|
+
})(LoopType || (exports.LoopType = LoopType = {}));
|
|
57
57
|
var BinaryTreeNode = /** @class */ (function () {
|
|
58
58
|
function BinaryTreeNode(id, val, count) {
|
|
59
59
|
this._familyPosition = FamilyPosition.root;
|
|
@@ -151,54 +151,6 @@ var BinaryTreeNode = /** @class */ (function () {
|
|
|
151
151
|
enumerable: false,
|
|
152
152
|
configurable: true
|
|
153
153
|
});
|
|
154
|
-
/**
|
|
155
|
-
* 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.
|
|
156
|
-
*/
|
|
157
|
-
BinaryTreeNode.prototype.getId = function () {
|
|
158
|
-
return this._id;
|
|
159
|
-
};
|
|
160
|
-
/**
|
|
161
|
-
* 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.
|
|
162
|
-
*/
|
|
163
|
-
BinaryTreeNode.prototype.getVal = function () {
|
|
164
|
-
return this._val;
|
|
165
|
-
};
|
|
166
|
-
/**
|
|
167
|
-
* 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.
|
|
168
|
-
*/
|
|
169
|
-
BinaryTreeNode.prototype.getLeft = function () {
|
|
170
|
-
return this._left;
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* 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.
|
|
174
|
-
*/
|
|
175
|
-
BinaryTreeNode.prototype.getRight = function () {
|
|
176
|
-
return this._right;
|
|
177
|
-
};
|
|
178
|
-
/**
|
|
179
|
-
* 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.
|
|
180
|
-
*/
|
|
181
|
-
BinaryTreeNode.prototype.getParent = function () {
|
|
182
|
-
return this._parent;
|
|
183
|
-
};
|
|
184
|
-
/**
|
|
185
|
-
* 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.
|
|
186
|
-
*/
|
|
187
|
-
BinaryTreeNode.prototype.getFamilyPosition = function () {
|
|
188
|
-
return this._familyPosition;
|
|
189
|
-
};
|
|
190
|
-
/**
|
|
191
|
-
* 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.
|
|
192
|
-
*/
|
|
193
|
-
BinaryTreeNode.prototype.getCount = function () {
|
|
194
|
-
return this._count;
|
|
195
|
-
};
|
|
196
|
-
/**
|
|
197
|
-
* 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.
|
|
198
|
-
*/
|
|
199
|
-
BinaryTreeNode.prototype.getHeight = function () {
|
|
200
|
-
return this._height;
|
|
201
|
-
};
|
|
202
154
|
BinaryTreeNode.prototype.swapLocation = function (swapNode) {
|
|
203
155
|
var val = swapNode.val, count = swapNode.count, height = swapNode.height;
|
|
204
156
|
var tempNode = new BinaryTreeNode(swapNode.id, val);
|
|
@@ -247,17 +199,73 @@ var BinaryTree = /** @class */ (function () {
|
|
|
247
199
|
this._loopType = loopType;
|
|
248
200
|
}
|
|
249
201
|
}
|
|
202
|
+
Object.defineProperty(BinaryTree.prototype, "loopType", {
|
|
203
|
+
get: function () {
|
|
204
|
+
return this._loopType;
|
|
205
|
+
},
|
|
206
|
+
enumerable: false,
|
|
207
|
+
configurable: true
|
|
208
|
+
});
|
|
209
|
+
Object.defineProperty(BinaryTree.prototype, "visitedId", {
|
|
210
|
+
get: function () {
|
|
211
|
+
return this._visitedId;
|
|
212
|
+
},
|
|
213
|
+
enumerable: false,
|
|
214
|
+
configurable: true
|
|
215
|
+
});
|
|
216
|
+
Object.defineProperty(BinaryTree.prototype, "visitedVal", {
|
|
217
|
+
get: function () {
|
|
218
|
+
return this._visitedVal;
|
|
219
|
+
},
|
|
220
|
+
enumerable: false,
|
|
221
|
+
configurable: true
|
|
222
|
+
});
|
|
223
|
+
Object.defineProperty(BinaryTree.prototype, "visitedNode", {
|
|
224
|
+
get: function () {
|
|
225
|
+
return this._visitedNode;
|
|
226
|
+
},
|
|
227
|
+
enumerable: false,
|
|
228
|
+
configurable: true
|
|
229
|
+
});
|
|
230
|
+
Object.defineProperty(BinaryTree.prototype, "visitedCount", {
|
|
231
|
+
get: function () {
|
|
232
|
+
return this._visitedCount;
|
|
233
|
+
},
|
|
234
|
+
enumerable: false,
|
|
235
|
+
configurable: true
|
|
236
|
+
});
|
|
237
|
+
Object.defineProperty(BinaryTree.prototype, "visitedLeftSum", {
|
|
238
|
+
get: function () {
|
|
239
|
+
return this._visitedLeftSum;
|
|
240
|
+
},
|
|
241
|
+
enumerable: false,
|
|
242
|
+
configurable: true
|
|
243
|
+
});
|
|
244
|
+
Object.defineProperty(BinaryTree.prototype, "autoIncrementId", {
|
|
245
|
+
get: function () {
|
|
246
|
+
return this._autoIncrementId;
|
|
247
|
+
},
|
|
248
|
+
enumerable: false,
|
|
249
|
+
configurable: true
|
|
250
|
+
});
|
|
251
|
+
Object.defineProperty(BinaryTree.prototype, "maxId", {
|
|
252
|
+
get: function () {
|
|
253
|
+
return this._maxId;
|
|
254
|
+
},
|
|
255
|
+
enumerable: false,
|
|
256
|
+
configurable: true
|
|
257
|
+
});
|
|
258
|
+
Object.defineProperty(BinaryTree.prototype, "isDuplicatedVal", {
|
|
259
|
+
get: function () {
|
|
260
|
+
return this._isDuplicatedVal;
|
|
261
|
+
},
|
|
262
|
+
enumerable: false,
|
|
263
|
+
configurable: true
|
|
264
|
+
});
|
|
250
265
|
Object.defineProperty(BinaryTree.prototype, "root", {
|
|
251
266
|
get: function () {
|
|
252
267
|
return this._root;
|
|
253
268
|
},
|
|
254
|
-
set: function (v) {
|
|
255
|
-
if (v) {
|
|
256
|
-
v.parent = null;
|
|
257
|
-
v.familyPosition = FamilyPosition.root;
|
|
258
|
-
}
|
|
259
|
-
this._root = v;
|
|
260
|
-
},
|
|
261
269
|
enumerable: false,
|
|
262
270
|
configurable: true
|
|
263
271
|
});
|
|
@@ -265,9 +273,6 @@ var BinaryTree = /** @class */ (function () {
|
|
|
265
273
|
get: function () {
|
|
266
274
|
return this._size;
|
|
267
275
|
},
|
|
268
|
-
set: function (v) {
|
|
269
|
-
this._size = v;
|
|
270
|
-
},
|
|
271
276
|
enumerable: false,
|
|
272
277
|
configurable: true
|
|
273
278
|
});
|
|
@@ -275,31 +280,9 @@ var BinaryTree = /** @class */ (function () {
|
|
|
275
280
|
get: function () {
|
|
276
281
|
return this._count;
|
|
277
282
|
},
|
|
278
|
-
set: function (v) {
|
|
279
|
-
this._count = v;
|
|
280
|
-
},
|
|
281
283
|
enumerable: false,
|
|
282
284
|
configurable: true
|
|
283
285
|
});
|
|
284
|
-
/**
|
|
285
|
-
* 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 Getters (using the same name as the property) while utilizing separate method names for Setters.
|
|
286
|
-
* @returns The method is returning either a BinaryTreeNode object of type T or null.
|
|
287
|
-
*/
|
|
288
|
-
BinaryTree.prototype.getRoot = function () {
|
|
289
|
-
return this._root;
|
|
290
|
-
};
|
|
291
|
-
/**
|
|
292
|
-
* 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.
|
|
293
|
-
*/
|
|
294
|
-
BinaryTree.prototype.getSize = function () {
|
|
295
|
-
return this._size;
|
|
296
|
-
};
|
|
297
|
-
/**
|
|
298
|
-
* 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.
|
|
299
|
-
*/
|
|
300
|
-
BinaryTree.prototype.getCount = function () {
|
|
301
|
-
return this._count;
|
|
302
|
-
};
|
|
303
286
|
/**
|
|
304
287
|
* The function creates a new binary tree node with the given id, value, and count, or returns null if the value is
|
|
305
288
|
* null.
|
|
@@ -319,10 +302,10 @@ var BinaryTree = /** @class */ (function () {
|
|
|
319
302
|
* The clear function resets the state of an object by setting its properties to their initial values.
|
|
320
303
|
*/
|
|
321
304
|
BinaryTree.prototype.clear = function () {
|
|
322
|
-
this.
|
|
323
|
-
this.
|
|
324
|
-
this.
|
|
325
|
-
this.
|
|
305
|
+
this._setRoot(null);
|
|
306
|
+
this._setSize(0);
|
|
307
|
+
this._setCount(0);
|
|
308
|
+
this._setMaxId(-1);
|
|
326
309
|
};
|
|
327
310
|
/**
|
|
328
311
|
* The function checks if the size of an object is equal to zero and returns a boolean value.
|
|
@@ -371,7 +354,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
371
354
|
existNode.count += count;
|
|
372
355
|
existNode.val = val;
|
|
373
356
|
if (needInsert !== null) {
|
|
374
|
-
this.count
|
|
357
|
+
this._setCount(this.count + count);
|
|
375
358
|
inserted = existNode;
|
|
376
359
|
}
|
|
377
360
|
}
|
|
@@ -380,10 +363,10 @@ var BinaryTree = /** @class */ (function () {
|
|
|
380
363
|
}
|
|
381
364
|
}
|
|
382
365
|
else {
|
|
383
|
-
this.
|
|
366
|
+
this._setRoot(val !== null ? new BinaryTreeNode(id, val, count) : null);
|
|
384
367
|
if (needInsert !== null) {
|
|
385
|
-
this.
|
|
386
|
-
this.count
|
|
368
|
+
this._setSize(1);
|
|
369
|
+
this._setCount(count);
|
|
387
370
|
}
|
|
388
371
|
inserted = this.root;
|
|
389
372
|
}
|
|
@@ -407,8 +390,8 @@ var BinaryTree = /** @class */ (function () {
|
|
|
407
390
|
}
|
|
408
391
|
parent.left = newNode;
|
|
409
392
|
if (newNode !== null) {
|
|
410
|
-
this.size
|
|
411
|
-
this.
|
|
393
|
+
this._setSize(this.size + 1);
|
|
394
|
+
this._setCount((_a = this.count + (newNode === null || newNode === void 0 ? void 0 : newNode.count)) !== null && _a !== void 0 ? _a : 0);
|
|
412
395
|
}
|
|
413
396
|
return parent.left;
|
|
414
397
|
}
|
|
@@ -419,8 +402,8 @@ var BinaryTree = /** @class */ (function () {
|
|
|
419
402
|
}
|
|
420
403
|
parent.right = newNode;
|
|
421
404
|
if (newNode !== null) {
|
|
422
|
-
this.size
|
|
423
|
-
this.
|
|
405
|
+
this._setSize(this.size + 1);
|
|
406
|
+
this._setCount((_b = this.count + (newNode === null || newNode === void 0 ? void 0 : newNode.count)) !== null && _b !== void 0 ? _b : 0);
|
|
424
407
|
}
|
|
425
408
|
return parent.right;
|
|
426
409
|
}
|
|
@@ -533,27 +516,27 @@ var BinaryTree = /** @class */ (function () {
|
|
|
533
516
|
node = undefined;
|
|
534
517
|
else if (node.count > 1 && !ignoreCount) {
|
|
535
518
|
node.count--;
|
|
536
|
-
this.count
|
|
519
|
+
this._setCount(this.count - 1);
|
|
537
520
|
}
|
|
538
521
|
else if (node instanceof BinaryTreeNode) {
|
|
539
522
|
var _a = __read(this.getSubTreeSizeAndCount(node), 2), subSize = _a[0], subCount = _a[1];
|
|
540
523
|
switch (node.familyPosition) {
|
|
541
524
|
case 0:
|
|
542
|
-
this.size
|
|
543
|
-
this.count
|
|
525
|
+
this._setSize(this.size - subSize);
|
|
526
|
+
this._setCount(this.count - subCount);
|
|
544
527
|
node = undefined;
|
|
545
528
|
break;
|
|
546
529
|
case 1:
|
|
547
530
|
if (node.parent) {
|
|
548
|
-
this.size
|
|
549
|
-
this.count
|
|
531
|
+
this._setSize(this.size - subSize);
|
|
532
|
+
this._setCount(this.count - subCount);
|
|
550
533
|
node.parent.left = null;
|
|
551
534
|
}
|
|
552
535
|
break;
|
|
553
536
|
case 2:
|
|
554
537
|
if (node.parent) {
|
|
555
|
-
this.size
|
|
556
|
-
this.count
|
|
538
|
+
this._setSize(this.size - subSize);
|
|
539
|
+
this._setCount(this.count - subCount);
|
|
557
540
|
node.parent.right = null;
|
|
558
541
|
}
|
|
559
542
|
break;
|
|
@@ -833,7 +816,6 @@ var BinaryTree = /** @class */ (function () {
|
|
|
833
816
|
return _traverse_5(node);
|
|
834
817
|
}
|
|
835
818
|
};
|
|
836
|
-
// --- start additional methods ---
|
|
837
819
|
/**
|
|
838
820
|
* The `isBST` function checks if a binary tree is a binary search tree.
|
|
839
821
|
* @param {BinaryTreeNode<T> | null} [node] - The `node` parameter is an optional parameter of type `BinaryTreeNode<T>
|
|
@@ -907,6 +889,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
907
889
|
return res;
|
|
908
890
|
}
|
|
909
891
|
};
|
|
892
|
+
// --- start additional methods ---
|
|
910
893
|
/**
|
|
911
894
|
* The function `subTreeSum` calculates the sum of a specified property in a binary tree, either recursively or
|
|
912
895
|
* iteratively.
|
|
@@ -980,7 +963,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
980
963
|
break;
|
|
981
964
|
case 'count':
|
|
982
965
|
cur.count += delta;
|
|
983
|
-
_this.count
|
|
966
|
+
_this._setCount(_this.count + delta);
|
|
984
967
|
break;
|
|
985
968
|
default:
|
|
986
969
|
cur.id += delta;
|
|
@@ -1338,6 +1321,46 @@ var BinaryTree = /** @class */ (function () {
|
|
|
1338
1321
|
}
|
|
1339
1322
|
return this._getResultByPropertyName(nodeOrPropertyName);
|
|
1340
1323
|
};
|
|
1324
|
+
BinaryTree.prototype._setLoopType = function (value) {
|
|
1325
|
+
this._loopType = value;
|
|
1326
|
+
};
|
|
1327
|
+
BinaryTree.prototype._setVisitedId = function (value) {
|
|
1328
|
+
this._visitedId = value;
|
|
1329
|
+
};
|
|
1330
|
+
BinaryTree.prototype._setVisitedVal = function (value) {
|
|
1331
|
+
this._visitedVal = value;
|
|
1332
|
+
};
|
|
1333
|
+
BinaryTree.prototype._setVisitedNode = function (value) {
|
|
1334
|
+
this._visitedNode = value;
|
|
1335
|
+
};
|
|
1336
|
+
BinaryTree.prototype.setVisitedCount = function (value) {
|
|
1337
|
+
this._visitedCount = value;
|
|
1338
|
+
};
|
|
1339
|
+
BinaryTree.prototype._setVisitedLeftSum = function (value) {
|
|
1340
|
+
this._visitedLeftSum = value;
|
|
1341
|
+
};
|
|
1342
|
+
BinaryTree.prototype._setAutoIncrementId = function (value) {
|
|
1343
|
+
this._autoIncrementId = value;
|
|
1344
|
+
};
|
|
1345
|
+
BinaryTree.prototype._setMaxId = function (value) {
|
|
1346
|
+
this._maxId = value;
|
|
1347
|
+
};
|
|
1348
|
+
BinaryTree.prototype._setIsDuplicatedVal = function (value) {
|
|
1349
|
+
this._isDuplicatedVal = value;
|
|
1350
|
+
};
|
|
1351
|
+
BinaryTree.prototype._setRoot = function (v) {
|
|
1352
|
+
if (v) {
|
|
1353
|
+
v.parent = null;
|
|
1354
|
+
v.familyPosition = FamilyPosition.root;
|
|
1355
|
+
}
|
|
1356
|
+
this._root = v;
|
|
1357
|
+
};
|
|
1358
|
+
BinaryTree.prototype._setSize = function (v) {
|
|
1359
|
+
this._size = v;
|
|
1360
|
+
};
|
|
1361
|
+
BinaryTree.prototype._setCount = function (v) {
|
|
1362
|
+
this._count = v;
|
|
1363
|
+
};
|
|
1341
1364
|
/**
|
|
1342
1365
|
* The function resets the values of several arrays used for tracking visited nodes and their properties.
|
|
1343
1366
|
*/
|