data-structure-typed 1.18.7 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +208 -419
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +198 -167
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +413 -398
- package/dist/data-structures/binary-tree/avl-tree.d.ts +24 -16
- package/dist/data-structures/binary-tree/avl-tree.js +23 -17
- package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -26
- package/dist/data-structures/binary-tree/binary-tree.js +12 -27
- package/dist/data-structures/binary-tree/bst.d.ts +66 -90
- package/dist/data-structures/binary-tree/bst.js +85 -163
- package/dist/data-structures/binary-tree/rb-tree.d.ts +6 -17
- package/dist/data-structures/binary-tree/rb-tree.js +5 -17
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +187 -18
- package/dist/data-structures/binary-tree/tree-multiset.js +716 -39
- package/dist/data-structures/graph/abstract-graph.d.ts +112 -52
- package/dist/data-structures/graph/abstract-graph.js +138 -72
- package/dist/data-structures/graph/directed-graph.d.ts +104 -101
- package/dist/data-structures/graph/directed-graph.js +134 -129
- package/dist/data-structures/graph/undirected-graph.d.ts +66 -65
- package/dist/data-structures/graph/undirected-graph.js +107 -106
- package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +12 -18
- package/dist/data-structures/interfaces/abstract-graph.d.ts +2 -4
- package/dist/data-structures/interfaces/avl-tree.d.ts +2 -2
- package/dist/data-structures/interfaces/binary-tree.d.ts +1 -1
- package/dist/data-structures/interfaces/bst.d.ts +4 -5
- package/dist/data-structures/interfaces/rb-tree.d.ts +2 -3
- 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 +10 -6
- 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 +5 -5
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/types/index.d.ts +1 -0
- package/dist/utils/types/index.js +1 -0
- package/dist/utils/types/validate-type.d.ts +19 -0
- package/dist/utils/types/validate-type.js +2 -0
- package/dist/utils/utils.d.ts +2 -2
- package/dist/utils/utils.js +0 -62
- package/dist/utils/validate-type.d.ts +45 -0
- package/dist/utils/validate-type.js +58 -0
- package/package.json +5 -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
|
@@ -39,27 +39,14 @@ var BSTNode = /** @class */ (function (_super) {
|
|
|
39
39
|
function BSTNode() {
|
|
40
40
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
41
41
|
}
|
|
42
|
-
/**
|
|
43
|
-
* The function creates a new binary search tree node with the specified id, value, and count.
|
|
44
|
-
* @param {BinaryTreeNodeId} id - The id parameter is the identifier for the binary tree node. It is used to uniquely
|
|
45
|
-
* identify each node in the tree.
|
|
46
|
-
* @param {T} [val] - The "val" parameter represents the value that will be stored in the binary tree node. It is an
|
|
47
|
-
* optional parameter, meaning it can be omitted when calling the "createNode" function.
|
|
48
|
-
* @param {number} [count] - The `count` parameter represents the number of occurrences of the value in the binary
|
|
49
|
-
* search tree node. It is an optional parameter, so it can be omitted when calling the `createNode` method.
|
|
50
|
-
* @returns The method is returning a new instance of the BSTNode class, casted as the FAMILY type.
|
|
51
|
-
*/
|
|
52
|
-
BSTNode.prototype.createNode = function (id, val, count) {
|
|
53
|
-
return new BSTNode(id, (val === undefined ? id : val), count);
|
|
54
|
-
};
|
|
55
42
|
return BSTNode;
|
|
56
43
|
}(binary_tree_1.BinaryTreeNode));
|
|
57
44
|
exports.BSTNode = BSTNode;
|
|
58
45
|
var BST = /** @class */ (function (_super) {
|
|
59
46
|
__extends(BST, _super);
|
|
60
47
|
/**
|
|
61
|
-
* The constructor function
|
|
62
|
-
* @param [options] - An optional object that
|
|
48
|
+
* The constructor function initializes a binary search tree object with an optional comparator function.
|
|
49
|
+
* @param {BSTOptions} [options] - An optional object that contains configuration options for the binary search tree.
|
|
63
50
|
*/
|
|
64
51
|
function BST(options) {
|
|
65
52
|
var _this = _super.call(this, options) || this;
|
|
@@ -73,38 +60,31 @@ var BST = /** @class */ (function (_super) {
|
|
|
73
60
|
return _this;
|
|
74
61
|
}
|
|
75
62
|
/**
|
|
76
|
-
* The function creates a new binary search tree node with the given id
|
|
77
|
-
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is
|
|
78
|
-
*
|
|
79
|
-
* @param
|
|
80
|
-
*
|
|
81
|
-
* @
|
|
82
|
-
* of a particular value in the binary search tree node.
|
|
83
|
-
* @returns a new instance of the BSTNode class, casted as type N.
|
|
63
|
+
* The function creates a new binary search tree node with the given id and value.
|
|
64
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
|
|
65
|
+
* identify each node in the binary tree.
|
|
66
|
+
* @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
|
|
67
|
+
* that will be stored in the node.
|
|
68
|
+
* @returns a new instance of the BSTNode class with the specified id and value.
|
|
84
69
|
*/
|
|
85
|
-
BST.prototype.createNode = function (id, val
|
|
86
|
-
return new BSTNode(id, val
|
|
70
|
+
BST.prototype.createNode = function (id, val) {
|
|
71
|
+
return new BSTNode(id, val);
|
|
87
72
|
};
|
|
88
73
|
/**
|
|
89
|
-
* The `add` function
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* the binary search tree. By default, it is set to 1, meaning that if no count is specified, the value will be
|
|
97
|
-
* inserted once.
|
|
98
|
-
* @returns The method `add` returns a `N` object or `null`.
|
|
74
|
+
* The `add` function adds a new node to a binary tree, ensuring that duplicates are not accepted.
|
|
75
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add. It
|
|
76
|
+
* is of type `BinaryTreeNodeId`.
|
|
77
|
+
* @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. It represents
|
|
78
|
+
* the value associated with the node.
|
|
79
|
+
* @returns The function `add` returns the inserted node (`inserted`) if it was successfully added to the binary tree.
|
|
80
|
+
* If the node was not added (e.g., due to a duplicate ID), it returns `null` or `undefined`.
|
|
99
81
|
*/
|
|
100
|
-
BST.prototype.add = function (id, val
|
|
101
|
-
if (count === void 0) { count = 1; }
|
|
82
|
+
BST.prototype.add = function (id, val) {
|
|
102
83
|
var inserted = null;
|
|
103
|
-
var newNode = this.createNode(id, val
|
|
84
|
+
var newNode = this.createNode(id, val);
|
|
104
85
|
if (this.root === null) {
|
|
105
86
|
this._setRoot(newNode);
|
|
106
87
|
this._setSize(this.size + 1);
|
|
107
|
-
this._setCount(this.count + count);
|
|
108
88
|
inserted = (this.root);
|
|
109
89
|
}
|
|
110
90
|
else {
|
|
@@ -114,8 +94,6 @@ var BST = /** @class */ (function (_super) {
|
|
|
114
94
|
if (cur !== null && newNode !== null) {
|
|
115
95
|
if (this._compare(cur.id, id) === types_1.CP.eq) {
|
|
116
96
|
if (newNode) {
|
|
117
|
-
cur.count += newNode.count;
|
|
118
|
-
this._setCount(this.count + newNode.count);
|
|
119
97
|
cur.val = newNode.val;
|
|
120
98
|
}
|
|
121
99
|
//Duplicates are not accepted.
|
|
@@ -127,12 +105,10 @@ var BST = /** @class */ (function (_super) {
|
|
|
127
105
|
if (cur.left === undefined) {
|
|
128
106
|
if (newNode) {
|
|
129
107
|
newNode.parent = cur;
|
|
130
|
-
newNode.familyPosition = types_1.FamilyPosition.LEFT;
|
|
131
108
|
}
|
|
132
109
|
//Add to the left of the current node
|
|
133
110
|
cur.left = newNode;
|
|
134
111
|
this._setSize(this.size + 1);
|
|
135
|
-
this._setCount(this.count + newNode.count);
|
|
136
112
|
traversing = false;
|
|
137
113
|
inserted = cur.left;
|
|
138
114
|
}
|
|
@@ -147,12 +123,10 @@ var BST = /** @class */ (function (_super) {
|
|
|
147
123
|
if (cur.right === undefined) {
|
|
148
124
|
if (newNode) {
|
|
149
125
|
newNode.parent = cur;
|
|
150
|
-
newNode.familyPosition = types_1.FamilyPosition.RIGHT;
|
|
151
126
|
}
|
|
152
127
|
//Add to the right of the current node
|
|
153
128
|
cur.right = newNode;
|
|
154
129
|
this._setSize(this.size + 1);
|
|
155
|
-
this._setCount(this.count + newNode.count);
|
|
156
130
|
traversing = false;
|
|
157
131
|
inserted = (cur.right);
|
|
158
132
|
}
|
|
@@ -171,13 +145,12 @@ var BST = /** @class */ (function (_super) {
|
|
|
171
145
|
return inserted;
|
|
172
146
|
};
|
|
173
147
|
/**
|
|
174
|
-
* The
|
|
148
|
+
* The function returns the first node in a binary tree that matches the given property name and value.
|
|
175
149
|
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
176
|
-
* generic type `N`. It represents the
|
|
150
|
+
* generic type `N`. It represents the property of the binary tree node that you want to search for.
|
|
177
151
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
178
|
-
* specifies the property name to use for searching the binary
|
|
179
|
-
*
|
|
180
|
-
* @returns The method is returning a N object or null.
|
|
152
|
+
* specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'id'`.
|
|
153
|
+
* @returns The method is returning either a BinaryTreeNodeId or N (generic type) or null.
|
|
181
154
|
*/
|
|
182
155
|
BST.prototype.get = function (nodeProperty, propertyName) {
|
|
183
156
|
var _a;
|
|
@@ -187,10 +160,9 @@ var BST = /** @class */ (function (_super) {
|
|
|
187
160
|
/**
|
|
188
161
|
* The function returns the id of the rightmost node if the comparison between two values is less than, the id of the
|
|
189
162
|
* leftmost node if the comparison is greater than, and the id of the rightmost node otherwise.
|
|
190
|
-
* @returns The
|
|
191
|
-
* the
|
|
192
|
-
*
|
|
193
|
-
* there are no nodes in
|
|
163
|
+
* @returns The method `lastKey()` returns the id of the rightmost node in the binary tree if the comparison between
|
|
164
|
+
* the values at index 0 and 1 is less than, otherwise it returns the id of the leftmost node. If the comparison is
|
|
165
|
+
* equal, it returns the id of the rightmost node. If there are no nodes in the tree, it returns 0.
|
|
194
166
|
*/
|
|
195
167
|
BST.prototype.lastKey = function () {
|
|
196
168
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -202,78 +174,15 @@ var BST = /** @class */ (function (_super) {
|
|
|
202
174
|
return (_f = (_e = this.getRightMost()) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : 0;
|
|
203
175
|
};
|
|
204
176
|
/**
|
|
205
|
-
* The `
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* from the binary search tree.
|
|
209
|
-
* @param {boolean} [ignoreCount] - A boolean flag indicating whether to ignore the count of the node being removed. If
|
|
210
|
-
* set to true, the count of the node will not be considered and the node will be removed regardless of its count. If
|
|
211
|
-
* set to false or not provided, the count of the node will be taken into account and the
|
|
212
|
-
* @returns an array of `BSTDeletedResult<N>` objects.
|
|
213
|
-
*/
|
|
214
|
-
BST.prototype.remove = function (id, ignoreCount) {
|
|
215
|
-
var bstDeletedResult = [];
|
|
216
|
-
if (!this.root)
|
|
217
|
-
return bstDeletedResult;
|
|
218
|
-
var curr = this.get(id);
|
|
219
|
-
if (!curr)
|
|
220
|
-
return bstDeletedResult;
|
|
221
|
-
var parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
|
|
222
|
-
var needBalanced = null, orgCurrent = curr;
|
|
223
|
-
if (curr.count > 1 && !ignoreCount) {
|
|
224
|
-
curr.count--;
|
|
225
|
-
this._setCount(this.count - 1);
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
if (!curr.left) {
|
|
229
|
-
if (!parent) {
|
|
230
|
-
if (curr.right !== undefined)
|
|
231
|
-
this._setRoot(curr.right);
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
switch (curr.familyPosition) {
|
|
235
|
-
case types_1.FamilyPosition.LEFT:
|
|
236
|
-
parent.left = curr.right;
|
|
237
|
-
break;
|
|
238
|
-
case types_1.FamilyPosition.RIGHT:
|
|
239
|
-
parent.right = curr.right;
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
needBalanced = parent;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
246
|
-
var leftSubTreeMax = curr.left ? this.getRightMost(curr.left) : null;
|
|
247
|
-
if (leftSubTreeMax) {
|
|
248
|
-
var parentOfLeftSubTreeMax = leftSubTreeMax.parent;
|
|
249
|
-
orgCurrent = curr.swapLocation(leftSubTreeMax);
|
|
250
|
-
if (parentOfLeftSubTreeMax) {
|
|
251
|
-
if (parentOfLeftSubTreeMax.right === leftSubTreeMax)
|
|
252
|
-
parentOfLeftSubTreeMax.right = leftSubTreeMax.left;
|
|
253
|
-
else
|
|
254
|
-
parentOfLeftSubTreeMax.left = leftSubTreeMax.left;
|
|
255
|
-
needBalanced = parentOfLeftSubTreeMax;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
this._setSize(this.size - 1);
|
|
260
|
-
this._setCount(this.count - curr.count);
|
|
261
|
-
}
|
|
262
|
-
bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
|
|
263
|
-
return bstDeletedResult;
|
|
264
|
-
};
|
|
265
|
-
/**
|
|
266
|
-
* The function `getNodes` returns an array of binary search tree nodes that match a given property value, with the
|
|
267
|
-
* option to specify the property name and whether to return only one node.
|
|
268
|
-
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
269
|
-
* generic type `N`. It represents the property value that you want to search for in the binary search tree.
|
|
177
|
+
* The function `getNodes` returns an array of nodes in a binary tree that match a given property value.
|
|
178
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or an
|
|
179
|
+
* `N` type. It represents the property of the binary tree node that you want to compare with.
|
|
270
180
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
271
|
-
* specifies the property
|
|
272
|
-
* `
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
* @returns an array of N objects.
|
|
181
|
+
* specifies the property name to use for comparison. If not provided, it defaults to `'id'`.
|
|
182
|
+
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
|
|
183
|
+
* return only one node that matches the given `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne`
|
|
184
|
+
* is set to `true`, the function will return an array with only one node (if
|
|
185
|
+
* @returns an array of nodes (type N).
|
|
277
186
|
*/
|
|
278
187
|
BST.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {
|
|
279
188
|
var _this = this;
|
|
@@ -324,29 +233,30 @@ var BST = /** @class */ (function (_super) {
|
|
|
324
233
|
};
|
|
325
234
|
// --- start additional functions
|
|
326
235
|
/**
|
|
327
|
-
* The `lesserSum` function calculates the sum of
|
|
328
|
-
* a
|
|
329
|
-
* @param {BinaryTreeNodeId}
|
|
330
|
-
* calculate the lesser sum.
|
|
236
|
+
* The `lesserSum` function calculates the sum of property values in a binary tree for nodes that have a property value
|
|
237
|
+
* less than a given node.
|
|
238
|
+
* @param {N | BinaryTreeNodeId | null} beginNode - The `beginNode` parameter can be one of the following:
|
|
331
239
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
332
|
-
* specifies the property
|
|
240
|
+
* specifies the property name to use for calculating the sum. If not provided, it defaults to `'id'`.
|
|
333
241
|
* @returns The function `lesserSum` returns a number, which represents the sum of the values of the nodes in the
|
|
334
|
-
* binary
|
|
242
|
+
* binary tree that have a lesser value than the specified `beginNode` based on the `propertyName`.
|
|
335
243
|
*/
|
|
336
|
-
BST.prototype.lesserSum = function (
|
|
244
|
+
BST.prototype.lesserSum = function (beginNode, propertyName) {
|
|
337
245
|
var _this = this;
|
|
338
246
|
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
247
|
+
if (typeof beginNode === 'number')
|
|
248
|
+
beginNode = this.get(beginNode, 'id');
|
|
249
|
+
if (!beginNode)
|
|
250
|
+
return 0;
|
|
339
251
|
if (!this.root)
|
|
340
252
|
return 0;
|
|
253
|
+
var id = beginNode.id;
|
|
341
254
|
var getSumByPropertyName = function (cur) {
|
|
342
255
|
var needSum;
|
|
343
256
|
switch (propertyName) {
|
|
344
257
|
case 'id':
|
|
345
258
|
needSum = cur.id;
|
|
346
259
|
break;
|
|
347
|
-
case 'count':
|
|
348
|
-
needSum = cur.count;
|
|
349
|
-
break;
|
|
350
260
|
default:
|
|
351
261
|
needSum = cur.id;
|
|
352
262
|
break;
|
|
@@ -412,20 +322,25 @@ var BST = /** @class */ (function (_super) {
|
|
|
412
322
|
return sum;
|
|
413
323
|
};
|
|
414
324
|
/**
|
|
415
|
-
* The
|
|
416
|
-
*
|
|
417
|
-
* @param node - The `node` parameter
|
|
418
|
-
*
|
|
325
|
+
* The `allGreaterNodesAdd` function adds a delta value to the specified property of all nodes in a binary tree that
|
|
326
|
+
* have a greater value than a given node.
|
|
327
|
+
* @param {N | BinaryTreeNodeId | null} node - The `node` parameter can be either of type `N` (a generic type),
|
|
328
|
+
* `BinaryTreeNodeId`, or `null`. It represents the node in the binary tree to which the delta value will be added.
|
|
419
329
|
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
|
|
420
|
-
* each node should be increased.
|
|
421
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that
|
|
422
|
-
* property of the
|
|
423
|
-
*
|
|
330
|
+
* each greater node should be increased.
|
|
331
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
332
|
+
* specifies the property name of the nodes in the binary tree that you want to update. If not provided, it defaults to
|
|
333
|
+
* 'id'.
|
|
424
334
|
* @returns a boolean value.
|
|
425
335
|
*/
|
|
426
336
|
BST.prototype.allGreaterNodesAdd = function (node, delta, propertyName) {
|
|
427
337
|
var _this = this;
|
|
428
338
|
propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
|
|
339
|
+
if (typeof node === 'number')
|
|
340
|
+
node = this.get(node, 'id');
|
|
341
|
+
if (!node)
|
|
342
|
+
return false;
|
|
343
|
+
var id = node.id;
|
|
429
344
|
if (!this.root)
|
|
430
345
|
return false;
|
|
431
346
|
var _sumByPropertyName = function (cur) {
|
|
@@ -433,9 +348,6 @@ var BST = /** @class */ (function (_super) {
|
|
|
433
348
|
case 'id':
|
|
434
349
|
cur.id += delta;
|
|
435
350
|
break;
|
|
436
|
-
case 'count':
|
|
437
|
-
cur.count += delta;
|
|
438
|
-
break;
|
|
439
351
|
default:
|
|
440
352
|
cur.id += delta;
|
|
441
353
|
break;
|
|
@@ -443,13 +355,14 @@ var BST = /** @class */ (function (_super) {
|
|
|
443
355
|
};
|
|
444
356
|
if (this.loopType === types_1.LoopType.RECURSIVE) {
|
|
445
357
|
var _traverse_3 = function (cur) {
|
|
446
|
-
var compared = _this._compare(cur.id,
|
|
447
|
-
|
|
358
|
+
var compared = _this._compare(cur.id, id);
|
|
359
|
+
if (compared === types_1.CP.gt)
|
|
360
|
+
_sumByPropertyName(cur);
|
|
448
361
|
if (!cur.left && !cur.right)
|
|
449
362
|
return;
|
|
450
|
-
if (cur.left &&
|
|
363
|
+
if (cur.left && _this._compare(cur.left.id, id) === types_1.CP.gt)
|
|
451
364
|
_traverse_3(cur.left);
|
|
452
|
-
|
|
365
|
+
if (cur.right && _this._compare(cur.right.id, id) === types_1.CP.gt)
|
|
453
366
|
_traverse_3(cur.right);
|
|
454
367
|
};
|
|
455
368
|
_traverse_3(this.root);
|
|
@@ -460,11 +373,12 @@ var BST = /** @class */ (function (_super) {
|
|
|
460
373
|
while (queue.length > 0) {
|
|
461
374
|
var cur = queue.shift();
|
|
462
375
|
if (cur) {
|
|
463
|
-
var compared = this._compare(cur.id,
|
|
464
|
-
|
|
465
|
-
|
|
376
|
+
var compared = this._compare(cur.id, id);
|
|
377
|
+
if (compared === types_1.CP.gt)
|
|
378
|
+
_sumByPropertyName(cur);
|
|
379
|
+
if (cur.left && this._compare(cur.left.id, id) === types_1.CP.gt)
|
|
466
380
|
queue.push(cur.left);
|
|
467
|
-
|
|
381
|
+
if (cur.right && this._compare(cur.right.id, id) === types_1.CP.gt)
|
|
468
382
|
queue.push(cur.right);
|
|
469
383
|
}
|
|
470
384
|
}
|
|
@@ -472,11 +386,20 @@ var BST = /** @class */ (function (_super) {
|
|
|
472
386
|
}
|
|
473
387
|
};
|
|
474
388
|
/**
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
389
|
+
* Balancing Adjustment:
|
|
390
|
+
* Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
|
|
391
|
+
* AVL Tree: After insertion or deletion operations, an AVL tree performs rotation adjustments based on the balance factor of nodes to restore the tree's balance. These rotations can be left rotations, right rotations, left-right rotations, or right-left rotations, performed as needed.
|
|
392
|
+
*
|
|
393
|
+
* Use Cases and Efficiency:
|
|
394
|
+
* Perfectly Balanced Binary Tree: Perfectly balanced binary trees are typically used in specific scenarios such as complete binary heaps in heap sort or certain types of Huffman trees. However, they are not suitable for dynamic operations requiring frequent insertions and deletions, as these operations often necessitate full tree reconstruction.
|
|
395
|
+
* AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
|
|
396
|
+
*/
|
|
397
|
+
/**
|
|
398
|
+
* The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
|
|
399
|
+
* constructs a balanced binary search tree using either a recursive or iterative approach.
|
|
400
|
+
* @returns The function `perfectlyBalance()` returns a boolean value.
|
|
478
401
|
*/
|
|
479
|
-
BST.prototype.
|
|
402
|
+
BST.prototype.perfectlyBalance = function () {
|
|
480
403
|
var _this = this;
|
|
481
404
|
var sorted = this.DFS('in', 'node'), n = sorted.length;
|
|
482
405
|
this.clear();
|
|
@@ -488,7 +411,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
488
411
|
return;
|
|
489
412
|
var m = l + Math.floor((r - l) / 2);
|
|
490
413
|
var midNode = sorted[m];
|
|
491
|
-
_this.add(midNode.id, midNode.val
|
|
414
|
+
_this.add(midNode.id, midNode.val);
|
|
492
415
|
buildBalanceBST_1(l, m - 1);
|
|
493
416
|
buildBalanceBST_1(m + 1, r);
|
|
494
417
|
};
|
|
@@ -504,7 +427,7 @@ var BST = /** @class */ (function (_super) {
|
|
|
504
427
|
if (l <= r) {
|
|
505
428
|
var m = l + Math.floor((r - l) / 2);
|
|
506
429
|
var midNode = sorted[m];
|
|
507
|
-
this.add(midNode.id, midNode.val
|
|
430
|
+
this.add(midNode.id, midNode.val);
|
|
508
431
|
stack.push([m + 1, r]);
|
|
509
432
|
stack.push([l, m - 1]);
|
|
510
433
|
}
|
|
@@ -514,9 +437,8 @@ var BST = /** @class */ (function (_super) {
|
|
|
514
437
|
}
|
|
515
438
|
};
|
|
516
439
|
/**
|
|
517
|
-
* The function `isAVLBalanced` checks if a binary
|
|
518
|
-
* @returns
|
|
519
|
-
* is balanced according to the AVL tree property, and `false` otherwise.
|
|
440
|
+
* The function `isAVLBalanced` checks if a binary tree is balanced according to the AVL tree property.
|
|
441
|
+
* @returns a boolean value.
|
|
520
442
|
*/
|
|
521
443
|
BST.prototype.isAVLBalanced = function () {
|
|
522
444
|
var _a, _b;
|
|
@@ -1,27 +1,16 @@
|
|
|
1
|
-
import { BinaryTreeNodeId, RBColor, RBTreeOptions } from '../types';
|
|
1
|
+
import { BinaryTreeNodeId, RBColor, RBTreeNodeNested, RBTreeOptions } from '../types';
|
|
2
2
|
import { IRBTree, IRBTreeNode } from '../interfaces/rb-tree';
|
|
3
3
|
import { BST, BSTNode } from './bst';
|
|
4
|
-
export declare class RBTreeNode<T,
|
|
5
|
-
constructor(id:
|
|
4
|
+
export declare class RBTreeNode<T = any, NEIGHBOR extends RBTreeNode<T, NEIGHBOR> = RBTreeNodeNested<T>> extends BSTNode<T, NEIGHBOR> implements IRBTreeNode<T, NEIGHBOR> {
|
|
5
|
+
constructor(id: BinaryTreeNodeId, color: RBColor, val?: T);
|
|
6
6
|
private _color;
|
|
7
7
|
get color(): RBColor;
|
|
8
8
|
set color(value: RBColor);
|
|
9
|
-
/**
|
|
10
|
-
* The function creates a new RBTreeNode with the given id, value, and count and returns it as a FAMILY object.
|
|
11
|
-
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
|
|
12
|
-
* identify each node in the tree.
|
|
13
|
-
* @param {T | null} [val] - The "val" parameter represents the value to be stored in the node. It can be of type T
|
|
14
|
-
* (generic type) or null.
|
|
15
|
-
* @param {number} [count] - The `count` parameter represents the number of occurrences of the value in the binary tree
|
|
16
|
-
* node.
|
|
17
|
-
* @returns The method is returning a new instance of the RBTreeNode class, casted as a FAMILY type.
|
|
18
|
-
*/
|
|
19
|
-
createNode(id: BinaryTreeNodeId, val?: T | null, count?: number): FAMILY;
|
|
20
9
|
}
|
|
21
|
-
export declare class RBTree<N extends RBTreeNode<N['val'], N
|
|
10
|
+
export declare class RBTree<N extends RBTreeNode<N['val'], N> = RBTreeNode> extends BST<N> implements IRBTree<N> {
|
|
22
11
|
constructor(options?: RBTreeOptions);
|
|
23
|
-
createNode(id: BinaryTreeNodeId, val?: N['val']
|
|
24
|
-
insert(id: number, val
|
|
12
|
+
createNode(id: BinaryTreeNodeId, val?: N['val']): N;
|
|
13
|
+
insert(id: number, val?: N | null): void;
|
|
25
14
|
private leftRotate;
|
|
26
15
|
private rightRotate;
|
|
27
16
|
private insertFixup;
|
|
@@ -20,9 +20,10 @@ var types_1 = require("../types");
|
|
|
20
20
|
var bst_1 = require("./bst");
|
|
21
21
|
var RBTreeNode = /** @class */ (function (_super) {
|
|
22
22
|
__extends(RBTreeNode, _super);
|
|
23
|
-
function RBTreeNode(id,
|
|
24
|
-
var _this = _super.call(this, id, val
|
|
23
|
+
function RBTreeNode(id, color, val) {
|
|
24
|
+
var _this = _super.call(this, id, val) || this;
|
|
25
25
|
_this._color = types_1.RBColor.RED;
|
|
26
|
+
_this._color = color;
|
|
26
27
|
return _this;
|
|
27
28
|
}
|
|
28
29
|
Object.defineProperty(RBTreeNode.prototype, "color", {
|
|
@@ -35,19 +36,6 @@ var RBTreeNode = /** @class */ (function (_super) {
|
|
|
35
36
|
enumerable: false,
|
|
36
37
|
configurable: true
|
|
37
38
|
});
|
|
38
|
-
/**
|
|
39
|
-
* The function creates a new RBTreeNode with the given id, value, and count and returns it as a FAMILY object.
|
|
40
|
-
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
|
|
41
|
-
* identify each node in the tree.
|
|
42
|
-
* @param {T | null} [val] - The "val" parameter represents the value to be stored in the node. It can be of type T
|
|
43
|
-
* (generic type) or null.
|
|
44
|
-
* @param {number} [count] - The `count` parameter represents the number of occurrences of the value in the binary tree
|
|
45
|
-
* node.
|
|
46
|
-
* @returns The method is returning a new instance of the RBTreeNode class, casted as a FAMILY type.
|
|
47
|
-
*/
|
|
48
|
-
RBTreeNode.prototype.createNode = function (id, val, count) {
|
|
49
|
-
return new RBTreeNode(id, val, count);
|
|
50
|
-
};
|
|
51
39
|
return RBTreeNode;
|
|
52
40
|
}(bst_1.BSTNode));
|
|
53
41
|
exports.RBTreeNode = RBTreeNode;
|
|
@@ -56,8 +44,8 @@ var RBTree = /** @class */ (function (_super) {
|
|
|
56
44
|
function RBTree(options) {
|
|
57
45
|
return _super.call(this, options) || this;
|
|
58
46
|
}
|
|
59
|
-
RBTree.prototype.createNode = function (id, val
|
|
60
|
-
return new RBTreeNode(id,
|
|
47
|
+
RBTree.prototype.createNode = function (id, val) {
|
|
48
|
+
return new RBTreeNode(id, types_1.RBColor.RED, val);
|
|
61
49
|
};
|
|
62
50
|
// private override _root: BinaryTreeNode<N> | null = null;
|
|
63
51
|
//
|