data-structure-typed 1.18.7 → 1.18.8
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 +154 -366
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +29 -32
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +179 -136
- package/dist/data-structures/binary-tree/avl-tree.d.ts +4 -4
- package/dist/data-structures/binary-tree/avl-tree.js +2 -2
- package/dist/data-structures/binary-tree/binary-tree.d.ts +3 -3
- package/dist/data-structures/binary-tree/binary-tree.js +4 -4
- package/dist/data-structures/binary-tree/bst.d.ts +13 -25
- package/dist/data-structures/binary-tree/bst.js +20 -74
- package/dist/data-structures/binary-tree/rb-tree.d.ts +6 -6
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +6 -6
- package/dist/data-structures/binary-tree/tree-multiset.js +7 -14
- package/dist/data-structures/graph/abstract-graph.d.ts +11 -9
- package/dist/data-structures/graph/abstract-graph.js +39 -22
- package/dist/data-structures/graph/directed-graph.d.ts +17 -15
- package/dist/data-structures/graph/directed-graph.js +47 -42
- package/dist/data-structures/graph/undirected-graph.d.ts +7 -7
- package/dist/data-structures/graph/undirected-graph.js +48 -48
- package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +2 -3
- package/dist/data-structures/interfaces/abstract-graph.d.ts +2 -4
- package/dist/data-structures/interfaces/avl-tree.d.ts +1 -1
- package/dist/data-structures/interfaces/bst.d.ts +2 -2
- package/dist/data-structures/interfaces/rb-tree.d.ts +2 -2
- package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -1
- package/dist/data-structures/tree/tree.d.ts +1 -4
- package/dist/data-structures/tree/tree.js +1 -12
- package/dist/data-structures/types/abstract-binary-tree.d.ts +9 -5
- package/dist/data-structures/types/abstract-binary-tree.js +9 -5
- package/dist/data-structures/types/avl-tree.d.ts +1 -1
- package/dist/data-structures/types/binary-tree.d.ts +1 -1
- package/dist/data-structures/types/bst.d.ts +1 -1
- package/dist/data-structures/types/bst.js +1 -1
- package/dist/data-structures/types/directed-graph.js +1 -1
- package/dist/data-structures/types/helpers.d.ts +1 -8
- package/dist/data-structures/types/rb-tree.d.ts +2 -0
- package/dist/data-structures/types/rb-tree.js +1 -1
- package/dist/data-structures/types/tree-multiset.d.ts +4 -4
- package/dist/utils/types/utils.d.ts +18 -0
- package/dist/utils/utils.d.ts +6 -1
- package/dist/utils/utils.js +21 -1
- package/package.json +2 -2
- package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
- package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
- package/backup/recursive-type/src/assets/logo.png +0 -0
- package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +0 -288
- package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
- package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +0 -1502
- package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +0 -503
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/index.ts +0 -11
- package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +0 -110
- package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +0 -243
- package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +0 -55
- package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/diagrams/README.md +0 -5
- package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +0 -985
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
- package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +0 -478
- package/backup/recursive-type/src/data-structures/graph/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +0 -293
- package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +0 -67
- package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +0 -56
- package/backup/recursive-type/src/data-structures/hash/hash-table.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/index.ts +0 -6
- package/backup/recursive-type/src/data-structures/hash/pair.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/tree-map.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/tree-set.ts +0 -3
- package/backup/recursive-type/src/data-structures/heap/heap.ts +0 -176
- package/backup/recursive-type/src/data-structures/heap/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/heap/max-heap.ts +0 -31
- package/backup/recursive-type/src/data-structures/heap/min-heap.ts +0 -34
- package/backup/recursive-type/src/data-structures/index.ts +0 -15
- package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +0 -42
- package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +0 -56
- package/backup/recursive-type/src/data-structures/interfaces/bst.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +0 -15
- package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/heap.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/index.ts +0 -13
- package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +0 -3
- package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
- package/backup/recursive-type/src/data-structures/linked-list/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +0 -490
- package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +0 -3
- package/backup/recursive-type/src/data-structures/matrix/index.ts +0 -4
- package/backup/recursive-type/src/data-structures/matrix/matrix.ts +0 -27
- package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +0 -208
- package/backup/recursive-type/src/data-structures/matrix/navigator.ts +0 -122
- package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +0 -316
- package/backup/recursive-type/src/data-structures/priority-queue/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
- package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
- package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +0 -354
- package/backup/recursive-type/src/data-structures/queue/deque.ts +0 -251
- package/backup/recursive-type/src/data-structures/queue/index.ts +0 -2
- package/backup/recursive-type/src/data-structures/queue/queue.ts +0 -120
- package/backup/recursive-type/src/data-structures/stack/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/stack/stack.ts +0 -98
- package/backup/recursive-type/src/data-structures/tree/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/tree/tree.ts +0 -80
- package/backup/recursive-type/src/data-structures/trie/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/trie/trie.ts +0 -227
- package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +0 -5
- package/backup/recursive-type/src/data-structures/types/avl-tree.ts +0 -8
- package/backup/recursive-type/src/data-structures/types/binary-tree.ts +0 -10
- package/backup/recursive-type/src/data-structures/types/bst.ts +0 -6
- package/backup/recursive-type/src/data-structures/types/directed-graph.ts +0 -8
- package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/heap.ts +0 -5
- package/backup/recursive-type/src/data-structures/types/index.ts +0 -12
- package/backup/recursive-type/src/data-structures/types/navigator.ts +0 -13
- package/backup/recursive-type/src/data-structures/types/priority-queue.ts +0 -9
- package/backup/recursive-type/src/data-structures/types/segment-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +0 -1
- package/backup/recursive-type/src/index.ts +0 -1
- package/backup/recursive-type/src/utils/index.ts +0 -2
- package/backup/recursive-type/src/utils/types/index.ts +0 -1
- package/backup/recursive-type/src/utils/types/utils.ts +0 -6
- package/backup/recursive-type/src/utils/utils.ts +0 -78
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -92
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1367
- package/docs/classes/AVLTree.html +0 -2451
- package/docs/classes/AVLTreeNode.html +0 -499
- package/docs/classes/AaTree.html +0 -172
- package/docs/classes/AbstractBinaryTree.html +0 -2118
- package/docs/classes/AbstractBinaryTreeNode.html +0 -524
- package/docs/classes/AbstractEdge.html +0 -295
- package/docs/classes/AbstractGraph.html +0 -1043
- package/docs/classes/AbstractVertex.html +0 -258
- package/docs/classes/ArrayDeque.html +0 -439
- package/docs/classes/BST.html +0 -2297
- package/docs/classes/BSTNode.html +0 -503
- package/docs/classes/BTree.html +0 -172
- package/docs/classes/BinaryIndexedTree.html +0 -341
- package/docs/classes/BinaryTree.html +0 -2133
- package/docs/classes/BinaryTreeNode.html +0 -501
- package/docs/classes/Character.html +0 -220
- package/docs/classes/CoordinateMap.html +0 -483
- package/docs/classes/CoordinateSet.html +0 -444
- package/docs/classes/Deque.html +0 -975
- package/docs/classes/DirectedEdge.html +0 -366
- package/docs/classes/DirectedGraph.html +0 -1443
- package/docs/classes/DirectedVertex.html +0 -254
- package/docs/classes/DoublyLinkedList.html +0 -968
- package/docs/classes/DoublyLinkedListNode.html +0 -297
- package/docs/classes/HashTable.html +0 -172
- package/docs/classes/Heap.html +0 -423
- package/docs/classes/HeapItem.html +0 -255
- package/docs/classes/Matrix2D.html +0 -502
- package/docs/classes/MatrixNTI2D.html +0 -240
- package/docs/classes/MaxHeap.html +0 -436
- package/docs/classes/MaxPriorityQueue.html +0 -836
- package/docs/classes/MinHeap.html +0 -437
- package/docs/classes/MinPriorityQueue.html +0 -838
- package/docs/classes/Navigator.html +0 -313
- package/docs/classes/ObjectDeque.html +0 -455
- package/docs/classes/Pair.html +0 -172
- package/docs/classes/PriorityQueue.html +0 -760
- package/docs/classes/Queue.html +0 -392
- package/docs/classes/RBTree.html +0 -2388
- package/docs/classes/RBTreeNode.html +0 -516
- package/docs/classes/SegmentTree.html +0 -434
- package/docs/classes/SegmentTreeNode.html +0 -357
- package/docs/classes/SinglyLinkedList.html +0 -788
- package/docs/classes/SinglyLinkedListNode.html +0 -270
- package/docs/classes/SkipLinkedList.html +0 -172
- package/docs/classes/SplayTree.html +0 -172
- package/docs/classes/Stack.html +0 -368
- package/docs/classes/TreeMap.html +0 -172
- package/docs/classes/TreeMultiSet.html +0 -2297
- package/docs/classes/TreeMultiSetNode.html +0 -499
- package/docs/classes/TreeNode.html +0 -343
- package/docs/classes/TreeSet.html +0 -172
- package/docs/classes/Trie.html +0 -372
- package/docs/classes/TrieNode.html +0 -280
- package/docs/classes/TwoThreeTree.html +0 -172
- package/docs/classes/UndirectedEdge.html +0 -337
- package/docs/classes/UndirectedGraph.html +0 -1210
- package/docs/classes/UndirectedVertex.html +0 -254
- package/docs/classes/Vector2D.html +0 -805
- package/docs/enums/CP.html +0 -181
- package/docs/enums/FamilyPosition.html +0 -181
- package/docs/enums/LoopType.html +0 -182
- package/docs/enums/RBColor.html +0 -174
- package/docs/enums/TopologicalProperty.html +0 -181
- package/docs/index.html +0 -645
- package/docs/interfaces/IAVLTree.html +0 -1378
- package/docs/interfaces/IAVLTreeNode.html +0 -405
- package/docs/interfaces/IAbstractBinaryTree.html +0 -1124
- package/docs/interfaces/IAbstractBinaryTreeNode.html +0 -384
- package/docs/interfaces/IAbstractGraph.html +0 -433
- package/docs/interfaces/IBST.html +0 -1271
- package/docs/interfaces/IBSTNode.html +0 -408
- package/docs/interfaces/IDirectedGraph.html +0 -572
- package/docs/interfaces/IUNDirectedGraph.html +0 -465
- package/docs/modules.html +0 -262
- package/docs/types/AVLTreeOptions.html +0 -150
- package/docs/types/AbstractBinaryTreeNodeProperties.html +0 -152
- package/docs/types/AbstractBinaryTreeNodeProperty.html +0 -152
- package/docs/types/AbstractBinaryTreeOptions.html +0 -156
- package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -152
- package/docs/types/BSTComparator.html +0 -162
- package/docs/types/BSTOptions.html +0 -152
- package/docs/types/BinaryTreeDeletedResult.html +0 -159
- package/docs/types/BinaryTreeNodeId.html +0 -147
- package/docs/types/BinaryTreeNodePropertyName.html +0 -147
- package/docs/types/BinaryTreeOptions.html +0 -150
- package/docs/types/DFSOrderPattern.html +0 -147
- package/docs/types/DijkstraResult.html +0 -167
- package/docs/types/Direction.html +0 -147
- package/docs/types/EdgeId.html +0 -147
- package/docs/types/HeapOptions.html +0 -168
- package/docs/types/IdObject.html +0 -157
- package/docs/types/KeyValObject.html +0 -152
- package/docs/types/NavigatorParams.html +0 -181
- package/docs/types/NodeOrPropertyName.html +0 -147
- package/docs/types/PriorityQueueComparator.html +0 -167
- package/docs/types/PriorityQueueDFSOrderPattern.html +0 -147
- package/docs/types/PriorityQueueOptions.html +0 -161
- package/docs/types/RBTreeOptions.html +0 -150
- package/docs/types/RecursiveAVLTreeNode.html +0 -152
- package/docs/types/RecursiveBSTNode.html +0 -152
- package/docs/types/RecursiveBinaryTreeNode.html +0 -152
- package/docs/types/RecursiveTreeMultiSetNode.html +0 -152
- package/docs/types/SegmentTreeNodeVal.html +0 -147
- package/docs/types/TopologicalStatus.html +0 -147
- package/docs/types/TreeMultiSetOptions.html +0 -152
- package/docs/types/Turning.html +0 -147
- package/docs/types/VertexId.html +0 -147
- package/notes/bst.test.ts +0 -181
- package/notes/note.md +0 -34
|
@@ -48,7 +48,6 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
|
|
|
48
48
|
* value `val` appears in the binary tree node. If the `count` parameter is not provided, it defaults to 1.
|
|
49
49
|
*/
|
|
50
50
|
function AbstractBinaryTreeNode(id, val, count) {
|
|
51
|
-
this._familyPosition = types_1.FamilyPosition.ROOT;
|
|
52
51
|
this._count = 1;
|
|
53
52
|
this._height = 0;
|
|
54
53
|
this._id = id;
|
|
@@ -82,7 +81,6 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
|
|
|
82
81
|
set: function (v) {
|
|
83
82
|
if (v) {
|
|
84
83
|
v.parent = this;
|
|
85
|
-
v.familyPosition = types_1.FamilyPosition.LEFT;
|
|
86
84
|
}
|
|
87
85
|
this._left = v;
|
|
88
86
|
},
|
|
@@ -96,7 +94,6 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
|
|
|
96
94
|
set: function (v) {
|
|
97
95
|
if (v) {
|
|
98
96
|
v.parent = this;
|
|
99
|
-
v.familyPosition = types_1.FamilyPosition.RIGHT;
|
|
100
97
|
}
|
|
101
98
|
this._right = v;
|
|
102
99
|
},
|
|
@@ -113,16 +110,6 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
|
|
|
113
110
|
enumerable: false,
|
|
114
111
|
configurable: true
|
|
115
112
|
});
|
|
116
|
-
Object.defineProperty(AbstractBinaryTreeNode.prototype, "familyPosition", {
|
|
117
|
-
get: function () {
|
|
118
|
-
return this._familyPosition;
|
|
119
|
-
},
|
|
120
|
-
set: function (v) {
|
|
121
|
-
this._familyPosition = v;
|
|
122
|
-
},
|
|
123
|
-
enumerable: false,
|
|
124
|
-
configurable: true
|
|
125
|
-
});
|
|
126
113
|
Object.defineProperty(AbstractBinaryTreeNode.prototype, "count", {
|
|
127
114
|
get: function () {
|
|
128
115
|
return this._count;
|
|
@@ -143,28 +130,63 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
|
|
|
143
130
|
enumerable: false,
|
|
144
131
|
configurable: true
|
|
145
132
|
});
|
|
133
|
+
Object.defineProperty(AbstractBinaryTreeNode.prototype, "familyPosition", {
|
|
134
|
+
get: function () {
|
|
135
|
+
var that = this;
|
|
136
|
+
if (that.parent) {
|
|
137
|
+
if (that.parent.left === that) {
|
|
138
|
+
if (that.left || that.right) {
|
|
139
|
+
return types_1.FamilyPosition.ROOT_LEFT;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
return types_1.FamilyPosition.LEFT;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else if (that.parent.right === that) {
|
|
146
|
+
if (that.left || that.right) {
|
|
147
|
+
return types_1.FamilyPosition.ROOT_RIGHT;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
return types_1.FamilyPosition.RIGHT;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
return types_1.FamilyPosition.MAL_NODE;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
if (that.left || that.right) {
|
|
159
|
+
return types_1.FamilyPosition.ROOT;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
return types_1.FamilyPosition.ISOLATED;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
enumerable: false,
|
|
167
|
+
configurable: true
|
|
168
|
+
});
|
|
146
169
|
/**
|
|
147
170
|
* The function swaps the location of two nodes in a binary tree.
|
|
148
|
-
* @param {FAMILY}
|
|
171
|
+
* @param {FAMILY} destNode - The `swapNode` parameter is of type `FAMILY`, which represents a node in a family tree.
|
|
149
172
|
* @returns the `swapNode` object after swapping its properties with the properties of `this` object.
|
|
150
173
|
*/
|
|
151
|
-
AbstractBinaryTreeNode.prototype.swapLocation = function (
|
|
152
|
-
var val =
|
|
153
|
-
var tempNode = this.createNode(
|
|
174
|
+
AbstractBinaryTreeNode.prototype.swapLocation = function (destNode) {
|
|
175
|
+
var val = destNode.val, count = destNode.count, height = destNode.height, id = destNode.id;
|
|
176
|
+
var tempNode = this.createNode(id, val, count);
|
|
177
|
+
tempNode.height = height;
|
|
154
178
|
if (tempNode instanceof AbstractBinaryTreeNode) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
swapNode.count = this.count;
|
|
161
|
-
swapNode.height = this.height;
|
|
179
|
+
// TODO should we consider the left, right children?
|
|
180
|
+
destNode.id = this.id;
|
|
181
|
+
destNode.val = this.val;
|
|
182
|
+
destNode.count = this.count;
|
|
183
|
+
destNode.height = this.height;
|
|
162
184
|
this.id = tempNode.id;
|
|
163
185
|
this.val = tempNode.val;
|
|
164
186
|
this.count = tempNode.count;
|
|
165
187
|
this.height = tempNode.height;
|
|
166
188
|
}
|
|
167
|
-
return
|
|
189
|
+
return destNode;
|
|
168
190
|
};
|
|
169
191
|
/**
|
|
170
192
|
* The `clone` function returns a new instance of the `FAMILY` class with the same `id`, `val`, and `count` properties.
|
|
@@ -192,13 +214,13 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
192
214
|
this._visitedLeftSum = [];
|
|
193
215
|
this._autoIncrementId = false;
|
|
194
216
|
this._maxId = -1;
|
|
195
|
-
this.
|
|
217
|
+
this._isMergeDuplicatedVal = true;
|
|
196
218
|
this._root = null;
|
|
197
219
|
this._size = 0;
|
|
198
220
|
this._count = 0;
|
|
199
221
|
if (options !== undefined) {
|
|
200
|
-
var _a = options.loopType, loopType = _a === void 0 ? types_1.LoopType.ITERATIVE : _a, _b = options.autoIncrementId, autoIncrementId = _b === void 0 ? false : _b, _c = options.
|
|
201
|
-
this.
|
|
222
|
+
var _a = options.loopType, loopType = _a === void 0 ? types_1.LoopType.ITERATIVE : _a, _b = options.autoIncrementId, autoIncrementId = _b === void 0 ? false : _b, _c = options.isMergeDuplicatedVal, isMergeDuplicatedVal = _c === void 0 ? true : _c;
|
|
223
|
+
this._isMergeDuplicatedVal = isMergeDuplicatedVal;
|
|
202
224
|
this._autoIncrementId = autoIncrementId;
|
|
203
225
|
this._loopType = loopType;
|
|
204
226
|
}
|
|
@@ -259,9 +281,9 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
259
281
|
enumerable: false,
|
|
260
282
|
configurable: true
|
|
261
283
|
});
|
|
262
|
-
Object.defineProperty(AbstractBinaryTree.prototype, "
|
|
284
|
+
Object.defineProperty(AbstractBinaryTree.prototype, "isMergeDuplicatedVal", {
|
|
263
285
|
get: function () {
|
|
264
|
-
return this.
|
|
286
|
+
return this._isMergeDuplicatedVal;
|
|
265
287
|
},
|
|
266
288
|
enumerable: false,
|
|
267
289
|
configurable: true
|
|
@@ -336,7 +358,7 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
336
358
|
return;
|
|
337
359
|
};
|
|
338
360
|
var inserted;
|
|
339
|
-
var needInsert = val !== null ? this.createNode(id, val
|
|
361
|
+
var needInsert = val !== null ? this.createNode(id, val, count) : null;
|
|
340
362
|
var existNode = val !== null ? this.get(id, 'id') : null;
|
|
341
363
|
if (this.root) {
|
|
342
364
|
if (existNode) {
|
|
@@ -352,7 +374,7 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
352
374
|
}
|
|
353
375
|
}
|
|
354
376
|
else {
|
|
355
|
-
this._setRoot(val !== null ? this.createNode(id, val
|
|
377
|
+
this._setRoot(val !== null ? this.createNode(id, val, count) : null);
|
|
356
378
|
if (needInsert !== null) {
|
|
357
379
|
this._setSize(1);
|
|
358
380
|
this._setCount(count);
|
|
@@ -376,7 +398,6 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
376
398
|
if (parent.left === undefined) {
|
|
377
399
|
if (newNode) {
|
|
378
400
|
newNode.parent = parent;
|
|
379
|
-
newNode.familyPosition = types_1.FamilyPosition.LEFT;
|
|
380
401
|
}
|
|
381
402
|
parent.left = newNode;
|
|
382
403
|
if (newNode !== null) {
|
|
@@ -388,7 +409,6 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
388
409
|
else if (parent.right === undefined) {
|
|
389
410
|
if (newNode) {
|
|
390
411
|
newNode.parent = parent;
|
|
391
|
-
newNode.familyPosition = types_1.FamilyPosition.RIGHT;
|
|
392
412
|
}
|
|
393
413
|
parent.right = newNode;
|
|
394
414
|
if (newNode !== null) {
|
|
@@ -415,13 +435,14 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
415
435
|
AbstractBinaryTree.prototype.addMany = function (data) {
|
|
416
436
|
var e_1, _a, e_2, _b;
|
|
417
437
|
var _c;
|
|
438
|
+
// TODO not sure addMany not be run multi times
|
|
418
439
|
var inserted = [];
|
|
419
440
|
var map = new Map();
|
|
420
|
-
if (
|
|
441
|
+
if (this.isMergeDuplicatedVal) {
|
|
421
442
|
try {
|
|
422
443
|
for (var data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
|
|
423
|
-
var
|
|
424
|
-
map.set(
|
|
444
|
+
var nodeOrId = data_1_1.value;
|
|
445
|
+
map.set(nodeOrId, ((_c = map.get(nodeOrId)) !== null && _c !== void 0 ? _c : 0) + 1);
|
|
425
446
|
}
|
|
426
447
|
}
|
|
427
448
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -434,53 +455,49 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
434
455
|
}
|
|
435
456
|
try {
|
|
436
457
|
for (var data_2 = __values(data), data_2_1 = data_2.next(); !data_2_1.done; data_2_1 = data_2.next()) {
|
|
437
|
-
var
|
|
458
|
+
var nodeOrId = data_2_1.value;
|
|
459
|
+
if (nodeOrId instanceof AbstractBinaryTreeNode) {
|
|
460
|
+
inserted.push(this.add(nodeOrId.id, nodeOrId.val, nodeOrId.count));
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
if (nodeOrId === null) {
|
|
464
|
+
inserted.push(this.add(NaN, null, 0));
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
438
467
|
// TODO will this cause an issue?
|
|
439
|
-
var count = this.
|
|
440
|
-
|
|
441
|
-
|
|
468
|
+
var count = this.isMergeDuplicatedVal ? map.get(nodeOrId) : 1;
|
|
469
|
+
var newId = void 0;
|
|
470
|
+
if (typeof nodeOrId === 'number') {
|
|
471
|
+
newId = this.autoIncrementId ? this.maxId + 1 : nodeOrId;
|
|
442
472
|
}
|
|
443
|
-
else if (
|
|
444
|
-
if (
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
473
|
+
else if (nodeOrId instanceof Object) {
|
|
474
|
+
if (this.autoIncrementId) {
|
|
475
|
+
newId = this.maxId + 1;
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
if (Object.keys(nodeOrId).includes('id')) {
|
|
479
|
+
newId = nodeOrId.id;
|
|
450
480
|
}
|
|
451
481
|
else {
|
|
452
|
-
|
|
482
|
+
console.warn(nodeOrId, 'Object value must has an id property when the autoIncrementId is false');
|
|
483
|
+
continue;
|
|
453
484
|
}
|
|
454
485
|
}
|
|
455
486
|
}
|
|
456
|
-
else
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
else {
|
|
465
|
-
console.warn('Object value must has an id property when the autoIncrementId is false');
|
|
466
|
-
break;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
else {
|
|
470
|
-
newId = this.maxId + 1;
|
|
471
|
-
this._setMaxId(newId);
|
|
472
|
-
}
|
|
473
|
-
inserted.push(this.add(newId, item, count));
|
|
474
|
-
map.delete(item);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
inserted.push(this.add(++this._maxId, item, 1));
|
|
487
|
+
else {
|
|
488
|
+
console.warn(nodeOrId, " is not added");
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
if (this.isMergeDuplicatedVal) {
|
|
492
|
+
if (map.has(nodeOrId)) {
|
|
493
|
+
inserted.push(this.add(newId, nodeOrId, count));
|
|
494
|
+
map.delete(nodeOrId);
|
|
479
495
|
}
|
|
480
496
|
}
|
|
481
|
-
else
|
|
482
|
-
inserted.push(this.add(
|
|
497
|
+
else {
|
|
498
|
+
inserted.push(this.add(newId, nodeOrId, 1));
|
|
483
499
|
}
|
|
500
|
+
this._setMaxId(newId);
|
|
484
501
|
}
|
|
485
502
|
}
|
|
486
503
|
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
@@ -504,62 +521,76 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
504
521
|
return data.length === this.addMany(data).length;
|
|
505
522
|
};
|
|
506
523
|
/**
|
|
507
|
-
* The function removes a node from a binary tree and returns
|
|
508
|
-
*
|
|
509
|
-
*
|
|
524
|
+
* The `remove` function removes a node from a binary search tree and returns the deleted node along with the parent
|
|
525
|
+
* node that needs to be balanced.
|
|
526
|
+
* @param {N | BinaryTreeNodeId | null} nodeOrId - The `nodeOrId` parameter can be one of the following:
|
|
510
527
|
* @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
|
|
511
528
|
* whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will
|
|
512
|
-
* not be
|
|
513
|
-
* @returns
|
|
514
|
-
* "needBalanced". The "deleted" property contains the deleted node or undefined if no node was deleted. The
|
|
515
|
-
* "needBalanced" property is always null.
|
|
529
|
+
* not be taken into account when removing it. If `ignoreCount` is set to `false
|
|
530
|
+
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
|
|
516
531
|
*/
|
|
517
|
-
AbstractBinaryTree.prototype.remove = function (
|
|
518
|
-
var
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
532
|
+
AbstractBinaryTree.prototype.remove = function (nodeOrId, ignoreCount) {
|
|
533
|
+
var bstDeletedResult = [];
|
|
534
|
+
if (!this.root)
|
|
535
|
+
return bstDeletedResult;
|
|
536
|
+
var curr = (typeof nodeOrId === 'number') ? this.get(nodeOrId) : nodeOrId;
|
|
537
|
+
if (!curr)
|
|
538
|
+
return bstDeletedResult;
|
|
539
|
+
var parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
|
|
540
|
+
var needBalanced = null, orgCurrent = curr;
|
|
541
|
+
if (curr.count > 1 && !ignoreCount) {
|
|
542
|
+
curr.count--;
|
|
524
543
|
this._setCount(this.count - 1);
|
|
525
544
|
}
|
|
526
|
-
else
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
this._setSize(this.size - subSize);
|
|
537
|
-
this._setCount(this.count - subCount);
|
|
538
|
-
node.parent.left = null;
|
|
545
|
+
else {
|
|
546
|
+
if (!curr.left) {
|
|
547
|
+
if (!parent) {
|
|
548
|
+
if (curr.right !== undefined)
|
|
549
|
+
this._setRoot(curr.right);
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
var fp = curr.familyPosition;
|
|
553
|
+
if (fp === types_1.FamilyPosition.LEFT || fp === types_1.FamilyPosition.ROOT_LEFT) {
|
|
554
|
+
parent.left = curr.right;
|
|
539
555
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
if (node.parent) {
|
|
543
|
-
this._setSize(this.size - subSize);
|
|
544
|
-
this._setCount(this.count - subCount);
|
|
545
|
-
node.parent.right = null;
|
|
556
|
+
else if (fp === types_1.FamilyPosition.RIGHT || fp === types_1.FamilyPosition.ROOT_RIGHT) {
|
|
557
|
+
parent.right = curr.right;
|
|
546
558
|
}
|
|
547
|
-
|
|
559
|
+
needBalanced = parent;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
var leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
|
|
564
|
+
if (leftSubTreeRightMost) {
|
|
565
|
+
var parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
566
|
+
orgCurrent = curr.swapLocation(leftSubTreeRightMost);
|
|
567
|
+
if (parentOfLeftSubTreeMax) {
|
|
568
|
+
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
|
|
569
|
+
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
570
|
+
else
|
|
571
|
+
parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
572
|
+
needBalanced = parentOfLeftSubTreeMax;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
548
575
|
}
|
|
576
|
+
this._setSize(this.size - 1);
|
|
577
|
+
this._setCount(this.count - orgCurrent.count);
|
|
549
578
|
}
|
|
550
|
-
|
|
579
|
+
bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
|
|
580
|
+
return bstDeletedResult;
|
|
551
581
|
};
|
|
552
582
|
/**
|
|
553
|
-
* The function calculates the depth of a
|
|
554
|
-
* @param
|
|
555
|
-
*
|
|
556
|
-
* @returns The depth of the given binary tree node.
|
|
583
|
+
* The function calculates the depth of a node in a binary tree.
|
|
584
|
+
* @param {N | BinaryTreeNodeId | null} beginRoot - The `beginRoot` parameter can be one of the following:
|
|
585
|
+
* @returns the depth of the given node or binary tree.
|
|
557
586
|
*/
|
|
558
|
-
AbstractBinaryTree.prototype.getDepth = function (
|
|
587
|
+
AbstractBinaryTree.prototype.getDepth = function (beginRoot) {
|
|
588
|
+
if (typeof beginRoot === 'number')
|
|
589
|
+
beginRoot = this.get(beginRoot, 'id');
|
|
559
590
|
var depth = 0;
|
|
560
|
-
while (
|
|
591
|
+
while (beginRoot === null || beginRoot === void 0 ? void 0 : beginRoot.parent) {
|
|
561
592
|
depth++;
|
|
562
|
-
|
|
593
|
+
beginRoot = beginRoot.parent;
|
|
563
594
|
}
|
|
564
595
|
return depth;
|
|
565
596
|
};
|
|
@@ -574,6 +605,8 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
574
605
|
AbstractBinaryTree.prototype.getHeight = function (beginRoot) {
|
|
575
606
|
var _a, _b, _c;
|
|
576
607
|
beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
|
|
608
|
+
if (typeof beginRoot === 'number')
|
|
609
|
+
beginRoot = this.get(beginRoot, 'id');
|
|
577
610
|
if (!beginRoot)
|
|
578
611
|
return -1;
|
|
579
612
|
if (this._loopType === types_1.LoopType.RECURSIVE) {
|
|
@@ -762,24 +795,28 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
762
795
|
return result;
|
|
763
796
|
};
|
|
764
797
|
/**
|
|
765
|
-
* The `getLeftMost` function returns the leftmost node in a binary tree,
|
|
766
|
-
*
|
|
767
|
-
* @param {N | null} [
|
|
768
|
-
*
|
|
769
|
-
*
|
|
770
|
-
* @returns The `getLeftMost`
|
|
798
|
+
* The `getLeftMost` function returns the leftmost node in a binary tree, starting from a specified node or the root if
|
|
799
|
+
* no node is specified.
|
|
800
|
+
* @param {N | BinaryTreeNodeId | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
|
|
801
|
+
* generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
|
|
802
|
+
* node), or `null`.
|
|
803
|
+
* @returns The function `getLeftMost` returns the leftmost node in a binary tree. If the `beginRoot` parameter is
|
|
804
|
+
* provided, it starts the traversal from that node. If `beginRoot` is not provided or is `null`, it starts the
|
|
805
|
+
* traversal from the root of the binary tree. If there are no nodes in the binary tree, it returns `null`.
|
|
771
806
|
*/
|
|
772
|
-
AbstractBinaryTree.prototype.getLeftMost = function (
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
807
|
+
AbstractBinaryTree.prototype.getLeftMost = function (beginRoot) {
|
|
808
|
+
if (typeof beginRoot === 'number')
|
|
809
|
+
beginRoot = this.get(beginRoot, 'id');
|
|
810
|
+
beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
|
|
811
|
+
if (!beginRoot)
|
|
812
|
+
return beginRoot;
|
|
776
813
|
if (this._loopType === types_1.LoopType.RECURSIVE) {
|
|
777
814
|
var _traverse_2 = function (cur) {
|
|
778
815
|
if (!cur.left)
|
|
779
816
|
return cur;
|
|
780
817
|
return _traverse_2(cur.left);
|
|
781
818
|
};
|
|
782
|
-
return _traverse_2(
|
|
819
|
+
return _traverse_2(beginRoot);
|
|
783
820
|
}
|
|
784
821
|
else {
|
|
785
822
|
// Indirect implementation of iteration using tail recursion optimization
|
|
@@ -788,7 +825,7 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
788
825
|
return cur;
|
|
789
826
|
return _traverse_3.cont(cur.left);
|
|
790
827
|
});
|
|
791
|
-
return _traverse_3(
|
|
828
|
+
return _traverse_3(beginRoot);
|
|
792
829
|
}
|
|
793
830
|
};
|
|
794
831
|
/**
|
|
@@ -827,6 +864,7 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
827
864
|
* @returns a boolean value.
|
|
828
865
|
*/
|
|
829
866
|
AbstractBinaryTree.prototype.isBSTByRooted = function (node) {
|
|
867
|
+
// TODO there is a bug
|
|
830
868
|
if (!node)
|
|
831
869
|
return true;
|
|
832
870
|
if (this._loopType === types_1.LoopType.RECURSIVE) {
|
|
@@ -912,6 +950,8 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
912
950
|
*/
|
|
913
951
|
AbstractBinaryTree.prototype.subTreeSum = function (subTreeRoot, propertyName) {
|
|
914
952
|
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
953
|
+
if (typeof subTreeRoot === 'number')
|
|
954
|
+
subTreeRoot = this.get(subTreeRoot, 'id');
|
|
915
955
|
if (!subTreeRoot)
|
|
916
956
|
return 0;
|
|
917
957
|
var sum = 0;
|
|
@@ -953,17 +993,21 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
953
993
|
return sum;
|
|
954
994
|
};
|
|
955
995
|
/**
|
|
956
|
-
* The function `subTreeAdd` adds a
|
|
957
|
-
* @param subTreeRoot - The `subTreeRoot` parameter
|
|
996
|
+
* The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
|
|
997
|
+
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
|
|
998
|
+
* tree or the ID of a binary tree node. It can also be `null` if there is no subtree root.
|
|
958
999
|
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
|
|
959
|
-
* each node in the subtree should be
|
|
1000
|
+
* each node in the subtree should be incremented or decremented.
|
|
960
1001
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
961
|
-
* specifies the property of the
|
|
962
|
-
*
|
|
1002
|
+
* specifies the property of the binary tree node that should be modified. It can be either 'id' or 'count'. If no
|
|
1003
|
+
* value is provided for `propertyName`, it defaults to 'id'.
|
|
1004
|
+
* @returns a boolean value.
|
|
963
1005
|
*/
|
|
964
1006
|
AbstractBinaryTree.prototype.subTreeAdd = function (subTreeRoot, delta, propertyName) {
|
|
965
1007
|
var _this = this;
|
|
966
1008
|
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
1009
|
+
if (typeof subTreeRoot === 'number')
|
|
1010
|
+
subTreeRoot = this.get(subTreeRoot, 'id');
|
|
967
1011
|
if (!subTreeRoot)
|
|
968
1012
|
return false;
|
|
969
1013
|
var _addByProperty = function (cur) {
|
|
@@ -1356,12 +1400,11 @@ var AbstractBinaryTree = /** @class */ (function () {
|
|
|
1356
1400
|
this._maxId = value;
|
|
1357
1401
|
};
|
|
1358
1402
|
AbstractBinaryTree.prototype._setIsDuplicatedVal = function (value) {
|
|
1359
|
-
this.
|
|
1403
|
+
this._isMergeDuplicatedVal = value;
|
|
1360
1404
|
};
|
|
1361
1405
|
AbstractBinaryTree.prototype._setRoot = function (v) {
|
|
1362
1406
|
if (v) {
|
|
1363
|
-
v.parent =
|
|
1364
|
-
v.familyPosition = types_1.FamilyPosition.ROOT;
|
|
1407
|
+
v.parent = undefined;
|
|
1365
1408
|
}
|
|
1366
1409
|
this._root = v;
|
|
1367
1410
|
};
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
|
-
import type { AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId
|
|
9
|
+
import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId } from '../types';
|
|
10
10
|
import { IAVLTree, IAVLTreeNode } from '../interfaces';
|
|
11
|
-
export declare class AVLTreeNode<T, FAMILY extends AVLTreeNode<T, FAMILY> =
|
|
11
|
+
export declare class AVLTreeNode<T = any, FAMILY extends AVLTreeNode<T, FAMILY> = AVLTreeNodeNested<T>> extends BSTNode<T, FAMILY> implements IAVLTreeNode<T, FAMILY> {
|
|
12
12
|
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
13
13
|
}
|
|
14
|
-
export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode
|
|
14
|
+
export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends BST<N> implements IAVLTree<N> {
|
|
15
15
|
constructor(options?: AVLTreeOptions);
|
|
16
16
|
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
17
17
|
/**
|
|
@@ -26,7 +26,7 @@ export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode<nu
|
|
|
26
26
|
* to `1`, indicating that the value should be inserted once.
|
|
27
27
|
* @returns The method is returning either an N object or null.
|
|
28
28
|
*/
|
|
29
|
-
add(id: BinaryTreeNodeId, val
|
|
29
|
+
add(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null;
|
|
30
30
|
/**
|
|
31
31
|
* The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and
|
|
32
32
|
* then balances the tree if necessary.
|
|
@@ -41,7 +41,7 @@ var AVLTreeNode = /** @class */ (function (_super) {
|
|
|
41
41
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
42
42
|
}
|
|
43
43
|
AVLTreeNode.prototype.createNode = function (id, val, count) {
|
|
44
|
-
return new AVLTreeNode(id,
|
|
44
|
+
return new AVLTreeNode(id, val, count);
|
|
45
45
|
};
|
|
46
46
|
return AVLTreeNode;
|
|
47
47
|
}(bst_1.BSTNode));
|
|
@@ -52,7 +52,7 @@ var AVLTree = /** @class */ (function (_super) {
|
|
|
52
52
|
return _super.call(this, options) || this;
|
|
53
53
|
}
|
|
54
54
|
AVLTree.prototype.createNode = function (id, val, count) {
|
|
55
|
-
return new AVLTreeNode(id,
|
|
55
|
+
return new AVLTreeNode(id, val, count);
|
|
56
56
|
};
|
|
57
57
|
/**
|
|
58
58
|
* The function overrides the add method of a Binary Search Tree to insert a node with a given id and value, and then
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeNodeId,
|
|
8
|
+
import type { BinaryTreeNodeId, BinaryTreeNodeNested } from '../types';
|
|
9
9
|
import { BinaryTreeOptions } from '../types';
|
|
10
10
|
import { AbstractBinaryTree, AbstractBinaryTreeNode } from './abstract-binary-tree';
|
|
11
11
|
import { IBinaryTree, IBinaryTreeNode } from '../interfaces/binary-tree';
|
|
12
|
-
export declare class BinaryTreeNode<T =
|
|
12
|
+
export declare class BinaryTreeNode<T = any, FAMILY extends BinaryTreeNode<T, FAMILY> = BinaryTreeNodeNested<T>> extends AbstractBinaryTreeNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
|
|
13
13
|
/**
|
|
14
14
|
* The function creates a new binary tree node with an optional value and count, and returns it as a specified type.
|
|
15
15
|
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
|
|
@@ -25,7 +25,7 @@ export declare class BinaryTreeNode<T = number, FAMILY extends BinaryTreeNode<T,
|
|
|
25
25
|
export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode> extends AbstractBinaryTree<N> implements IBinaryTree<N> {
|
|
26
26
|
/**
|
|
27
27
|
* The constructor function accepts an optional options object and sets the values of loopType, autoIncrementId, and
|
|
28
|
-
*
|
|
28
|
+
* isMergeDuplicatedVal based on the provided options.
|
|
29
29
|
* @param [options] - An optional object that can contain the following properties:
|
|
30
30
|
*/
|
|
31
31
|
constructor(options?: BinaryTreeOptions);
|
|
@@ -40,7 +40,7 @@ var BinaryTreeNode = /** @class */ (function (_super) {
|
|
|
40
40
|
* @returns a new instance of the BinaryTreeNode class, casted as the FAMILY type.
|
|
41
41
|
*/
|
|
42
42
|
BinaryTreeNode.prototype.createNode = function (id, val, count) {
|
|
43
|
-
return new BinaryTreeNode(id,
|
|
43
|
+
return new BinaryTreeNode(id, val, count);
|
|
44
44
|
};
|
|
45
45
|
return BinaryTreeNode;
|
|
46
46
|
}(abstract_binary_tree_1.AbstractBinaryTreeNode));
|
|
@@ -49,11 +49,11 @@ var BinaryTree = /** @class */ (function (_super) {
|
|
|
49
49
|
__extends(BinaryTree, _super);
|
|
50
50
|
/**
|
|
51
51
|
* The constructor function accepts an optional options object and sets the values of loopType, autoIncrementId, and
|
|
52
|
-
*
|
|
52
|
+
* isMergeDuplicatedVal based on the provided options.
|
|
53
53
|
* @param [options] - An optional object that can contain the following properties:
|
|
54
54
|
*/
|
|
55
55
|
function BinaryTree(options) {
|
|
56
|
-
return _super.call(this) || this;
|
|
56
|
+
return _super.call(this, options) || this;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* The function creates a new binary tree node with the given id, value, and count if the value is not null, otherwise
|
|
@@ -67,7 +67,7 @@ var BinaryTree = /** @class */ (function (_super) {
|
|
|
67
67
|
* @returns a BinaryTreeNode object if the value is not null, otherwise it returns null.
|
|
68
68
|
*/
|
|
69
69
|
BinaryTree.prototype.createNode = function (id, val, count) {
|
|
70
|
-
return new BinaryTreeNode(id, val
|
|
70
|
+
return new BinaryTreeNode(id, val, count);
|
|
71
71
|
};
|
|
72
72
|
return BinaryTree;
|
|
73
73
|
}(abstract_binary_tree_1.AbstractBinaryTree));
|