doubly-linked-list-typed 1.51.9 → 1.52.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/base/index.d.ts +2 -1
- package/dist/data-structures/base/index.js +2 -1
- package/dist/data-structures/base/iterable-element-base.d.ts +171 -0
- package/dist/data-structures/base/iterable-element-base.js +225 -0
- package/dist/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
- package/dist/data-structures/base/{iterable-base.js → iterable-entry-base.js} +12 -189
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +13 -13
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- package/dist/data-structures/binary-tree/avl-tree.d.ts +13 -13
- package/dist/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/data-structures/binary-tree/binary-tree.d.ts +99 -99
- package/dist/data-structures/binary-tree/binary-tree.js +54 -52
- package/dist/data-structures/binary-tree/bst.d.ts +37 -45
- package/dist/data-structures/binary-tree/bst.js +17 -25
- package/dist/data-structures/binary-tree/rb-tree.d.ts +10 -10
- package/dist/data-structures/binary-tree/rb-tree.js +6 -6
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +12 -12
- package/dist/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/data-structures/graph/directed-graph.js +2 -1
- package/dist/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/data-structures/heap/heap.d.ts +43 -114
- package/dist/data-structures/heap/heap.js +59 -127
- package/dist/data-structures/heap/max-heap.d.ts +50 -4
- package/dist/data-structures/heap/max-heap.js +76 -10
- package/dist/data-structures/heap/min-heap.d.ts +51 -5
- package/dist/data-structures/heap/min-heap.js +68 -11
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
- package/dist/data-structures/linked-list/doubly-linked-list.js +26 -28
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +22 -25
- package/dist/data-structures/linked-list/singly-linked-list.js +29 -26
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
- package/dist/data-structures/priority-queue/max-priority-queue.js +79 -10
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
- package/dist/data-structures/priority-queue/min-priority-queue.js +71 -11
- package/dist/data-structures/priority-queue/priority-queue.d.ts +50 -4
- package/dist/data-structures/priority-queue/priority-queue.js +70 -1
- package/dist/data-structures/queue/deque.d.ts +27 -18
- package/dist/data-structures/queue/deque.js +43 -21
- package/dist/data-structures/queue/queue.d.ts +8 -29
- package/dist/data-structures/queue/queue.js +15 -32
- package/dist/data-structures/stack/stack.d.ts +17 -22
- package/dist/data-structures/stack/stack.js +25 -24
- package/dist/data-structures/trie/trie.d.ts +18 -13
- package/dist/data-structures/trie/trie.js +26 -15
- package/dist/interfaces/binary-tree.d.ts +4 -4
- package/dist/types/common.d.ts +1 -22
- package/dist/types/data-structures/base/base.d.ts +5 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +20 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +5 -3
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
- package/dist/types/data-structures/heap/heap.d.ts +3 -2
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +4 -2
- package/dist/types/data-structures/queue/queue.d.ts +2 -1
- package/dist/types/data-structures/stack/stack.d.ts +2 -1
- package/dist/types/data-structures/trie/trie.d.ts +3 -2
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +2 -1
- package/src/data-structures/base/iterable-element-base.ts +250 -0
- package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +14 -15
- package/src/data-structures/binary-tree/avl-tree.ts +13 -14
- package/src/data-structures/binary-tree/binary-tree.ts +156 -152
- package/src/data-structures/binary-tree/bst.ts +52 -60
- package/src/data-structures/binary-tree/rb-tree.ts +12 -13
- package/src/data-structures/binary-tree/tree-multi-map.ts +12 -13
- package/src/data-structures/graph/directed-graph.ts +2 -1
- package/src/data-structures/hash/hash-map.ts +4 -4
- package/src/data-structures/heap/heap.ts +71 -152
- package/src/data-structures/heap/max-heap.ts +88 -13
- package/src/data-structures/heap/min-heap.ts +78 -15
- package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
- package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
- package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
- package/src/data-structures/priority-queue/priority-queue.ts +81 -4
- package/src/data-structures/queue/deque.ts +50 -25
- package/src/data-structures/queue/queue.ts +23 -37
- package/src/data-structures/stack/stack.ts +31 -26
- package/src/data-structures/trie/trie.ts +33 -18
- package/src/interfaces/binary-tree.ts +4 -5
- package/src/types/common.ts +2 -24
- package/src/types/data-structures/base/base.ts +14 -6
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -3
- package/src/types/data-structures/binary-tree/avl-tree.ts +2 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +24 -5
- package/src/types/data-structures/binary-tree/bst.ts +9 -3
- package/src/types/data-structures/binary-tree/rb-tree.ts +2 -3
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -3
- package/src/types/data-structures/heap/heap.ts +4 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
- package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/types/data-structures/queue/deque.ts +6 -1
- package/src/types/data-structures/queue/queue.ts +3 -1
- package/src/types/data-structures/stack/stack.ts +3 -1
- package/src/types/data-structures/trie/trie.ts +3 -1
|
@@ -39,7 +39,7 @@ class BinaryTreeNode {
|
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* The function sets the left child of a node and updates its parent reference.
|
|
42
|
-
* @param {NODE
|
|
42
|
+
* @param {OptBTNOrNull<NODE>} v - The parameter `v` can be of type `NODE`, `null`, or
|
|
43
43
|
* `undefined`.
|
|
44
44
|
*/
|
|
45
45
|
set left(v) {
|
|
@@ -58,7 +58,7 @@ class BinaryTreeNode {
|
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
60
|
* The function sets the right child of a node and updates its parent.
|
|
61
|
-
* @param {NODE
|
|
61
|
+
* @param {OptBTNOrNull<NODE>} v - The parameter `v` can be of type `NODE`, `null`, or
|
|
62
62
|
* `undefined`.
|
|
63
63
|
*/
|
|
64
64
|
set right(v) {
|
|
@@ -96,7 +96,7 @@ exports.BinaryTreeNode = BinaryTreeNode;
|
|
|
96
96
|
class BinaryTree extends base_1.IterableEntryBase {
|
|
97
97
|
/**
|
|
98
98
|
* The constructor function initializes a binary tree object with optional keysOrNodesOrEntriesOrRawElements and options.
|
|
99
|
-
* @param [keysOrNodesOrEntriesOrRawElements] -
|
|
99
|
+
* @param [keysOrNodesOrEntriesOrRawElements] - Optional iterable of BTNKeyOrNodeOrEntry objects. These objects represent the
|
|
100
100
|
* nodes to be added to the binary tree.
|
|
101
101
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
102
102
|
* configuration options for the binary tree. In this case, it is of type
|
|
@@ -115,6 +115,8 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
115
115
|
this.iterationType = iterationType;
|
|
116
116
|
if (typeof toEntryFn === 'function')
|
|
117
117
|
this._toEntryFn = toEntryFn;
|
|
118
|
+
else if (toEntryFn)
|
|
119
|
+
throw TypeError('toEntryFn must be a function type');
|
|
118
120
|
}
|
|
119
121
|
if (keysOrNodesOrEntriesOrRawElements)
|
|
120
122
|
this.addMany(keysOrNodesOrEntriesOrRawElements);
|
|
@@ -170,8 +172,8 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
170
172
|
/**
|
|
171
173
|
* The function `keyValueOrEntryOrRawElementToNode` converts a key-value pair, entry, or raw element
|
|
172
174
|
* into a node object.
|
|
173
|
-
* @param {R |
|
|
174
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
175
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
176
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
175
177
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
176
178
|
* `keyValueOrEntryOrRawElementToNode` function. It represents the value associated with a key in a
|
|
177
179
|
* key-value pair. If provided, it will be used to create a node with the specified key and value.
|
|
@@ -215,8 +217,8 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
215
217
|
*
|
|
216
218
|
* The `ensureNode` function checks if the input is a valid node and returns it, or converts it to a
|
|
217
219
|
* node if it is a key or entry.
|
|
218
|
-
* @param {R |
|
|
219
|
-
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, `
|
|
220
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
221
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
|
|
220
222
|
* a raw element.
|
|
221
223
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
222
224
|
* parameter that specifies the type of iteration to be used when searching for a node. It has a
|
|
@@ -251,8 +253,8 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
251
253
|
}
|
|
252
254
|
/**
|
|
253
255
|
* The function checks if the input is an instance of the BinaryTreeNode class.
|
|
254
|
-
* @param {R |
|
|
255
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
256
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
257
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
256
258
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
257
259
|
* an instance of the `BinaryTreeNode` class.
|
|
258
260
|
*/
|
|
@@ -261,8 +263,8 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
261
263
|
}
|
|
262
264
|
/**
|
|
263
265
|
* The function checks if a given node is a valid node in a binary search tree.
|
|
264
|
-
* @param {R |
|
|
265
|
-
* `
|
|
266
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
|
|
267
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
266
268
|
* @returns a boolean value.
|
|
267
269
|
*/
|
|
268
270
|
isRealNode(node) {
|
|
@@ -272,8 +274,8 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
272
274
|
}
|
|
273
275
|
/**
|
|
274
276
|
* The function checks if a given node is a real node or null.
|
|
275
|
-
* @param {R |
|
|
276
|
-
* `
|
|
277
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
|
|
278
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
277
279
|
* @returns a boolean value.
|
|
278
280
|
*/
|
|
279
281
|
isNodeOrNull(node) {
|
|
@@ -281,8 +283,8 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
281
283
|
}
|
|
282
284
|
/**
|
|
283
285
|
* The function checks if a given node is equal to the NIL value.
|
|
284
|
-
* @param {R |
|
|
285
|
-
* `
|
|
286
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
|
|
287
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
286
288
|
* @returns a boolean value.
|
|
287
289
|
*/
|
|
288
290
|
isNIL(node) {
|
|
@@ -291,8 +293,8 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
291
293
|
/**
|
|
292
294
|
* The function checks if the input is an array with two elements, indicating it is a binary tree
|
|
293
295
|
* node entry.
|
|
294
|
-
* @param {R |
|
|
295
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
296
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
297
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
296
298
|
* @returns a boolean value.
|
|
297
299
|
*/
|
|
298
300
|
isEntry(keyOrNodeOrEntryOrRawElement) {
|
|
@@ -340,10 +342,10 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
340
342
|
*
|
|
341
343
|
* The `add` function is used to insert a new node into a binary tree, checking for duplicate keys
|
|
342
344
|
* and finding the appropriate insertion position.
|
|
343
|
-
* @param {R |
|
|
345
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
344
346
|
* `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which represents the key,
|
|
345
347
|
* node, entry, or raw element to be added to the tree. It can also accept a value of type
|
|
346
|
-
* `
|
|
348
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>
|
|
347
349
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
348
350
|
* key being added to the tree. It represents the value that will be stored in the tree for the given
|
|
349
351
|
* key.
|
|
@@ -445,7 +447,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
445
447
|
*
|
|
446
448
|
* The `refill` function clears the current data and adds new data to the collection.
|
|
447
449
|
* @param keysOrNodesOrEntriesOrRawElements - An iterable collection of keys, nodes, entries, or raw
|
|
448
|
-
* elements. These can be of any type (R) or a specific type (
|
|
450
|
+
* elements. These can be of any type (R) or a specific type (BTNKeyOrNodeOrEntry<K, V, NODE>).
|
|
449
451
|
* @param [values] - The `values` parameter is an optional iterable of values that will be associated
|
|
450
452
|
* with the keys or nodes being added. If provided, the values will be assigned to the corresponding
|
|
451
453
|
* keys or nodes. If not provided, the values will be set to `undefined`.
|
|
@@ -540,7 +542,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
540
542
|
* the identifier or all nodes that match the identifier. If set to true, only the first matching
|
|
541
543
|
* node will be returned. If set to false, all matching nodes will be returned. The default value is
|
|
542
544
|
* false.
|
|
543
|
-
* @param {R |
|
|
545
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
544
546
|
* point for the search. It can be either a node object, a key-value pair, or a key. If it is not
|
|
545
547
|
* provided, the `root` of the data structure is used as the starting point.
|
|
546
548
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
@@ -599,7 +601,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
599
601
|
* the `C` callback function, or it can be `null` or `undefined`.
|
|
600
602
|
* @param {C} callback - The `callback` parameter is a function that will be used to determine if a
|
|
601
603
|
* node matches the desired criteria. It should return a value that can be used to identify the node.
|
|
602
|
-
* @param {R |
|
|
604
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
603
605
|
* point for searching nodes in a tree structure. It can be either a root node, a key-value pair, or
|
|
604
606
|
* a node entry. If not provided, the search will start from the root of the tree.
|
|
605
607
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -644,7 +646,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
644
646
|
* callback function `C`. It can also be `null` or `undefined` if no identifier is provided.
|
|
645
647
|
* @param {C} callback - The `callback` parameter is a function that will be used to determine if a
|
|
646
648
|
* node matches the given identifier. It is optional and defaults to `this._DEFAULT_CALLBACK`.
|
|
647
|
-
* @param {R |
|
|
649
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
648
650
|
* point for the search in the binary tree. It can be either a root node of the tree or a key, node,
|
|
649
651
|
* or entry object that exists in the tree. If no specific starting point is provided, the search
|
|
650
652
|
* will begin from the root of the
|
|
@@ -675,7 +677,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
675
677
|
* @param {C} callback - The `callback` parameter is a function that will be used to determine
|
|
676
678
|
* whether a node should be included in the result or not. It is of type `C`, which extends the
|
|
677
679
|
* `BTNCallback<NODE>` type.
|
|
678
|
-
* @param {R |
|
|
680
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
679
681
|
* point for the iteration in the data structure. It can be either a root node, a key-value pair, or
|
|
680
682
|
* a node entry. If not specified, it defaults to the root of the data structure.
|
|
681
683
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -724,10 +726,10 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
724
726
|
*
|
|
725
727
|
* The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
|
|
726
728
|
* height of the tree.
|
|
727
|
-
* @param {R |
|
|
729
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The parameter `beginRoot` is optional and
|
|
728
730
|
* has a default value of `this.root`. It represents the starting point for checking if the tree is
|
|
729
731
|
* perfectly balanced. It can be either a root node (`R`), a key or node or entry
|
|
730
|
-
* (`
|
|
732
|
+
* (`BTNKeyOrNodeOrEntry<K, V, NODE
|
|
731
733
|
* @returns a boolean value.
|
|
732
734
|
*/
|
|
733
735
|
isPerfectlyBalanced(beginRoot = this.root) {
|
|
@@ -742,7 +744,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
742
744
|
* Space Complexity: O(1)
|
|
743
745
|
*
|
|
744
746
|
* The function `isBST` checks if a binary search tree is valid, either recursively or iteratively.
|
|
745
|
-
* @param {R |
|
|
747
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
746
748
|
* starting point for checking if a binary search tree (BST) is valid. It can be either a root node
|
|
747
749
|
* of the BST, a key value of a node in the BST, or an entry object containing both the key and value
|
|
748
750
|
* of a node in the BST
|
|
@@ -802,10 +804,10 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
802
804
|
* Space Complexity: O(1)
|
|
803
805
|
*
|
|
804
806
|
* The function calculates the depth of a given node or key in a tree-like data structure.
|
|
805
|
-
* @param {R |
|
|
806
|
-
* (representing a root node), or a `
|
|
807
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} dist - The `dist` parameter can be either a `R`
|
|
808
|
+
* (representing a root node), or a `BTNKeyOrNodeOrEntry<K, V, NODE>` (representing a key, node, or
|
|
807
809
|
* entry).
|
|
808
|
-
* @param {R |
|
|
810
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is optional and
|
|
809
811
|
* represents the starting point from which to calculate the depth. It can be either a reference to a
|
|
810
812
|
* node in the tree or a key-value pair or an entry object. If not provided, the default value is
|
|
811
813
|
* `this.root`, which refers to the root node
|
|
@@ -834,9 +836,9 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
834
836
|
*
|
|
835
837
|
* The `getHeight` function calculates the maximum height of a binary tree using either a recursive
|
|
836
838
|
* or iterative approach.
|
|
837
|
-
* @param {R |
|
|
839
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
838
840
|
* starting point for calculating the height of a tree. It can be either a root node (`R`), a key or
|
|
839
|
-
* node or entry (`
|
|
841
|
+
* node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current tree.
|
|
840
842
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
841
843
|
* iteration used to calculate the height of the tree. It can have two possible values:
|
|
842
844
|
* @returns the maximum height of the binary tree.
|
|
@@ -879,9 +881,9 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
879
881
|
*
|
|
880
882
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
881
883
|
* recursive or iterative approach.
|
|
882
|
-
* @param {R |
|
|
884
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
883
885
|
* starting point for calculating the minimum height of a tree. It can be either a root node (`R`), a
|
|
884
|
-
* key or node or entry (`
|
|
886
|
+
* key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current
|
|
885
887
|
* tree.
|
|
886
888
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
887
889
|
* iteration to be used when calculating the minimum height of the tree. It can have two possible
|
|
@@ -944,8 +946,8 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
944
946
|
*
|
|
945
947
|
* The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
|
|
946
948
|
* up to the root node, with an option to reverse the order of the nodes.
|
|
947
|
-
* @param {R |
|
|
948
|
-
* type `R` or `
|
|
949
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginNode - The `beginNode` parameter can be either of
|
|
950
|
+
* type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
949
951
|
* @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
|
|
950
952
|
* resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
|
|
951
953
|
* reversed before returning it. If `isReverse` is set to `false` or not provided, the path will
|
|
@@ -974,9 +976,9 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
974
976
|
*
|
|
975
977
|
* The `getLeftMost` function returns the leftmost node in a binary tree, either using recursive or
|
|
976
978
|
* iterative traversal.
|
|
977
|
-
* @param {R |
|
|
979
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
978
980
|
* starting point for finding the leftmost node in a binary tree. It can be either a root node (`R`),
|
|
979
|
-
* a key or node or entry (`
|
|
981
|
+
* a key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
|
|
980
982
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
981
983
|
* of iteration to be performed. It can have two possible values:
|
|
982
984
|
* @returns The function `getLeftMost` returns the leftmost node in a binary tree.
|
|
@@ -1015,9 +1017,9 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1015
1017
|
*
|
|
1016
1018
|
* The `getRightMost` function returns the rightmost node in a binary tree, either recursively or
|
|
1017
1019
|
* iteratively.
|
|
1018
|
-
* @param {R |
|
|
1020
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
1019
1021
|
* starting point for finding the rightmost node in a binary tree. It can be either a root node
|
|
1020
|
-
* (`R`), a key or node or entry (`
|
|
1022
|
+
* (`R`), a key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
|
|
1021
1023
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
1022
1024
|
* of iteration to be performed when finding the rightmost node in a binary tree. It can have two
|
|
1023
1025
|
* possible values:
|
|
@@ -1117,7 +1119,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1117
1119
|
* return type of the callback function is determined by the generic type `C`.
|
|
1118
1120
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter determines the order in which the
|
|
1119
1121
|
* nodes are visited during the depth-first search. It can have one of the following values:
|
|
1120
|
-
* @param {R |
|
|
1122
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
1121
1123
|
* point of the depth-first search. It can be either a node object, a key-value pair, or a key. If it
|
|
1122
1124
|
* is a key or key-value pair, the method will find the corresponding node in the tree and start the
|
|
1123
1125
|
* search from there.
|
|
@@ -1248,7 +1250,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1248
1250
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
1249
1251
|
* the breadth-first search traversal. It takes a single argument, which is the current node being
|
|
1250
1252
|
* visited, and returns a value of any type.
|
|
1251
|
-
* @param {R |
|
|
1253
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
1252
1254
|
* starting point of the breadth-first search. It can be either a root node of a tree or a key, node,
|
|
1253
1255
|
* or entry object. If no value is provided, the `root` property of the class is used as the default
|
|
1254
1256
|
* starting point.
|
|
@@ -1326,7 +1328,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1326
1328
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
1327
1329
|
* the tree. It takes a node as an argument and returns a value. The return type of the callback
|
|
1328
1330
|
* function is determined by the generic type `C` which extends `BTNCallback<NODE | null>`.
|
|
1329
|
-
* @param {R |
|
|
1331
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
1330
1332
|
* starting point for traversing the tree. It can be either a root node, a key-value pair, or a node
|
|
1331
1333
|
* entry. If no value is provided, the `root` property of the class is used as the default starting
|
|
1332
1334
|
* point.
|
|
@@ -1404,7 +1406,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1404
1406
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function is used
|
|
1405
1407
|
* to specify the order in which the nodes of a binary tree are traversed. It can take one of the
|
|
1406
1408
|
* following values:
|
|
1407
|
-
* @param {R |
|
|
1409
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
1408
1410
|
* point for the traversal. It can be either a node object, a key, or an entry object. If no value is
|
|
1409
1411
|
* provided, the `root` of the tree is used as the starting point.
|
|
1410
1412
|
* @returns The function `morris` returns an array of values that are the return values of the
|
|
@@ -1590,7 +1592,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1590
1592
|
* Space Complexity: O(n)
|
|
1591
1593
|
*
|
|
1592
1594
|
* The `print` function in TypeScript prints the binary tree structure with customizable options.
|
|
1593
|
-
* @param {R |
|
|
1595
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
1594
1596
|
* point for printing the binary tree. It can be either a node of the binary tree or a key or entry
|
|
1595
1597
|
* that exists in the binary tree. If no value is provided, the root of the binary tree will be used
|
|
1596
1598
|
* as the starting point.
|
|
@@ -1673,7 +1675,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1673
1675
|
*
|
|
1674
1676
|
* The `_displayAux` function is responsible for generating the display layout of a binary tree node,
|
|
1675
1677
|
* taking into account various options such as whether to show null, undefined, or NaN nodes.
|
|
1676
|
-
* @param {NODE
|
|
1678
|
+
* @param {OptBTNOrNull<NODE>} node - The `node` parameter represents a node in a binary tree.
|
|
1677
1679
|
* It can be of type `NODE`, `null`, or `undefined`.
|
|
1678
1680
|
* @param {BinaryTreePrintOptions} options - The `options` parameter is an object that contains the
|
|
1679
1681
|
* following properties:
|
|
@@ -1699,12 +1701,12 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1699
1701
|
}
|
|
1700
1702
|
else if (node !== null && node !== undefined) {
|
|
1701
1703
|
// Display logic of normal nodes
|
|
1702
|
-
const key = node.key, line = this.isNIL(node) ? 'S' : key
|
|
1704
|
+
const key = node.key, line = this.isNIL(node) ? 'S' : String(key), width = line.length;
|
|
1703
1705
|
return _buildNodeDisplay(line, width, this._displayAux(node.left, options), this._displayAux(node.right, options));
|
|
1704
1706
|
}
|
|
1705
1707
|
else {
|
|
1706
1708
|
// For cases where none of the conditions are met, null, undefined, and NaN nodes are not displayed
|
|
1707
|
-
const line = node === undefined ? 'U' : '
|
|
1709
|
+
const line = node === undefined ? 'U' : 'N', width = line.length;
|
|
1708
1710
|
return _buildNodeDisplay(line, width, [[''], 1, 0, 0], [[''], 1, 0, 0]);
|
|
1709
1711
|
}
|
|
1710
1712
|
function _buildNodeDisplay(line, width, left, right) {
|
|
@@ -1745,10 +1747,10 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1745
1747
|
* Space Complexity: O(1)
|
|
1746
1748
|
*
|
|
1747
1749
|
* The function `_swapProperties` swaps the key-value properties between two nodes.
|
|
1748
|
-
* @param {R |
|
|
1750
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} srcNode - The source node that will be swapped with the
|
|
1749
1751
|
* destination node. It can be either an instance of the class `R`, or an object of type
|
|
1750
|
-
* `
|
|
1751
|
-
* @param {R |
|
|
1752
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
1753
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} destNode - The `destNode` parameter is the node where
|
|
1752
1754
|
* the properties will be swapped with the `srcNode`.
|
|
1753
1755
|
* @returns either the `destNode` object with its properties swapped with the `srcNode` object's
|
|
1754
1756
|
* properties, or `undefined` if either `srcNode` or `destNode` is falsy.
|
|
@@ -1812,7 +1814,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1812
1814
|
*
|
|
1813
1815
|
* The function sets the root property of an object to the provided value, and also updates the
|
|
1814
1816
|
* parent property of the new root.
|
|
1815
|
-
* @param {NODE
|
|
1817
|
+
* @param {OptBTNOrNull<NODE>} v - The parameter `v` is of type `OptBTNOrNull<NODE>`. This
|
|
1816
1818
|
* means that it can accept a value of type `NODE`, `null`, or `undefined`.
|
|
1817
1819
|
*/
|
|
1818
1820
|
_setRoot(v) {
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BSTNested, BSTNKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback,
|
|
8
|
+
import type { BSTNested, BSTNKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback, BTNKeyOrNodeOrEntry, Comparator, CP, DFSOrderPattern, IterationType, OptBSTN } from '../../types';
|
|
9
9
|
import { BTNEntry } from '../../types';
|
|
10
10
|
import { BinaryTree, BinaryTreeNode } from './binary-tree';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
|
-
export declare class BSTNode<K
|
|
12
|
+
export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, NODE> {
|
|
13
13
|
parent?: NODE;
|
|
14
14
|
constructor(key: K, value?: V);
|
|
15
15
|
protected _left?: NODE;
|
|
@@ -17,26 +17,26 @@ export declare class BSTNode<K extends Comparable, V = any, NODE extends BSTNode
|
|
|
17
17
|
* The function returns the value of the `_left` property.
|
|
18
18
|
* @returns The `_left` property of the current object is being returned.
|
|
19
19
|
*/
|
|
20
|
-
get left(): NODE
|
|
20
|
+
get left(): OptBSTN<NODE>;
|
|
21
21
|
/**
|
|
22
22
|
* The function sets the left child of a node and updates the parent reference of the child.
|
|
23
|
-
* @param {NODE
|
|
23
|
+
* @param {OptBSTN<NODE>} v - The parameter `v` is of type `OptBSTN<NODE>`. It can either be an
|
|
24
24
|
* instance of the `NODE` class or `undefined`.
|
|
25
25
|
*/
|
|
26
|
-
set left(v: NODE
|
|
26
|
+
set left(v: OptBSTN<NODE>);
|
|
27
27
|
protected _right?: NODE;
|
|
28
28
|
/**
|
|
29
29
|
* The function returns the right node of a binary tree or undefined if there is no right node.
|
|
30
30
|
* @returns The method is returning the value of the `_right` property, which is of type `NODE` or
|
|
31
31
|
* `undefined`.
|
|
32
32
|
*/
|
|
33
|
-
get right(): NODE
|
|
33
|
+
get right(): OptBSTN<NODE>;
|
|
34
34
|
/**
|
|
35
35
|
* The function sets the right child of a node and updates the parent reference of the child.
|
|
36
|
-
* @param {NODE
|
|
36
|
+
* @param {OptBSTN<NODE>} v - The parameter `v` is of type `OptBSTN<NODE>`. It can either be a
|
|
37
37
|
* `NODE` object or `undefined`.
|
|
38
38
|
*/
|
|
39
|
-
set right(v: NODE
|
|
39
|
+
set right(v: OptBSTN<NODE>);
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* 1. Node Order: Each node's left child has a lesser value, and the right child has a greater value.
|
|
@@ -47,7 +47,7 @@ export declare class BSTNode<K extends Comparable, V = any, NODE extends BSTNode
|
|
|
47
47
|
* 6. Balance Variability: Can become unbalanced; special types maintain balance.
|
|
48
48
|
* 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
|
|
49
49
|
*/
|
|
50
|
-
export declare class BST<K
|
|
50
|
+
export declare class BST<K = any, V = any, R = BTNEntry<K, V>, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, R, NODE, TREE> = BST<K, V, R, NODE, BSTNested<K, V, R, NODE>>> extends BinaryTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
51
51
|
/**
|
|
52
52
|
* This is the constructor function for a Binary Search Tree class in TypeScript.
|
|
53
53
|
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
|
|
@@ -56,13 +56,13 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
56
56
|
* @param [options] - An optional object that contains additional options for the Binary Search Tree.
|
|
57
57
|
* It can include a comparator function that defines the order of the elements in the tree.
|
|
58
58
|
*/
|
|
59
|
-
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R |
|
|
59
|
+
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: BSTOptions<K, V, R>);
|
|
60
60
|
protected _root?: NODE;
|
|
61
61
|
/**
|
|
62
62
|
* The function returns the root node of a tree structure.
|
|
63
63
|
* @returns The `_root` property of the object, which is of type `NODE` or `undefined`.
|
|
64
64
|
*/
|
|
65
|
-
get root(): NODE
|
|
65
|
+
get root(): OptBSTN<NODE>;
|
|
66
66
|
/**
|
|
67
67
|
* The function creates a new BSTNode with the given key and value and returns it.
|
|
68
68
|
* @param {K} key - The key parameter is of type K, which represents the type of the key for the node
|
|
@@ -82,21 +82,21 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
82
82
|
createTree(options?: Partial<BSTOptions<K, V, R>>): TREE;
|
|
83
83
|
/**
|
|
84
84
|
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
85
|
-
* @param {R |
|
|
86
|
-
* type R or
|
|
85
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - A variable that can be of
|
|
86
|
+
* type R or BTNKeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
|
|
87
87
|
* element.
|
|
88
88
|
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
89
89
|
* value associated with a key in a key-value pair.
|
|
90
90
|
* @returns either a NODE object or undefined.
|
|
91
91
|
*/
|
|
92
|
-
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R |
|
|
92
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): OptBSTN<NODE>;
|
|
93
93
|
/**
|
|
94
94
|
* Time Complexity: O(log n)
|
|
95
95
|
* Space Complexity: O(log n)
|
|
96
96
|
*
|
|
97
97
|
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
98
98
|
* it doesn't exist.
|
|
99
|
-
* @param {R |
|
|
99
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
100
100
|
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, which represents the key, node,
|
|
101
101
|
* entry, or raw element that needs to be ensured in the tree.
|
|
102
102
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
@@ -105,27 +105,27 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
105
105
|
* @returns The method is returning either the node that was ensured or `undefined` if the node could
|
|
106
106
|
* not be ensured.
|
|
107
107
|
*/
|
|
108
|
-
ensureNode(keyOrNodeOrEntryOrRawElement: R |
|
|
108
|
+
ensureNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBSTN<NODE>;
|
|
109
109
|
/**
|
|
110
110
|
* The function checks if the input is an instance of the BSTNode class.
|
|
111
|
-
* @param {R |
|
|
112
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
111
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
112
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
113
113
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
114
114
|
* an instance of the `BSTNode` class.
|
|
115
115
|
*/
|
|
116
|
-
isNode(keyOrNodeOrEntryOrRawElement: R |
|
|
116
|
+
isNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
|
|
117
117
|
/**
|
|
118
118
|
* Time Complexity: O(log n)
|
|
119
119
|
* Space Complexity: O(1)
|
|
120
120
|
*
|
|
121
121
|
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
122
|
-
* @param {R |
|
|
123
|
-
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `
|
|
122
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
123
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
124
124
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
125
125
|
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
126
126
|
* @returns a boolean value.
|
|
127
127
|
*/
|
|
128
|
-
add(keyOrNodeOrEntryOrRawElement: R |
|
|
128
|
+
add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
|
|
129
129
|
/**
|
|
130
130
|
* Time Complexity: O(log n)
|
|
131
131
|
* Space Complexity: O(log n)
|
|
@@ -151,7 +151,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
151
151
|
* @returns The function `addMany` returns an array of booleans indicating whether each element was
|
|
152
152
|
* successfully inserted into the data structure.
|
|
153
153
|
*/
|
|
154
|
-
addMany(keysOrNodesOrEntriesOrRawElements: Iterable<R |
|
|
154
|
+
addMany(keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
|
|
155
155
|
/**
|
|
156
156
|
* Time Complexity: O(log n)
|
|
157
157
|
* Space Complexity: O(k + log n)
|
|
@@ -167,14 +167,14 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
167
167
|
* @param [onlyOne=false] - A boolean value indicating whether to return only the first matching node
|
|
168
168
|
* or all matching nodes. If set to true, only the first matching node will be returned. If set to
|
|
169
169
|
* false, all matching nodes will be returned. The default value is false.
|
|
170
|
-
* @param {R |
|
|
170
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
171
171
|
* point for the search in the binary tree. It can be either a node object, a key-value pair, or an
|
|
172
172
|
* entry object. If it is not provided, the `root` of the binary tree is used as the starting point.
|
|
173
173
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
174
174
|
* iteration to be performed. It can have two possible values:
|
|
175
175
|
* @returns The method `getNodes` returns an array of `NODE` objects.
|
|
176
176
|
*/
|
|
177
|
-
getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: R |
|
|
177
|
+
getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
178
178
|
/**
|
|
179
179
|
* Time Complexity: O(log n)
|
|
180
180
|
* Space Complexity: O(1)
|
|
@@ -200,7 +200,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
200
200
|
* of the following values:
|
|
201
201
|
* @returns The method is returning a NODE object or undefined.
|
|
202
202
|
*/
|
|
203
|
-
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: R | BSTNKeyOrNode<K, NODE>, iterationType?: IterationType): NODE
|
|
203
|
+
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: R | BSTNKeyOrNode<K, NODE>, iterationType?: IterationType): OptBSTN<NODE>;
|
|
204
204
|
/**
|
|
205
205
|
* Time Complexity: O(k log n)
|
|
206
206
|
* Space Complexity: O(k + log n)
|
|
@@ -218,7 +218,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
218
218
|
* It has a default value of `'ITERATIVE'`.
|
|
219
219
|
* @returns The method is returning a NODE object or undefined.
|
|
220
220
|
*/
|
|
221
|
-
getNodeByKey(key: K, iterationType?: IterationType): NODE
|
|
221
|
+
getNodeByKey(key: K, iterationType?: IterationType): OptBSTN<NODE>;
|
|
222
222
|
/**
|
|
223
223
|
* Time Complexity: O(log n)
|
|
224
224
|
* Space Complexity: O(k + log n)
|
|
@@ -235,7 +235,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
235
235
|
* @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
|
|
236
236
|
* order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
|
|
237
237
|
* take one of the following values:
|
|
238
|
-
* @param {R |
|
|
238
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
239
239
|
* point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
|
|
240
240
|
* node entry. If not specified, the default value is the root of the tree.
|
|
241
241
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
|
|
@@ -243,7 +243,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
243
243
|
* following values:
|
|
244
244
|
* @returns The method is returning an array of the return type of the callback function.
|
|
245
245
|
*/
|
|
246
|
-
dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R |
|
|
246
|
+
dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
247
247
|
/**
|
|
248
248
|
* Time Complexity: O(log n)
|
|
249
249
|
* Space Complexity: O(1)
|
|
@@ -257,7 +257,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
257
257
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
258
258
|
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
259
259
|
* node being visited, and it can return a value of any type.
|
|
260
|
-
* @param {R |
|
|
260
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
261
261
|
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
262
262
|
* object. If no value is provided, the default value is the root of the tree.
|
|
263
263
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -265,7 +265,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
265
265
|
* the following values:
|
|
266
266
|
* @returns an array of the return type of the callback function.
|
|
267
267
|
*/
|
|
268
|
-
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R |
|
|
268
|
+
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
269
269
|
/**
|
|
270
270
|
* Time Complexity: O(log n)
|
|
271
271
|
* Space Complexity: O(1)
|
|
@@ -279,7 +279,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
279
279
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
280
280
|
* `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
|
|
281
281
|
* tree during the iteration process.
|
|
282
|
-
* @param {R |
|
|
282
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
283
283
|
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
284
284
|
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
285
285
|
* value is provided, the root of
|
|
@@ -288,7 +288,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
288
288
|
* @returns The method is returning a two-dimensional array of the return type of the callback
|
|
289
289
|
* function.
|
|
290
290
|
*/
|
|
291
|
-
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R |
|
|
291
|
+
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[][];
|
|
292
292
|
/**
|
|
293
293
|
* Time complexity: O(n)
|
|
294
294
|
* Space complexity: O(n)
|
|
@@ -305,7 +305,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
305
305
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
306
306
|
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
307
307
|
* 0, or 1, where:
|
|
308
|
-
* @param {R |
|
|
308
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} targetNode - The `targetNode` parameter is the node in
|
|
309
309
|
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
310
310
|
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
311
311
|
* `targetNode` is provided,
|
|
@@ -314,7 +314,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
314
314
|
* @returns The function `lesserOrGreaterTraverse` returns an array of values of type
|
|
315
315
|
* `ReturnType<C>`, which is the return type of the callback function passed as an argument.
|
|
316
316
|
*/
|
|
317
|
-
lesserOrGreaterTraverse<C extends BTNCallback<NODE>>(callback?: C, lesserOrGreater?: CP, targetNode?: R |
|
|
317
|
+
lesserOrGreaterTraverse<C extends BTNCallback<NODE>>(callback?: C, lesserOrGreater?: CP, targetNode?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
318
318
|
/**
|
|
319
319
|
* Time complexity: O(n)
|
|
320
320
|
* Space complexity: O(n)
|
|
@@ -349,15 +349,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
349
349
|
* @returns a boolean value.
|
|
350
350
|
*/
|
|
351
351
|
isAVLBalanced(iterationType?: IterationType): boolean;
|
|
352
|
-
/**
|
|
353
|
-
* Time complexity: O(n)
|
|
354
|
-
* Space complexity: O(n)
|
|
355
|
-
*/
|
|
356
352
|
protected _DEFAULT_COMPARATOR: (a: K, b: K) => number;
|
|
357
|
-
/**
|
|
358
|
-
* Time complexity: O(n)
|
|
359
|
-
* Space complexity: O(n)
|
|
360
|
-
*/
|
|
361
353
|
protected _comparator: Comparator<K>;
|
|
362
354
|
/**
|
|
363
355
|
* Time Complexity: O(n)
|
|
@@ -371,7 +363,7 @@ export declare class BST<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE
|
|
|
371
363
|
/**
|
|
372
364
|
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
373
365
|
* root.
|
|
374
|
-
* @param {NODE
|
|
366
|
+
* @param {OptBSTN<NODE>} v - v is a parameter of type NODE or undefined.
|
|
375
367
|
*/
|
|
376
|
-
protected _setRoot(v: NODE
|
|
368
|
+
protected _setRoot(v: OptBSTN<NODE>): void;
|
|
377
369
|
}
|