data-structure-typed 1.18.0 → 1.18.5
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 +193 -66
- 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 +3 -0
- package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +288 -0
- package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +3 -0
- package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +78 -0
- package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +1502 -0
- package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +503 -0
- 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 +11 -0
- package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +110 -0
- package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +243 -0
- package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +3 -0
- package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +55 -0
- package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +3 -0
- package/backup/recursive-type/src/data-structures/diagrams/README.md +5 -0
- package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +985 -0
- 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 +478 -0
- package/backup/recursive-type/src/data-structures/graph/index.ts +3 -0
- package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +293 -0
- package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +67 -0
- package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +56 -0
- package/backup/recursive-type/src/data-structures/hash/hash-table.ts +3 -0
- package/backup/recursive-type/src/data-structures/hash/index.ts +6 -0
- package/backup/recursive-type/src/data-structures/hash/pair.ts +3 -0
- package/backup/recursive-type/src/data-structures/hash/tree-map.ts +3 -0
- package/backup/recursive-type/src/data-structures/hash/tree-set.ts +3 -0
- package/backup/recursive-type/src/data-structures/heap/heap.ts +176 -0
- package/backup/recursive-type/src/data-structures/heap/index.ts +3 -0
- package/backup/recursive-type/src/data-structures/heap/max-heap.ts +31 -0
- package/backup/recursive-type/src/data-structures/heap/min-heap.ts +34 -0
- package/backup/recursive-type/src/data-structures/index.ts +15 -0
- package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +42 -0
- package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +56 -0
- package/backup/recursive-type/src/data-structures/interfaces/bst.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +15 -0
- package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/heap.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/index.ts +13 -0
- package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +1 -0
- package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +3 -0
- package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +573 -0
- package/backup/recursive-type/src/data-structures/linked-list/index.ts +3 -0
- package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +490 -0
- package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +3 -0
- package/backup/recursive-type/src/data-structures/matrix/index.ts +4 -0
- package/backup/recursive-type/src/data-structures/matrix/matrix.ts +27 -0
- package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +208 -0
- package/backup/recursive-type/src/data-structures/matrix/navigator.ts +122 -0
- package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +316 -0
- package/backup/recursive-type/src/data-structures/priority-queue/index.ts +3 -0
- package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +49 -0
- package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +50 -0
- package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +354 -0
- package/backup/recursive-type/src/data-structures/queue/deque.ts +251 -0
- package/backup/recursive-type/src/data-structures/queue/index.ts +2 -0
- package/backup/recursive-type/src/data-structures/queue/queue.ts +120 -0
- package/backup/recursive-type/src/data-structures/stack/index.ts +1 -0
- package/backup/recursive-type/src/data-structures/stack/stack.ts +98 -0
- package/backup/recursive-type/src/data-structures/tree/index.ts +1 -0
- package/backup/recursive-type/src/data-structures/tree/tree.ts +80 -0
- package/backup/recursive-type/src/data-structures/trie/index.ts +1 -0
- package/backup/recursive-type/src/data-structures/trie/trie.ts +227 -0
- package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +5 -0
- package/backup/recursive-type/src/data-structures/types/avl-tree.ts +8 -0
- package/backup/recursive-type/src/data-structures/types/binary-tree.ts +10 -0
- package/backup/recursive-type/src/data-structures/types/bst.ts +6 -0
- package/backup/recursive-type/src/data-structures/types/directed-graph.ts +8 -0
- package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/backup/recursive-type/src/data-structures/types/heap.ts +5 -0
- package/backup/recursive-type/src/data-structures/types/index.ts +12 -0
- package/backup/recursive-type/src/data-structures/types/navigator.ts +13 -0
- package/backup/recursive-type/src/data-structures/types/priority-queue.ts +9 -0
- package/backup/recursive-type/src/data-structures/types/segment-tree.ts +1 -0
- package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +1 -0
- package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +1 -0
- package/backup/recursive-type/src/index.ts +1 -0
- package/backup/recursive-type/src/utils/index.ts +2 -0
- package/backup/recursive-type/src/utils/types/index.ts +1 -0
- package/backup/recursive-type/src/utils/types/utils.ts +6 -0
- package/backup/recursive-type/src/utils/utils.ts +78 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +19 -25
- package/dist/data-structures/binary-tree/avl-tree.js +8 -16
- package/dist/data-structures/binary-tree/binary-tree.d.ts +99 -98
- package/dist/data-structures/binary-tree/binary-tree.js +70 -65
- package/dist/data-structures/binary-tree/bst.d.ts +21 -21
- package/dist/data-structures/binary-tree/bst.js +15 -17
- package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -2
- package/dist/data-structures/binary-tree/rb-tree.js +68 -5
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +9 -8
- package/dist/data-structures/binary-tree/tree-multiset.js +7 -6
- package/dist/data-structures/graph/abstract-graph.d.ts +56 -58
- package/dist/data-structures/graph/abstract-graph.js +84 -68
- package/dist/data-structures/graph/directed-graph.d.ts +127 -96
- package/dist/data-structures/graph/directed-graph.js +161 -109
- package/dist/data-structures/graph/undirected-graph.d.ts +82 -59
- package/dist/data-structures/graph/undirected-graph.js +99 -72
- package/dist/data-structures/hash/coordinate-set.d.ts +1 -1
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/interfaces/abstract-graph.d.ts +22 -0
- package/dist/data-structures/interfaces/abstract-graph.js +2 -0
- package/dist/data-structures/interfaces/avl-tree.d.ts +1 -0
- package/dist/data-structures/interfaces/avl-tree.js +2 -0
- package/dist/data-structures/interfaces/binary-tree.d.ts +27 -0
- package/dist/data-structures/interfaces/binary-tree.js +2 -0
- package/dist/data-structures/interfaces/bst.d.ts +1 -0
- package/dist/data-structures/interfaces/bst.js +2 -0
- package/dist/data-structures/interfaces/directed-graph.d.ts +9 -0
- package/dist/data-structures/interfaces/directed-graph.js +2 -0
- package/dist/data-structures/interfaces/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/interfaces/doubly-linked-list.js +2 -0
- package/dist/data-structures/interfaces/heap.d.ts +1 -0
- package/dist/data-structures/interfaces/heap.js +2 -0
- package/dist/data-structures/interfaces/index.d.ts +13 -0
- package/dist/data-structures/interfaces/index.js +29 -0
- package/dist/data-structures/interfaces/navigator.d.ts +1 -0
- package/dist/data-structures/interfaces/navigator.js +2 -0
- package/dist/data-structures/interfaces/priority-queue.d.ts +1 -0
- package/dist/data-structures/interfaces/priority-queue.js +2 -0
- package/dist/data-structures/interfaces/segment-tree.d.ts +1 -0
- package/dist/data-structures/interfaces/segment-tree.js +2 -0
- package/dist/data-structures/interfaces/singly-linked-list.d.ts +1 -0
- package/dist/data-structures/interfaces/singly-linked-list.js +2 -0
- package/dist/data-structures/interfaces/tree-multiset.d.ts +1 -0
- package/dist/data-structures/interfaces/tree-multiset.js +2 -0
- package/dist/data-structures/interfaces/undirected-graph.d.ts +2 -0
- package/dist/data-structures/interfaces/undirected-graph.js +2 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -1
- package/dist/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/data-structures/priority-queue/priority-queue.js +4 -4
- package/dist/data-structures/queue/deque.d.ts +5 -5
- package/dist/data-structures/queue/deque.js +6 -6
- package/dist/data-structures/queue/queue.d.ts +1 -1
- package/dist/data-structures/stack/stack.d.ts +1 -1
- package/dist/data-structures/types/abstract-graph.d.ts +1 -20
- package/dist/data-structures/types/avl-tree.d.ts +5 -4
- package/dist/data-structures/types/binary-tree.d.ts +6 -5
- package/dist/data-structures/types/bst.d.ts +4 -3
- package/dist/data-structures/types/directed-graph.d.ts +5 -9
- package/dist/data-structures/types/directed-graph.js +7 -0
- package/dist/data-structures/types/heap.d.ts +2 -2
- package/dist/data-structures/types/index.d.ts +0 -1
- package/dist/data-structures/types/index.js +0 -1
- package/dist/data-structures/types/navigator.d.ts +2 -2
- package/dist/data-structures/types/priority-queue.d.ts +2 -2
- package/dist/data-structures/types/tree-multiset.d.ts +3 -4
- package/docs/assets/search.js +1 -1
- package/docs/classes/AVLTree.html +288 -287
- package/docs/classes/AVLTreeNode.html +106 -63
- package/docs/classes/AaTree.html +14 -12
- package/docs/classes/AbstractEdge.html +68 -34
- package/docs/classes/AbstractGraph.html +219 -114
- package/docs/classes/AbstractVertex.html +71 -30
- package/docs/classes/ArrayDeque.html +27 -25
- package/docs/classes/BST.html +279 -273
- package/docs/classes/BSTNode.html +106 -57
- package/docs/classes/BTree.html +14 -12
- package/docs/classes/BinaryIndexedTree.html +22 -20
- package/docs/classes/BinaryTree.html +283 -277
- package/docs/classes/BinaryTreeNode.html +111 -63
- package/docs/classes/Character.html +17 -15
- package/docs/classes/CoordinateMap.html +22 -20
- package/docs/classes/CoordinateSet.html +23 -21
- package/docs/classes/Deque.html +47 -45
- package/docs/classes/DirectedEdge.html +74 -41
- package/docs/classes/DirectedGraph.html +444 -208
- package/docs/classes/DirectedVertex.html +63 -36
- package/docs/classes/DoublyLinkedList.html +52 -50
- package/docs/classes/DoublyLinkedListNode.html +24 -22
- package/docs/classes/HashTable.html +14 -12
- package/docs/classes/Heap.html +29 -27
- package/docs/classes/HeapItem.html +21 -19
- package/docs/classes/Matrix2D.html +29 -27
- package/docs/classes/MatrixNTI2D.html +17 -15
- package/docs/classes/MaxHeap.html +29 -27
- package/docs/classes/MaxPriorityQueue.html +67 -60
- package/docs/classes/MinHeap.html +29 -27
- package/docs/classes/MinPriorityQueue.html +67 -60
- package/docs/classes/Navigator.html +24 -22
- package/docs/classes/ObjectDeque.html +62 -50
- package/docs/classes/Pair.html +14 -12
- package/docs/classes/PriorityQueue.html +62 -55
- package/docs/classes/Queue.html +29 -27
- package/docs/classes/SegmentTree.html +30 -28
- package/docs/classes/SegmentTreeNode.html +33 -31
- package/docs/classes/SinglyLinkedList.html +49 -47
- package/docs/classes/SinglyLinkedListNode.html +21 -19
- package/docs/classes/SkipLinkedList.html +14 -12
- package/docs/classes/SplayTree.html +14 -12
- package/docs/classes/Stack.html +27 -25
- package/docs/classes/TreeMap.html +14 -12
- package/docs/classes/TreeMultiSet.html +277 -270
- package/docs/classes/TreeNode.html +29 -27
- package/docs/classes/TreeSet.html +14 -12
- package/docs/classes/Trie.html +26 -24
- package/docs/classes/TrieNode.html +24 -22
- package/docs/classes/TwoThreeTree.html +14 -12
- package/docs/classes/UndirectedEdge.html +70 -51
- package/docs/classes/UndirectedGraph.html +344 -161
- package/docs/classes/UndirectedVertex.html +63 -36
- package/docs/classes/Vector2D.html +41 -39
- package/docs/enums/CP.html +17 -15
- package/docs/enums/FamilyPosition.html +17 -15
- package/docs/enums/LoopType.html +16 -14
- package/docs/{interfaces/AVLTreeDeleted.html → enums/TopologicalProperty.html} +43 -43
- package/docs/index.html +195 -68
- package/docs/interfaces/{HeapOptions.html → IBinaryTree.html} +39 -32
- package/docs/interfaces/IBinaryTreeNode.html +383 -0
- package/docs/interfaces/IDirectedGraph.html +20 -18
- package/docs/interfaces/IGraph.html +118 -88
- package/docs/interfaces/{PriorityQueueOptions.html → IUNDirectedGraph.html} +22 -53
- package/docs/modules.html +25 -21
- package/docs/types/{ToThunkFn.html → AVLTreeDeleted.html} +27 -21
- package/docs/types/BSTComparator.html +14 -12
- package/docs/types/BSTDeletedResult.html +19 -17
- package/docs/types/BinaryTreeDeleted.html +19 -17
- package/docs/types/BinaryTreeNodeId.html +14 -12
- package/docs/types/BinaryTreeNodePropertyName.html +14 -12
- package/docs/types/DFSOrderPattern.html +14 -12
- package/docs/types/DijkstraResult.html +14 -12
- package/docs/types/Direction.html +14 -12
- package/docs/types/{TrlFn.html → EdgeId.html} +18 -29
- package/docs/types/{TrlAsyncFn.html → HeapOptions.html} +29 -19
- package/docs/types/NavigatorParams.html +164 -0
- package/docs/types/NodeOrPropertyName.html +14 -12
- package/docs/types/PriorityQueueComparator.html +14 -12
- package/docs/types/PriorityQueueDFSOrderPattern.html +14 -12
- package/docs/types/{SpecifyOptional.html → PriorityQueueOptions.html} +28 -19
- package/docs/types/RecursiveAVLTreeNode.html +135 -0
- package/docs/types/{Thunk.html → RecursiveBSTNode.html} +23 -24
- package/docs/types/RecursiveBinaryTreeNode.html +135 -0
- package/docs/types/ResultByProperty.html +17 -15
- package/docs/types/ResultsByProperty.html +17 -15
- package/docs/types/SegmentTreeNodeVal.html +14 -12
- package/docs/types/TopologicalStatus.html +14 -12
- package/docs/types/TreeMultiSetDeletedResult.html +19 -17
- package/docs/types/Turning.html +14 -12
- package/docs/types/VertexId.html +14 -12
- package/notes/note.md +8 -1
- package/package.json +10 -2
- package/docs/classes/RBTree.html +0 -153
- package/docs/interfaces/NavigatorParams.html +0 -200
|
@@ -151,24 +151,29 @@ var BinaryTreeNode = /** @class */ (function () {
|
|
|
151
151
|
enumerable: false,
|
|
152
152
|
configurable: true
|
|
153
153
|
});
|
|
154
|
+
BinaryTreeNode.prototype._createNode = function (id, val, count) {
|
|
155
|
+
return val !== null ? new BinaryTreeNode(id, val, count) : null;
|
|
156
|
+
};
|
|
154
157
|
BinaryTreeNode.prototype.swapLocation = function (swapNode) {
|
|
155
158
|
var val = swapNode.val, count = swapNode.count, height = swapNode.height;
|
|
156
|
-
var tempNode =
|
|
157
|
-
tempNode
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
159
|
+
var tempNode = this._createNode(swapNode.id, val);
|
|
160
|
+
if (tempNode instanceof BinaryTreeNode) {
|
|
161
|
+
tempNode.val = val;
|
|
162
|
+
tempNode.count = count;
|
|
163
|
+
tempNode.height = height;
|
|
164
|
+
swapNode.id = this.id;
|
|
165
|
+
swapNode.val = this.val;
|
|
166
|
+
swapNode.count = this.count;
|
|
167
|
+
swapNode.height = this.height;
|
|
168
|
+
this.id = tempNode.id;
|
|
169
|
+
this.val = tempNode.val;
|
|
170
|
+
this.count = tempNode.count;
|
|
171
|
+
this.height = tempNode.height;
|
|
172
|
+
}
|
|
168
173
|
return swapNode;
|
|
169
174
|
};
|
|
170
175
|
BinaryTreeNode.prototype.clone = function () {
|
|
171
|
-
return
|
|
176
|
+
return this._createNode(this.id, this.val, this.count);
|
|
172
177
|
};
|
|
173
178
|
return BinaryTreeNode;
|
|
174
179
|
}());
|
|
@@ -284,19 +289,19 @@ var BinaryTree = /** @class */ (function () {
|
|
|
284
289
|
configurable: true
|
|
285
290
|
});
|
|
286
291
|
/**
|
|
287
|
-
* The function creates a new binary tree node with the given id, value, and count
|
|
288
|
-
* null.
|
|
292
|
+
* The function creates a new binary tree node with the given id, value, and count if the value is not null, otherwise
|
|
293
|
+
* it returns null.
|
|
289
294
|
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
|
|
290
|
-
* `BinaryTreeNodeId
|
|
291
|
-
* @param {
|
|
292
|
-
*
|
|
293
|
-
* @param {number} [count] - The count parameter is an optional parameter
|
|
294
|
-
* the value in the binary tree node.
|
|
295
|
-
* @returns
|
|
296
|
-
* Otherwise, it returns null.
|
|
295
|
+
* `BinaryTreeNodeId`.
|
|
296
|
+
* @param {N | null} val - The `val` parameter represents the value of the node. It can be of type `N` (generic type)
|
|
297
|
+
* or `null`.
|
|
298
|
+
* @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
|
|
299
|
+
* of occurrences of the value in the binary tree node. If not provided, the default value is `undefined`.
|
|
300
|
+
* @returns a BinaryTreeNode object if the value is not null, otherwise it returns null.
|
|
297
301
|
*/
|
|
298
|
-
BinaryTree.prototype.
|
|
299
|
-
|
|
302
|
+
BinaryTree.prototype._createNode = function (id, val, count) {
|
|
303
|
+
var node = new BinaryTreeNode(id, val, count);
|
|
304
|
+
return node;
|
|
300
305
|
};
|
|
301
306
|
/**
|
|
302
307
|
* The clear function resets the state of an object by setting its properties to their initial values.
|
|
@@ -319,10 +324,10 @@ var BinaryTree = /** @class */ (function () {
|
|
|
319
324
|
* already exists.
|
|
320
325
|
* @param {BinaryTreeNodeId} id - The id parameter is the identifier of the binary tree node. It is used to uniquely
|
|
321
326
|
* identify each node in the binary tree.
|
|
322
|
-
* @param {
|
|
327
|
+
* @param {N} val - The value to be inserted into the binary tree.
|
|
323
328
|
* @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
|
|
324
329
|
* value should be inserted into the binary tree. If not provided, it defaults to 1.
|
|
325
|
-
* @returns The function `add` returns a `
|
|
330
|
+
* @returns The function `add` returns a `N` object if a new node is inserted, or `null` if no new node
|
|
326
331
|
* is inserted, or `undefined` if the insertion fails.
|
|
327
332
|
*/
|
|
328
333
|
BinaryTree.prototype.add = function (id, val, count) {
|
|
@@ -347,7 +352,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
347
352
|
return;
|
|
348
353
|
};
|
|
349
354
|
var inserted;
|
|
350
|
-
var needInsert = val !== null ?
|
|
355
|
+
var needInsert = val !== null ? this._createNode(id, val, count) : null;
|
|
351
356
|
var existNode = val !== null ? this.get(id, 'id') : null;
|
|
352
357
|
if (this.root) {
|
|
353
358
|
if (existNode) {
|
|
@@ -363,7 +368,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
363
368
|
}
|
|
364
369
|
}
|
|
365
370
|
else {
|
|
366
|
-
this._setRoot(val !== null ?
|
|
371
|
+
this._setRoot(val !== null ? this._createNode(id, val, count) : null);
|
|
367
372
|
if (needInsert !== null) {
|
|
368
373
|
this._setSize(1);
|
|
369
374
|
this._setCount(count);
|
|
@@ -374,7 +379,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
374
379
|
};
|
|
375
380
|
/**
|
|
376
381
|
* The function inserts a new node into a binary tree as the left or right child of a given parent node.
|
|
377
|
-
* @param {
|
|
382
|
+
* @param {N | null} newNode - The `newNode` parameter is an instance of the `BinaryTreeNode` class or
|
|
378
383
|
* `null`. It represents the node that needs to be inserted into the binary tree.
|
|
379
384
|
* @param parent - The `parent` parameter is a BinaryTreeNode object representing the parent node to which the new node
|
|
380
385
|
* will be inserted as a child.
|
|
@@ -391,7 +396,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
391
396
|
parent.left = newNode;
|
|
392
397
|
if (newNode !== null) {
|
|
393
398
|
this._setSize(this.size + 1);
|
|
394
|
-
this._setCount((_a = this.count +
|
|
399
|
+
this._setCount((_a = this.count + newNode.count) !== null && _a !== void 0 ? _a : 0);
|
|
395
400
|
}
|
|
396
401
|
return parent.left;
|
|
397
402
|
}
|
|
@@ -403,7 +408,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
403
408
|
parent.right = newNode;
|
|
404
409
|
if (newNode !== null) {
|
|
405
410
|
this._setSize(this.size + 1);
|
|
406
|
-
this._setCount((_b = this.count +
|
|
411
|
+
this._setCount((_b = this.count + newNode.count) !== null && _b !== void 0 ? _b : 0);
|
|
407
412
|
}
|
|
408
413
|
return parent.right;
|
|
409
414
|
}
|
|
@@ -418,9 +423,9 @@ var BinaryTree = /** @class */ (function () {
|
|
|
418
423
|
/**
|
|
419
424
|
* The `addMany` function inserts multiple items into a binary tree and returns an array of the inserted nodes or
|
|
420
425
|
* null/undefined values.
|
|
421
|
-
* @param {
|
|
422
|
-
* array of `
|
|
423
|
-
* @returns The function `addMany` returns an array of `
|
|
426
|
+
* @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
|
|
427
|
+
* array of `N` objects.
|
|
428
|
+
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
424
429
|
*/
|
|
425
430
|
BinaryTree.prototype.addMany = function (data) {
|
|
426
431
|
var e_1, _a, e_2, _b;
|
|
@@ -490,8 +495,8 @@ var BinaryTree = /** @class */ (function () {
|
|
|
490
495
|
/**
|
|
491
496
|
* The `fill` function clears the current data and inserts new data, returning a boolean indicating if the insertion
|
|
492
497
|
* was successful.
|
|
493
|
-
* @param {
|
|
494
|
-
* array of `
|
|
498
|
+
* @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
|
|
499
|
+
* array of `N` objects.
|
|
495
500
|
* @returns The method is returning a boolean value.
|
|
496
501
|
*/
|
|
497
502
|
BinaryTree.prototype.fill = function (data) {
|
|
@@ -546,7 +551,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
546
551
|
};
|
|
547
552
|
/**
|
|
548
553
|
* The function calculates the depth of a binary tree node by traversing its parent nodes.
|
|
549
|
-
* @param node -
|
|
554
|
+
* @param node - N - This is the node for which we want to calculate the depth. It is a generic type,
|
|
550
555
|
* meaning it can represent any type of data that we want to store in the node.
|
|
551
556
|
* @returns The depth of the given binary tree node.
|
|
552
557
|
*/
|
|
@@ -561,8 +566,8 @@ var BinaryTree = /** @class */ (function () {
|
|
|
561
566
|
/**
|
|
562
567
|
* The `getHeight` function calculates the maximum height of a binary tree using either a recursive or iterative
|
|
563
568
|
* approach.
|
|
564
|
-
* @param {
|
|
565
|
-
* `
|
|
569
|
+
* @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
|
|
570
|
+
* `N | null`. It represents the starting node from which to calculate the height of the binary tree.
|
|
566
571
|
* If no value is provided for `beginRoot`, the function will use the `root` property of the class instance as
|
|
567
572
|
* @returns the height of the binary tree.
|
|
568
573
|
*/
|
|
@@ -612,8 +617,8 @@ var BinaryTree = /** @class */ (function () {
|
|
|
612
617
|
/**
|
|
613
618
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a recursive or iterative
|
|
614
619
|
* approach.
|
|
615
|
-
* @param {
|
|
616
|
-
* `
|
|
620
|
+
* @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
|
|
621
|
+
* `N | null`. It represents the starting node from which to calculate the minimum height of the binary
|
|
617
622
|
* tree. If no value is provided for `beginRoot`, the function will use the root node of the binary tree.
|
|
618
623
|
* @returns The function `getMinHeight` returns the minimum height of the binary tree.
|
|
619
624
|
*/
|
|
@@ -664,8 +669,8 @@ var BinaryTree = /** @class */ (function () {
|
|
|
664
669
|
};
|
|
665
670
|
/**
|
|
666
671
|
* The function checks if a binary tree is balanced by comparing the minimum height and the maximum height of the tree.
|
|
667
|
-
* @param {
|
|
668
|
-
* of type `
|
|
672
|
+
* @param {N | null} [beginRoot] - The `beginRoot` parameter is the root node of a binary tree. It is
|
|
673
|
+
* of type `N | null`, which means it can either be a `BinaryTreeNode` object or `null`.
|
|
669
674
|
* @returns The method is returning a boolean value.
|
|
670
675
|
*/
|
|
671
676
|
BinaryTree.prototype.isBalanced = function (beginRoot) {
|
|
@@ -674,14 +679,14 @@ var BinaryTree = /** @class */ (function () {
|
|
|
674
679
|
/**
|
|
675
680
|
* The function `getNodes` returns an array of binary tree nodes that match a given property value, with options for
|
|
676
681
|
* searching recursively or iteratively.
|
|
677
|
-
* @param {BinaryTreeNodeId |
|
|
678
|
-
* generic type `
|
|
682
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
683
|
+
* generic type `N`. It represents the property of the binary tree node that you want to search for.
|
|
679
684
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
680
685
|
* specifies the property name to use when searching for nodes. If not provided, it defaults to 'id'.
|
|
681
686
|
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
|
|
682
687
|
* return only one node that matches the `nodeProperty` or `propertyName` criteria. If `onlyOne` is set to `true`, the
|
|
683
688
|
* function will stop traversing the tree and return the first matching node. If `
|
|
684
|
-
* @returns The function `getNodes` returns an array of `
|
|
689
|
+
* @returns The function `getNodes` returns an array of `N | null | undefined` objects.
|
|
685
690
|
*/
|
|
686
691
|
BinaryTree.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {
|
|
687
692
|
var _this = this;
|
|
@@ -717,8 +722,8 @@ var BinaryTree = /** @class */ (function () {
|
|
|
717
722
|
/**
|
|
718
723
|
* The function checks if a binary tree node has a specific property or if any node in the tree has a specific
|
|
719
724
|
* property.
|
|
720
|
-
* @param {BinaryTreeNodeId |
|
|
721
|
-
* generic type `
|
|
725
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
726
|
+
* generic type `N`. It represents the property of a binary tree node that you want to check.
|
|
722
727
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
723
728
|
* specifies the name of the property to check for in the nodes.
|
|
724
729
|
* @returns a boolean value.
|
|
@@ -729,8 +734,8 @@ var BinaryTree = /** @class */ (function () {
|
|
|
729
734
|
/**
|
|
730
735
|
* The function returns the first binary tree node that matches the given property name and value, or null if no match
|
|
731
736
|
* is found.
|
|
732
|
-
* @param {BinaryTreeNodeId |
|
|
733
|
-
* generic type `
|
|
737
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
738
|
+
* generic type `N`. It represents the property of the binary tree node that you want to search for.
|
|
734
739
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
735
740
|
* specifies the property of the binary tree node to search for. If not provided, it defaults to `'id'`.
|
|
736
741
|
* @returns a BinaryTreeNode object or null.
|
|
@@ -744,7 +749,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
744
749
|
* The function getPathToRoot returns an array of BinaryTreeNode objects representing the path from a given node to the
|
|
745
750
|
* root of a binary tree.
|
|
746
751
|
* @param node - The `node` parameter is a BinaryTreeNode object.
|
|
747
|
-
* @returns The function `getPathToRoot` returns an array of `
|
|
752
|
+
* @returns The function `getPathToRoot` returns an array of `N` objects, representing the path from
|
|
748
753
|
* the given `node` to the root of the binary tree.
|
|
749
754
|
*/
|
|
750
755
|
BinaryTree.prototype.getPathToRoot = function (node) {
|
|
@@ -759,7 +764,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
759
764
|
/**
|
|
760
765
|
* The `getLeftMost` function returns the leftmost node in a binary tree, either recursively or iteratively using tail
|
|
761
766
|
* recursion optimization.
|
|
762
|
-
* @param {
|
|
767
|
+
* @param {N | null} [node] - The `node` parameter is an optional parameter of type `N
|
|
763
768
|
* | null`. It represents the starting node from which to find the leftmost node in a binary tree. If no node is
|
|
764
769
|
* provided, the function will use the root node of the binary tree.
|
|
765
770
|
* @returns The `getLeftMost` function returns the leftmost node in a binary tree.
|
|
@@ -789,7 +794,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
789
794
|
/**
|
|
790
795
|
* The `getRightMost` function returns the rightmost node in a binary tree, either recursively or iteratively using
|
|
791
796
|
* tail recursion optimization.
|
|
792
|
-
* @param {
|
|
797
|
+
* @param {N | null} [node] - The `node` parameter is an optional parameter of type `N
|
|
793
798
|
* | null`. It represents the starting node from which to find the rightmost node in a binary tree. If no node is
|
|
794
799
|
* provided, the function will use the root node of the binary tree.
|
|
795
800
|
* @returns The `getRightMost` function returns the rightmost node in a binary tree.
|
|
@@ -818,7 +823,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
818
823
|
};
|
|
819
824
|
/**
|
|
820
825
|
* The `isBST` function checks if a binary tree is a binary search tree.
|
|
821
|
-
* @param {
|
|
826
|
+
* @param {N | null} [node] - The `node` parameter is an optional parameter of type `N
|
|
822
827
|
* | null`. It represents the root node of the binary search tree (BST) that we want to check for validity. If no node
|
|
823
828
|
* is provided, the function will default to using the root node of the BST instance that
|
|
824
829
|
* @returns The `isBST` function returns a boolean value. It returns `true` if the binary tree is a valid binary search
|
|
@@ -858,7 +863,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
858
863
|
/**
|
|
859
864
|
* The function calculates the size and count of a subtree in a binary tree using either recursive or iterative
|
|
860
865
|
* traversal.
|
|
861
|
-
* @param {
|
|
866
|
+
* @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter is the root node of a binary
|
|
862
867
|
* tree.
|
|
863
868
|
* @returns The function `getSubTreeSizeAndCount` returns an array `[number, number]`. The first element of the array
|
|
864
869
|
* represents the size of the subtree, and the second element represents the count of the nodes in the subtree.
|
|
@@ -996,7 +1001,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
996
1001
|
* represents either a node or a property name. If a node is provided, the breadth-first search algorithm will be
|
|
997
1002
|
* performed starting from that node. If a property name is provided, the breadth-first search algorithm will be
|
|
998
1003
|
* performed starting from the root node
|
|
999
|
-
* @returns an object of type `ResultsByProperty<
|
|
1004
|
+
* @returns an object of type `ResultsByProperty<N>`.
|
|
1000
1005
|
*/
|
|
1001
1006
|
BinaryTree.prototype.BFS = function (nodeOrPropertyName) {
|
|
1002
1007
|
nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
|
|
@@ -1024,7 +1029,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
1024
1029
|
* either the name of a property in the `BinaryTreeNode` object or the value of the `id` property in the
|
|
1025
1030
|
* `BinaryTreeNode` object. This parameter is used to accumulate the results based on the specified property name. If
|
|
1026
1031
|
* no value
|
|
1027
|
-
* @returns an object of type `ResultsByProperty<
|
|
1032
|
+
* @returns an object of type `ResultsByProperty<N>`.
|
|
1028
1033
|
*/
|
|
1029
1034
|
BinaryTree.prototype.DFS = function (pattern, nodeOrPropertyName) {
|
|
1030
1035
|
var _this = this;
|
|
@@ -1111,14 +1116,14 @@ var BinaryTree = /** @class */ (function () {
|
|
|
1111
1116
|
/**
|
|
1112
1117
|
* The `levelIterative` function performs a level-order traversal on a binary tree and returns the values of the nodes
|
|
1113
1118
|
* in an array, based on a specified property name.
|
|
1114
|
-
* @param {
|
|
1119
|
+
* @param {N | null} node - The `node` parameter is a BinaryTreeNode object representing the starting
|
|
1115
1120
|
* node for the level order traversal. It can be null if no specific node is provided, in which case the root node of
|
|
1116
1121
|
* the tree is used as the starting node.
|
|
1117
1122
|
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
|
|
1118
1123
|
* can be either a `BinaryTreeNode` property name or the string `'id'`. If a property name is provided, the function
|
|
1119
1124
|
* will accumulate results based on that property. If no property name is provided, the function will default to
|
|
1120
1125
|
* accumulating results
|
|
1121
|
-
* @returns The function `levelIterative` returns an object of type `ResultsByProperty<
|
|
1126
|
+
* @returns The function `levelIterative` returns an object of type `ResultsByProperty<N>`.
|
|
1122
1127
|
*/
|
|
1123
1128
|
BinaryTree.prototype.levelIterative = function (node, nodeOrPropertyName) {
|
|
1124
1129
|
nodeOrPropertyName = nodeOrPropertyName || 'id';
|
|
@@ -1143,12 +1148,12 @@ var BinaryTree = /** @class */ (function () {
|
|
|
1143
1148
|
};
|
|
1144
1149
|
/**
|
|
1145
1150
|
* The `listLevels` function collects nodes from a binary tree by a specified property and organizes them into levels.
|
|
1146
|
-
* @param {
|
|
1151
|
+
* @param {N | null} node - The `node` parameter is a BinaryTreeNode object or null. It represents the
|
|
1147
1152
|
* root node of a binary tree. If it is null, the function will use the root node of the current binary tree instance.
|
|
1148
1153
|
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
|
|
1149
1154
|
* specifies the property of the `BinaryTreeNode` object to collect at each level. It can be one of the following
|
|
1150
1155
|
* values:
|
|
1151
|
-
* @returns The function `listLevels` returns a 2D array of `ResultByProperty<
|
|
1156
|
+
* @returns The function `listLevels` returns a 2D array of `ResultByProperty<N>` objects.
|
|
1152
1157
|
*/
|
|
1153
1158
|
BinaryTree.prototype.listLevels = function (node, nodeOrPropertyName) {
|
|
1154
1159
|
nodeOrPropertyName = nodeOrPropertyName || 'id';
|
|
@@ -1232,7 +1237,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
1232
1237
|
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is used to specify the
|
|
1233
1238
|
* property of the nodes that you want to retrieve in the results. It can be either the node itself or the name of the
|
|
1234
1239
|
* property. If not provided, it defaults to `'id'`.
|
|
1235
|
-
* @returns The function `morris` returns an object of type `ResultsByProperty<
|
|
1240
|
+
* @returns The function `morris` returns an object of type `ResultsByProperty<N>`.
|
|
1236
1241
|
*/
|
|
1237
1242
|
BinaryTree.prototype.morris = function (pattern, nodeOrPropertyName) {
|
|
1238
1243
|
var _this = this;
|
|
@@ -1375,9 +1380,9 @@ var BinaryTree = /** @class */ (function () {
|
|
|
1375
1380
|
* The function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to
|
|
1376
1381
|
* a result array.
|
|
1377
1382
|
* @param cur - The current binary tree node that is being checked.
|
|
1378
|
-
* @param {(
|
|
1383
|
+
* @param {(N | null | undefined)[]} result - An array that stores the matching nodes found during the
|
|
1379
1384
|
* traversal.
|
|
1380
|
-
* @param {BinaryTreeNodeId |
|
|
1385
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is the value that we are searching for in
|
|
1381
1386
|
* the binary tree nodes. It can be either the `id`, `count`, or `val` property of the node.
|
|
1382
1387
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
1383
1388
|
* specifies the property of the `BinaryTreeNode` object that you want to compare with the `nodeProperty` value. It can
|
|
@@ -1418,7 +1423,7 @@ var BinaryTree = /** @class */ (function () {
|
|
|
1418
1423
|
/**
|
|
1419
1424
|
* The function `_accumulatedByPropertyName` pushes a property value of a binary tree node into an array based on the
|
|
1420
1425
|
* provided property name or a default property name.
|
|
1421
|
-
* @param node - The `node` parameter is of type `
|
|
1426
|
+
* @param node - The `node` parameter is of type `N`, which represents a node in a binary tree.
|
|
1422
1427
|
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
|
|
1423
1428
|
* can be either a string representing a property name or a reference to a node object. If it is a string, it specifies
|
|
1424
1429
|
* the property name of the node that should be accumulated. If it is a node object, it specifies the node itself
|
|
@@ -5,17 +5,17 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTDeletedResult } from '../types';
|
|
8
|
+
import type { BinaryTreeNodeId, BinaryTreeNodePropertyName, BSTComparator, BSTDeletedResult, RecursiveBSTNode } from '../types';
|
|
9
9
|
import { BinaryTree, BinaryTreeNode, LoopType } from './binary-tree';
|
|
10
|
+
import { IBinaryTree, IBinaryTreeNode } from '../interfaces';
|
|
10
11
|
export declare enum CP {
|
|
11
12
|
lt = -1,
|
|
12
13
|
eq = 0,
|
|
13
14
|
gt = 1
|
|
14
15
|
}
|
|
15
|
-
export declare class BSTNode<T> extends BinaryTreeNode<T> {
|
|
16
|
-
clone(): BSTNode<T>;
|
|
16
|
+
export declare class BSTNode<T, FAMILY extends BSTNode<T, FAMILY> = RecursiveBSTNode<T>> extends BinaryTreeNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
|
|
17
17
|
}
|
|
18
|
-
export declare class BST<
|
|
18
|
+
export declare class BST<N extends BSTNode<N['val'], N> = BSTNode<number>> extends BinaryTree<N> implements IBinaryTree<N> {
|
|
19
19
|
/**
|
|
20
20
|
* The constructor function accepts an optional options object and sets the comparator property if provided.
|
|
21
21
|
* @param [options] - An optional object that can contain the following properties:
|
|
@@ -24,30 +24,30 @@ export declare class BST<T> extends BinaryTree<T> {
|
|
|
24
24
|
comparator?: BSTComparator;
|
|
25
25
|
loopType?: LoopType;
|
|
26
26
|
});
|
|
27
|
-
|
|
27
|
+
_createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
|
|
28
28
|
/**
|
|
29
29
|
* The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
|
|
30
30
|
* the ID matches, and returns the inserted node.
|
|
31
31
|
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node. It is used to
|
|
32
32
|
* determine the position of the node in the binary search tree.
|
|
33
|
-
* @param {
|
|
34
|
-
* be of type `
|
|
33
|
+
* @param {N | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
|
|
34
|
+
* be of type `N` (the generic type) or `null`.
|
|
35
35
|
* @param {number} [count=1] - The `count` parameter represents the number of times the value should be inserted into
|
|
36
36
|
* the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
|
|
37
37
|
* inserted once.
|
|
38
|
-
* @returns The method `add` returns a `
|
|
38
|
+
* @returns The method `add` returns a `N` object or `null`.
|
|
39
39
|
*/
|
|
40
|
-
add(id: BinaryTreeNodeId, val:
|
|
40
|
+
add(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
|
|
41
41
|
/**
|
|
42
42
|
* The `get` function returns the first node in a binary search tree that matches the given property value or name.
|
|
43
|
-
* @param {BinaryTreeNodeId |
|
|
44
|
-
* generic type `
|
|
43
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
44
|
+
* generic type `N`. It represents the value of the property that you want to search for in the binary search tree.
|
|
45
45
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
46
46
|
* specifies the property name to use for searching the binary search tree nodes. If not provided, it defaults to
|
|
47
47
|
* `'id'`.
|
|
48
|
-
* @returns The method is returning a
|
|
48
|
+
* @returns The method is returning a N object or null.
|
|
49
49
|
*/
|
|
50
|
-
get(nodeProperty: BinaryTreeNodeId |
|
|
50
|
+
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
51
51
|
/**
|
|
52
52
|
* The function returns the id of the rightmost node if the comparison between two values is less than, the id of the
|
|
53
53
|
* leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
|
|
@@ -65,23 +65,23 @@ export declare class BST<T> extends BinaryTree<T> {
|
|
|
65
65
|
* @param {boolean} [ignoreCount] - A boolean flag indicating whether to ignore the count of the node being removed. If
|
|
66
66
|
* set to true, the count of the node will not be considered and the node will be removed regardless of its count. If
|
|
67
67
|
* set to false or not provided, the count of the node will be taken into account and the
|
|
68
|
-
* @returns an array of `BSTDeletedResult<
|
|
68
|
+
* @returns an array of `BSTDeletedResult<N>` objects.
|
|
69
69
|
*/
|
|
70
|
-
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BSTDeletedResult<
|
|
70
|
+
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BSTDeletedResult<N>[];
|
|
71
71
|
/**
|
|
72
72
|
* The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
|
|
73
73
|
* option to specify the property name and whether to return only one node.
|
|
74
|
-
* @param {BinaryTreeNodeId |
|
|
75
|
-
* generic type `
|
|
74
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
75
|
+
* generic type `N`. It represents the property value that you want to search for in the binary search tree.
|
|
76
76
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
77
77
|
* specifies the property of the nodes to compare with the `nodeProperty` parameter. If not provided, it defaults to
|
|
78
78
|
* `'id'`.
|
|
79
79
|
* @param {boolean} [onlyOne] - A boolean value indicating whether to return only one node that matches the given
|
|
80
80
|
* nodeProperty. If set to true, the function will stop traversing the tree and return the first matching node. If set
|
|
81
81
|
* to false or not provided, the function will return all nodes that match the given nodeProperty.
|
|
82
|
-
* @returns an array of
|
|
82
|
+
* @returns an array of N objects.
|
|
83
83
|
*/
|
|
84
|
-
getNodes(nodeProperty: BinaryTreeNodeId |
|
|
84
|
+
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
85
85
|
/**
|
|
86
86
|
* The `lesserSum` function calculates the sum of a specified property in all nodes with an ID less than a given ID in
|
|
87
87
|
* a binary search tree.
|
|
@@ -96,7 +96,7 @@ export declare class BST<T> extends BinaryTree<T> {
|
|
|
96
96
|
/**
|
|
97
97
|
* The function `allGreaterNodesAdd` updates the value of a specified property for all nodes in a binary search tree
|
|
98
98
|
* that have a greater value than a given node.
|
|
99
|
-
* @param node - The `node` parameter is of type `
|
|
99
|
+
* @param node - The `node` parameter is of type `N`, which represents a node in a binary search tree. It
|
|
100
100
|
* contains properties such as `id` and `count`.
|
|
101
101
|
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
|
|
102
102
|
* each node should be increased.
|
|
@@ -105,7 +105,7 @@ export declare class BST<T> extends BinaryTree<T> {
|
|
|
105
105
|
* defaults to 'id'.
|
|
106
106
|
* @returns a boolean value.
|
|
107
107
|
*/
|
|
108
|
-
allGreaterNodesAdd(node:
|
|
108
|
+
allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
109
109
|
/**
|
|
110
110
|
* The `balance` function takes a sorted array of nodes and builds a balanced binary search tree using either a
|
|
111
111
|
* recursive or iterative approach.
|
|
@@ -44,9 +44,6 @@ var BSTNode = /** @class */ (function (_super) {
|
|
|
44
44
|
function BSTNode() {
|
|
45
45
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
46
46
|
}
|
|
47
|
-
BSTNode.prototype.clone = function () {
|
|
48
|
-
return new BSTNode(this.id, this.val, this.count);
|
|
49
|
-
};
|
|
50
47
|
return BSTNode;
|
|
51
48
|
}(binary_tree_1.BinaryTreeNode));
|
|
52
49
|
exports.BSTNode = BSTNode;
|
|
@@ -67,25 +64,26 @@ var BST = /** @class */ (function (_super) {
|
|
|
67
64
|
}
|
|
68
65
|
return _this;
|
|
69
66
|
}
|
|
70
|
-
BST.prototype.
|
|
71
|
-
|
|
67
|
+
BST.prototype._createNode = function (id, val, count) {
|
|
68
|
+
var node = val !== null ? new BSTNode(id, val, count) : null;
|
|
69
|
+
return node;
|
|
72
70
|
};
|
|
73
71
|
/**
|
|
74
72
|
* The `add` function inserts a new node into a binary search tree, updating the count and value of an existing node if
|
|
75
73
|
* the ID matches, and returns the inserted node.
|
|
76
74
|
* @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node. It is used to
|
|
77
75
|
* determine the position of the node in the binary search tree.
|
|
78
|
-
* @param {
|
|
79
|
-
* be of type `
|
|
76
|
+
* @param {N | null} val - The `val` parameter represents the value to be stored in the binary search tree node. It can
|
|
77
|
+
* be of type `N` (the generic type) or `null`.
|
|
80
78
|
* @param {number} [count=1] - The `count` parameter represents the number of times the value should be inserted into
|
|
81
79
|
* the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
|
|
82
80
|
* inserted once.
|
|
83
|
-
* @returns The method `add` returns a `
|
|
81
|
+
* @returns The method `add` returns a `N` object or `null`.
|
|
84
82
|
*/
|
|
85
83
|
BST.prototype.add = function (id, val, count) {
|
|
86
84
|
if (count === void 0) { count = 1; }
|
|
87
85
|
var inserted = null;
|
|
88
|
-
var newNode = this.
|
|
86
|
+
var newNode = this._createNode(id, val, count);
|
|
89
87
|
if (this.root === null) {
|
|
90
88
|
this._setRoot(newNode);
|
|
91
89
|
this._setSize(this.size + 1);
|
|
@@ -157,12 +155,12 @@ var BST = /** @class */ (function (_super) {
|
|
|
157
155
|
};
|
|
158
156
|
/**
|
|
159
157
|
* The `get` function returns the first node in a binary search tree that matches the given property value or name.
|
|
160
|
-
* @param {BinaryTreeNodeId |
|
|
161
|
-
* generic type `
|
|
158
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
159
|
+
* generic type `N`. It represents the value of the property that you want to search for in the binary search tree.
|
|
162
160
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
163
161
|
* specifies the property name to use for searching the binary search tree nodes. If not provided, it defaults to
|
|
164
162
|
* `'id'`.
|
|
165
|
-
* @returns The method is returning a
|
|
163
|
+
* @returns The method is returning a N object or null.
|
|
166
164
|
*/
|
|
167
165
|
BST.prototype.get = function (nodeProperty, propertyName) {
|
|
168
166
|
var _a;
|
|
@@ -194,7 +192,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
194
192
|
* @param {boolean} [ignoreCount] - A boolean flag indicating whether to ignore the count of the node being removed. If
|
|
195
193
|
* set to true, the count of the node will not be considered and the node will be removed regardless of its count. If
|
|
196
194
|
* set to false or not provided, the count of the node will be taken into account and the
|
|
197
|
-
* @returns an array of `BSTDeletedResult<
|
|
195
|
+
* @returns an array of `BSTDeletedResult<N>` objects.
|
|
198
196
|
*/
|
|
199
197
|
BST.prototype.remove = function (id, ignoreCount) {
|
|
200
198
|
var bstDeletedResult = [];
|
|
@@ -250,15 +248,15 @@ var BST = /** @class */ (function (_super) {
|
|
|
250
248
|
/**
|
|
251
249
|
* The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
|
|
252
250
|
* option to specify the property name and whether to return only one node.
|
|
253
|
-
* @param {BinaryTreeNodeId |
|
|
254
|
-
* generic type `
|
|
251
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
252
|
+
* generic type `N`. It represents the property value that you want to search for in the binary search tree.
|
|
255
253
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
256
254
|
* specifies the property of the nodes to compare with the `nodeProperty` parameter. If not provided, it defaults to
|
|
257
255
|
* `'id'`.
|
|
258
256
|
* @param {boolean} [onlyOne] - A boolean value indicating whether to return only one node that matches the given
|
|
259
257
|
* nodeProperty. If set to true, the function will stop traversing the tree and return the first matching node. If set
|
|
260
258
|
* to false or not provided, the function will return all nodes that match the given nodeProperty.
|
|
261
|
-
* @returns an array of
|
|
259
|
+
* @returns an array of N objects.
|
|
262
260
|
*/
|
|
263
261
|
BST.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {
|
|
264
262
|
var _this = this;
|
|
@@ -399,7 +397,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
399
397
|
/**
|
|
400
398
|
* The function `allGreaterNodesAdd` updates the value of a specified property for all nodes in a binary search tree
|
|
401
399
|
* that have a greater value than a given node.
|
|
402
|
-
* @param node - The `node` parameter is of type `
|
|
400
|
+
* @param node - The `node` parameter is of type `N`, which represents a node in a binary search tree. It
|
|
403
401
|
* contains properties such as `id` and `count`.
|
|
404
402
|
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
|
|
405
403
|
* each node should be increased.
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
}
|
|
1
|
+
export {};
|