priority-queue-typed 1.48.1 → 1.48.3
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 +1 -0
- package/dist/data-structures/base/index.js +17 -0
- package/dist/data-structures/base/iterable-base.d.ts +232 -0
- package/dist/data-structures/base/iterable-base.js +312 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +16 -16
- package/dist/data-structures/binary-tree/avl-tree.js +7 -7
- package/dist/data-structures/binary-tree/binary-tree.d.ts +121 -152
- package/dist/data-structures/binary-tree/binary-tree.js +140 -182
- package/dist/data-structures/binary-tree/bst.d.ts +28 -47
- package/dist/data-structures/binary-tree/bst.js +54 -57
- package/dist/data-structures/binary-tree/rb-tree.d.ts +15 -15
- package/dist/data-structures/binary-tree/rb-tree.js +7 -7
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +22 -22
- package/dist/data-structures/binary-tree/tree-multimap.js +11 -11
- package/dist/data-structures/graph/abstract-graph.d.ts +44 -6
- package/dist/data-structures/graph/abstract-graph.js +50 -27
- package/dist/data-structures/hash/hash-map.d.ts +59 -100
- package/dist/data-structures/hash/hash-map.js +69 -173
- package/dist/data-structures/heap/heap.d.ts +50 -7
- package/dist/data-structures/heap/heap.js +60 -30
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +38 -51
- package/dist/data-structures/linked-list/doubly-linked-list.js +46 -73
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +32 -51
- package/dist/data-structures/linked-list/singly-linked-list.js +40 -73
- package/dist/data-structures/queue/deque.d.ts +29 -51
- package/dist/data-structures/queue/deque.js +36 -71
- package/dist/data-structures/queue/queue.d.ts +49 -48
- package/dist/data-structures/queue/queue.js +69 -82
- package/dist/data-structures/stack/stack.d.ts +43 -10
- package/dist/data-structures/stack/stack.js +50 -31
- package/dist/data-structures/trie/trie.d.ts +41 -6
- package/dist/data-structures/trie/trie.js +53 -32
- package/dist/interfaces/binary-tree.d.ts +6 -6
- package/dist/types/common.d.ts +11 -8
- package/dist/types/common.js +6 -1
- package/dist/types/data-structures/base/base.d.ts +5 -0
- package/dist/types/data-structures/base/base.js +2 -0
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/index.js +17 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
- package/dist/types/data-structures/index.d.ts +1 -0
- package/dist/types/data-structures/index.js +1 -0
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-base.ts +329 -0
- package/src/data-structures/binary-tree/avl-tree.ts +20 -21
- package/src/data-structures/binary-tree/binary-tree.ts +222 -267
- package/src/data-structures/binary-tree/bst.ts +86 -82
- package/src/data-structures/binary-tree/rb-tree.ts +25 -26
- package/src/data-structures/binary-tree/tree-multimap.ts +30 -35
- package/src/data-structures/graph/abstract-graph.ts +55 -28
- package/src/data-structures/hash/hash-map.ts +76 -185
- package/src/data-structures/heap/heap.ts +63 -36
- package/src/data-structures/index.ts +1 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +50 -79
- package/src/data-structures/linked-list/singly-linked-list.ts +45 -80
- package/src/data-structures/queue/deque.ts +40 -82
- package/src/data-structures/queue/queue.ts +72 -87
- package/src/data-structures/stack/stack.ts +53 -34
- package/src/data-structures/trie/trie.ts +58 -35
- package/src/interfaces/binary-tree.ts +5 -6
- package/src/types/common.ts +11 -8
- package/src/types/data-structures/base/base.ts +6 -0
- package/src/types/data-structures/base/index.ts +1 -0
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +6 -5
- package/src/types/data-structures/binary-tree/bst.ts +6 -6
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/tree-multimap.ts +3 -3
- package/src/types/data-structures/index.ts +1 -0
|
@@ -29,7 +29,7 @@ exports.AVLTreeNode = AVLTreeNode;
|
|
|
29
29
|
class AVLTree extends bst_1.BST {
|
|
30
30
|
/**
|
|
31
31
|
* The constructor function initializes an AVLTree object with optional elements and options.
|
|
32
|
-
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<V, N>`
|
|
32
|
+
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<K, V, N>`
|
|
33
33
|
* objects. It represents a collection of elements that will be added to the AVL tree during
|
|
34
34
|
* initialization.
|
|
35
35
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
@@ -43,7 +43,7 @@ class AVLTree extends bst_1.BST {
|
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* The function creates a new AVL tree node with the specified key and value.
|
|
46
|
-
* @param {
|
|
46
|
+
* @param {K} key - The key parameter is the key value that will be associated with
|
|
47
47
|
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
48
48
|
* @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
|
|
49
49
|
* type `V`, which means it can be any value that is assignable to the `value` property of the
|
|
@@ -61,11 +61,11 @@ class AVLTree extends bst_1.BST {
|
|
|
61
61
|
* @returns a new AVLTree object.
|
|
62
62
|
*/
|
|
63
63
|
createTree(options) {
|
|
64
|
-
return new AVLTree([], Object.assign({ iterationType: this.iterationType,
|
|
64
|
+
return new AVLTree([], Object.assign({ iterationType: this.iterationType, variant: this.variant }, options));
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* The function checks if an exemplar is an instance of AVLTreeNode.
|
|
68
|
-
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`.
|
|
68
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
|
|
69
69
|
* @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
|
|
70
70
|
*/
|
|
71
71
|
isNode(exemplar) {
|
|
@@ -126,9 +126,9 @@ class AVLTree extends bst_1.BST {
|
|
|
126
126
|
/**
|
|
127
127
|
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
|
|
128
128
|
* tree.
|
|
129
|
-
* @param {
|
|
130
|
-
* needs to be swapped with the destination node. It can be of type `
|
|
131
|
-
* @param {
|
|
129
|
+
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node that
|
|
130
|
+
* needs to be swapped with the destination node. It can be of type `K`, `N`, or `undefined`.
|
|
131
|
+
* @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
|
|
132
132
|
* node where the values from the source node will be swapped to.
|
|
133
133
|
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
134
134
|
* if either `srcNode` or `destNode` is undefined.
|
|
@@ -5,19 +5,20 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback,
|
|
9
|
-
import { BinaryTreeNested, BinaryTreePrintOptions, BiTreeDeleteResult, DFSOrderPattern, FamilyPosition, IterationType, NodeDisplayLayout } from '../../types';
|
|
8
|
+
import type { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNodeEntry, BTNodeExemplar, BTNodeKeyOrNode } from '../../types';
|
|
9
|
+
import { BinaryTreeNested, BinaryTreePrintOptions, BiTreeDeleteResult, DFSOrderPattern, FamilyPosition, IterationType, NodeDisplayLayout, PairCallback } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
|
+
import { IterablePairBase } from "../base";
|
|
11
12
|
/**
|
|
12
13
|
* Represents a node in a binary tree.
|
|
13
14
|
* @template V - The type of data stored in the node.
|
|
14
15
|
* @template N - The type of the family relationship in the binary tree.
|
|
15
16
|
*/
|
|
16
|
-
export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>> {
|
|
17
|
-
key:
|
|
17
|
+
export declare class BinaryTreeNode<K = any, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>> {
|
|
18
|
+
key: K;
|
|
18
19
|
value?: V;
|
|
19
20
|
parent?: N;
|
|
20
|
-
constructor(key:
|
|
21
|
+
constructor(key: K, value?: V);
|
|
21
22
|
protected _left?: N | null;
|
|
22
23
|
get left(): N | null | undefined;
|
|
23
24
|
set left(v: N | null | undefined);
|
|
@@ -41,7 +42,7 @@ export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = Bi
|
|
|
41
42
|
* 8. Full Trees: Every node has either 0 or 2 children.
|
|
42
43
|
* 9. Complete Trees: All levels are fully filled except possibly the last, filled from left to right.
|
|
43
44
|
*/
|
|
44
|
-
export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>, TREE extends BinaryTree<V, N, TREE> = BinaryTree<V, N, BinaryTreeNested<V, N>>> implements IBinaryTree<V, N, TREE> {
|
|
45
|
+
export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, N, TREE> = BinaryTree<K, V, N, BinaryTreeNested<K, V, N>>> extends IterablePairBase<K, V | undefined> implements IBinaryTree<K, V, N, TREE> {
|
|
45
46
|
iterationType: IterationType;
|
|
46
47
|
/**
|
|
47
48
|
* The constructor function initializes a binary tree object with optional elements and options.
|
|
@@ -52,18 +53,20 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
52
53
|
* `Partial<BinaryTreeOptions>`, which means that not all properties of `BinaryTreeOptions` are
|
|
53
54
|
* required.
|
|
54
55
|
*/
|
|
55
|
-
constructor(elements?: Iterable<BTNodeExemplar<V, N>>, options?: Partial<BinaryTreeOptions
|
|
56
|
+
constructor(elements?: Iterable<BTNodeExemplar<K, V, N>>, options?: Partial<BinaryTreeOptions<K>>);
|
|
57
|
+
protected _extractor: (key: K) => number;
|
|
58
|
+
get extractor(): (key: K) => number;
|
|
56
59
|
protected _root?: N | null;
|
|
57
60
|
get root(): N | null | undefined;
|
|
58
61
|
protected _size: number;
|
|
59
62
|
get size(): number;
|
|
60
63
|
/**
|
|
61
64
|
* Creates a new instance of BinaryTreeNode with the given key and value.
|
|
62
|
-
* @param {
|
|
65
|
+
* @param {K} key - The key for the new node.
|
|
63
66
|
* @param {V} value - The value for the new node.
|
|
64
67
|
* @returns {N} - The newly created BinaryTreeNode.
|
|
65
68
|
*/
|
|
66
|
-
createNode(key:
|
|
69
|
+
createNode(key: K, value?: V): N;
|
|
67
70
|
/**
|
|
68
71
|
* The function creates a binary tree with the given options.
|
|
69
72
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
@@ -71,28 +74,28 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
71
74
|
* you can provide only a subset of the properties defined in the `BinaryTreeOptions` interface.
|
|
72
75
|
* @returns a new instance of a binary tree.
|
|
73
76
|
*/
|
|
74
|
-
createTree(options?: Partial<BinaryTreeOptions
|
|
77
|
+
createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
|
|
75
78
|
/**
|
|
76
79
|
* The function "isNode" checks if an exemplar is an instance of the BinaryTreeNode class.
|
|
77
|
-
* @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<V,
|
|
80
|
+
* @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<K, V,N>`.
|
|
78
81
|
* @returns a boolean value indicating whether the exemplar is an instance of the class N.
|
|
79
82
|
*/
|
|
80
|
-
isNode(exemplar: BTNodeExemplar<V, N>): exemplar is N;
|
|
83
|
+
isNode(exemplar: BTNodeExemplar<K, V, N>): exemplar is N;
|
|
81
84
|
/**
|
|
82
85
|
* The function `exemplarToNode` converts an exemplar of a binary tree node into an actual node
|
|
83
86
|
* object.
|
|
84
|
-
* @param exemplar - BTNodeExemplar<V,
|
|
87
|
+
* @param exemplar - BTNodeExemplar<K, V,N> - A generic type representing the exemplar parameter of the
|
|
85
88
|
* function. It can be any type.
|
|
86
89
|
* @returns a value of type `N` (which represents a node), or `null`, or `undefined`.
|
|
87
90
|
*/
|
|
88
|
-
exemplarToNode(exemplar: BTNodeExemplar<V, N>): N | null | undefined;
|
|
91
|
+
exemplarToNode(exemplar: BTNodeExemplar<K, V, N>): N | null | undefined;
|
|
89
92
|
/**
|
|
90
93
|
* The function checks if a given value is an entry in a binary tree node.
|
|
91
|
-
* @param kne - BTNodeExemplar<V,
|
|
94
|
+
* @param kne - BTNodeExemplar<K, V,N> - A generic type representing a node in a binary tree. It has
|
|
92
95
|
* two type parameters V and N, representing the value and node type respectively.
|
|
93
96
|
* @returns a boolean value.
|
|
94
97
|
*/
|
|
95
|
-
isEntry(kne: BTNodeExemplar<V, N>): kne is BTNodeEntry<V>;
|
|
98
|
+
isEntry(kne: BTNodeExemplar<K, V, N>): kne is BTNodeEntry<K, V>;
|
|
96
99
|
/**
|
|
97
100
|
* Time Complexity O(log n) - O(n)
|
|
98
101
|
* Space Complexity O(1)
|
|
@@ -105,7 +108,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
105
108
|
* @param keyOrNodeOrEntry - The parameter `keyOrNodeOrEntry` can be one of the following:
|
|
106
109
|
* @returns The function `add` returns the inserted node (`N`), `null`, or `undefined`.
|
|
107
110
|
*/
|
|
108
|
-
add(keyOrNodeOrEntry: BTNodeExemplar<V, N>): N | null | undefined;
|
|
111
|
+
add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>): N | null | undefined;
|
|
109
112
|
/**
|
|
110
113
|
* Time Complexity: O(k log n) - O(k * n)
|
|
111
114
|
* Space Complexity: O(1)
|
|
@@ -118,11 +121,11 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
118
121
|
* The function `addMany` takes in an iterable of `BTNodeExemplar` objects, adds each object to the
|
|
119
122
|
* current instance, and returns an array of the inserted nodes.
|
|
120
123
|
* @param nodes - The `nodes` parameter is an iterable (such as an array or a set) of
|
|
121
|
-
* `BTNodeExemplar<V,
|
|
124
|
+
* `BTNodeExemplar<K, V,N>` objects.
|
|
122
125
|
* @returns The function `addMany` returns an array of values, where each value is either of type
|
|
123
126
|
* `N`, `null`, or `undefined`.
|
|
124
127
|
*/
|
|
125
|
-
addMany(nodes: Iterable<BTNodeExemplar<V, N>>): (N | null | undefined)[];
|
|
128
|
+
addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>): (N | null | undefined)[];
|
|
126
129
|
/**
|
|
127
130
|
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
128
131
|
* Space Complexity: O(1)
|
|
@@ -135,12 +138,12 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
135
138
|
* @param nodesOrKeysOrEntries - The parameter `nodesOrKeysOrEntries` is an iterable object that can
|
|
136
139
|
* contain either `BTNodeExemplar` objects, keys, or entries.
|
|
137
140
|
*/
|
|
138
|
-
refill(nodesOrKeysOrEntries: Iterable<BTNodeExemplar<V, N>>): void;
|
|
141
|
+
refill(nodesOrKeysOrEntries: Iterable<BTNodeExemplar<K, V, N>>): void;
|
|
139
142
|
/**
|
|
140
143
|
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
141
144
|
* Space Complexity: O(1)
|
|
142
145
|
*/
|
|
143
|
-
delete<C extends BTNCallback<N,
|
|
146
|
+
delete<C extends BTNCallback<N, K>>(identifier: K, callback?: C): BiTreeDeleteResult<N>[];
|
|
144
147
|
delete<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C): BiTreeDeleteResult<N>[];
|
|
145
148
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C): BiTreeDeleteResult<N>[];
|
|
146
149
|
/**
|
|
@@ -152,15 +155,15 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
152
155
|
* Space Complexity: O(1)
|
|
153
156
|
*
|
|
154
157
|
* The function calculates the depth of a given node in a binary tree.
|
|
155
|
-
* @param {
|
|
156
|
-
* the binary tree whose depth we want to find. It can be of type `
|
|
158
|
+
* @param {K | N | null | undefined} distNode - The `distNode` parameter represents the node in
|
|
159
|
+
* the binary tree whose depth we want to find. It can be of type `K`, `N`, `null`, or
|
|
157
160
|
* `undefined`.
|
|
158
|
-
* @param {
|
|
159
|
-
* from which we want to calculate the depth. It can be either a `
|
|
161
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
|
|
162
|
+
* from which we want to calculate the depth. It can be either a `K` (binary tree node key) or
|
|
160
163
|
* `N` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
|
|
161
164
|
* @returns the depth of the `distNode` relative to the `beginRoot`.
|
|
162
165
|
*/
|
|
163
|
-
getDepth(distNode: BTNodeKeyOrNode<N>, beginRoot?: BTNodeKeyOrNode<N>): number;
|
|
166
|
+
getDepth(distNode: BTNodeKeyOrNode<K, N>, beginRoot?: BTNodeKeyOrNode<K, N>): number;
|
|
164
167
|
/**
|
|
165
168
|
* Time Complexity: O(n)
|
|
166
169
|
* Space Complexity: O(1)
|
|
@@ -171,15 +174,15 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
171
174
|
*
|
|
172
175
|
* The function `getHeight` calculates the maximum height of a binary tree using either recursive or
|
|
173
176
|
* iterative traversal.
|
|
174
|
-
* @param {
|
|
177
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
175
178
|
* starting node of the binary tree from which we want to calculate the height. It can be of type
|
|
176
|
-
* `
|
|
179
|
+
* `K`, `N`, `null`, or `undefined`. If not provided, it defaults to `this.root`.
|
|
177
180
|
* @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
|
|
178
181
|
* height of the tree using a recursive approach or an iterative approach. It can have two possible
|
|
179
182
|
* values:
|
|
180
183
|
* @returns the height of the binary tree.
|
|
181
184
|
*/
|
|
182
|
-
getHeight(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): number;
|
|
185
|
+
getHeight(beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): number;
|
|
183
186
|
/**
|
|
184
187
|
* Time Complexity: O(n)
|
|
185
188
|
* Space Complexity: O(log n)
|
|
@@ -191,14 +194,14 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
191
194
|
*
|
|
192
195
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
193
196
|
* recursive or iterative approach.
|
|
194
|
-
* @param {
|
|
197
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
195
198
|
* starting node of the binary tree from which we want to calculate the minimum height. It can be of
|
|
196
|
-
* type `
|
|
199
|
+
* type `K`, `N`, `null`, or `undefined`. If no value is provided, it defaults to `this.root`.
|
|
197
200
|
* @param iterationType - The `iterationType` parameter is used to determine the method of iteration
|
|
198
201
|
* to calculate the minimum height of a binary tree. It can have two possible values:
|
|
199
202
|
* @returns The function `getMinHeight` returns the minimum height of a binary tree.
|
|
200
203
|
*/
|
|
201
|
-
getMinHeight(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): number;
|
|
204
|
+
getMinHeight(beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): number;
|
|
202
205
|
/**
|
|
203
206
|
* Time Complexity: O(n)
|
|
204
207
|
* Space Complexity: O(log n)
|
|
@@ -210,33 +213,33 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
210
213
|
*
|
|
211
214
|
* The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
|
|
212
215
|
* height of the tree.
|
|
213
|
-
* @param {
|
|
214
|
-
* for calculating the height and minimum height of a binary tree. It can be either a `
|
|
216
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
|
|
217
|
+
* for calculating the height and minimum height of a binary tree. It can be either a `K` (a key
|
|
215
218
|
* value of a binary tree node), `N` (a node of a binary tree), `null`, or `undefined`. If
|
|
216
219
|
* @returns a boolean value.
|
|
217
220
|
*/
|
|
218
|
-
isPerfectlyBalanced(beginRoot?: BTNodeKeyOrNode<N>): boolean;
|
|
221
|
+
isPerfectlyBalanced(beginRoot?: BTNodeKeyOrNode<K, N>): boolean;
|
|
219
222
|
/**
|
|
220
223
|
* Time Complexity: O(n)
|
|
221
224
|
* Space Complexity: O(log n)
|
|
222
225
|
*/
|
|
223
|
-
getNodes<C extends BTNCallback<N,
|
|
224
|
-
getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N[];
|
|
225
|
-
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N[];
|
|
226
|
+
getNodes<C extends BTNCallback<N, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N[];
|
|
227
|
+
getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N[];
|
|
228
|
+
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N[];
|
|
226
229
|
/**
|
|
227
230
|
* Time Complexity: O(n)
|
|
228
231
|
* Space Complexity: O(log n).
|
|
229
232
|
*/
|
|
230
|
-
has<C extends BTNCallback<N,
|
|
231
|
-
has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): boolean;
|
|
232
|
-
has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): boolean;
|
|
233
|
+
has<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): boolean;
|
|
234
|
+
has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): boolean;
|
|
235
|
+
has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): boolean;
|
|
233
236
|
/**
|
|
234
237
|
* Time Complexity: O(n)
|
|
235
238
|
* Space Complexity: O(log n).
|
|
236
239
|
*/
|
|
237
|
-
getNode<C extends BTNCallback<N,
|
|
238
|
-
getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
|
|
239
|
-
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
|
|
240
|
+
getNode<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
241
|
+
getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
242
|
+
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
240
243
|
/**
|
|
241
244
|
* Time Complexity: O(n)
|
|
242
245
|
* Space Complexity: O(log n)
|
|
@@ -247,7 +250,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
247
250
|
*
|
|
248
251
|
* The function `getNodeByKey` searches for a node in a binary tree by its key, using either
|
|
249
252
|
* recursive or iterative iteration.
|
|
250
|
-
* @param {
|
|
253
|
+
* @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
|
|
251
254
|
* It is used to find the node with the matching key value.
|
|
252
255
|
* @param iterationType - The `iterationType` parameter is used to determine whether the search for
|
|
253
256
|
* the node with the given key should be performed iteratively or recursively. It has two possible
|
|
@@ -255,7 +258,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
255
258
|
* @returns The function `getNodeByKey` returns a node (`N`) if a node with the specified key is
|
|
256
259
|
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
257
260
|
*/
|
|
258
|
-
getNodeByKey(key:
|
|
261
|
+
getNodeByKey(key: K, iterationType?: IterationType): N | undefined;
|
|
259
262
|
/**
|
|
260
263
|
* Time Complexity: O(n)
|
|
261
264
|
* Space Complexity: O(log n)
|
|
@@ -263,7 +266,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
263
266
|
/**
|
|
264
267
|
* The function `ensureNode` returns the node corresponding to the given key if it is a valid node
|
|
265
268
|
* key, otherwise it returns the key itself.
|
|
266
|
-
* @param {
|
|
269
|
+
* @param {K | N | null | undefined} key - The `key` parameter can be of type `K`, `N`,
|
|
267
270
|
* `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
|
|
268
271
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
269
272
|
* type of iteration to be used when searching for a node by key. It has a default value of
|
|
@@ -271,10 +274,10 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
271
274
|
* @returns either the node corresponding to the given key if it is a valid node key, or the key
|
|
272
275
|
* itself if it is not a valid node key.
|
|
273
276
|
*/
|
|
274
|
-
ensureNode(key: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
|
|
275
|
-
get<C extends BTNCallback<N,
|
|
276
|
-
get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): V | undefined;
|
|
277
|
-
get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): V | undefined;
|
|
277
|
+
ensureNode(key: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
278
|
+
get<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
|
|
279
|
+
get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
|
|
280
|
+
get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
|
|
278
281
|
/**
|
|
279
282
|
* Time Complexity: O(n)
|
|
280
283
|
* Space Complexity: O(log n)
|
|
@@ -294,15 +297,15 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
294
297
|
*
|
|
295
298
|
* The function `getPathToRoot` returns an array of nodes from a given node to the root of a tree
|
|
296
299
|
* structure, with the option to reverse the order of the nodes.
|
|
297
|
-
* @param {
|
|
298
|
-
* starting node from which you want to find the path to the root. It can be of type `
|
|
300
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
301
|
+
* starting node from which you want to find the path to the root. It can be of type `K`, `N`,
|
|
299
302
|
* `null`, or `undefined`.
|
|
300
303
|
* @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
|
|
301
304
|
* resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
|
|
302
305
|
* reversed before returning it. If `isReverse` is set to `false`, the path will be returned as is
|
|
303
306
|
* @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
|
|
304
307
|
*/
|
|
305
|
-
getPathToRoot(beginRoot: BTNodeKeyOrNode<N>, isReverse?: boolean): N[];
|
|
308
|
+
getPathToRoot(beginRoot: BTNodeKeyOrNode<K, N>, isReverse?: boolean): N[];
|
|
306
309
|
/**
|
|
307
310
|
* Time Complexity: O(log n)
|
|
308
311
|
* Space Complexity: O(log n)
|
|
@@ -313,15 +316,15 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
313
316
|
*
|
|
314
317
|
* The function `getLeftMost` returns the leftmost node in a binary tree, either recursively or
|
|
315
318
|
* iteratively.
|
|
316
|
-
* @param {
|
|
317
|
-
* for finding the leftmost node in a binary tree. It can be either a `
|
|
319
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
|
|
320
|
+
* for finding the leftmost node in a binary tree. It can be either a `K` (a key value), `N` (a
|
|
318
321
|
* node), `null`, or `undefined`. If not provided, it defaults to `this.root`,
|
|
319
322
|
* @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
|
|
320
323
|
* be performed when finding the leftmost node in a binary tree. It can have two possible values:
|
|
321
324
|
* @returns The function `getLeftMost` returns the leftmost node (`N`) in the binary tree. If there
|
|
322
325
|
* is no leftmost node, it returns `null` or `undefined` depending on the input.
|
|
323
326
|
*/
|
|
324
|
-
getLeftMost(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
|
|
327
|
+
getLeftMost(beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
325
328
|
/**
|
|
326
329
|
* Time Complexity: O(log n)
|
|
327
330
|
* Space Complexity: O(1)
|
|
@@ -332,8 +335,8 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
332
335
|
*
|
|
333
336
|
* The function `getRightMost` returns the rightmost node in a binary tree, either recursively or
|
|
334
337
|
* iteratively.
|
|
335
|
-
* @param {
|
|
336
|
-
* starting node from which we want to find the rightmost node. It can be of type `
|
|
338
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
339
|
+
* starting node from which we want to find the rightmost node. It can be of type `K`, `N`,
|
|
337
340
|
* `null`, or `undefined`. If not provided, it defaults to `this.root`, which is a property of the
|
|
338
341
|
* current object.
|
|
339
342
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
@@ -341,7 +344,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
341
344
|
* @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If there
|
|
342
345
|
* is no rightmost node, it returns `null` or `undefined`, depending on the input.
|
|
343
346
|
*/
|
|
344
|
-
getRightMost(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
|
|
347
|
+
getRightMost(beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
345
348
|
/**
|
|
346
349
|
* Time Complexity: O(log n)
|
|
347
350
|
* Space Complexity: O(1)
|
|
@@ -351,14 +354,14 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
351
354
|
* Space Complexity: O(1)
|
|
352
355
|
*
|
|
353
356
|
* The function `isSubtreeBST` checks if a given binary tree is a valid binary search tree.
|
|
354
|
-
* @param {
|
|
357
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the root
|
|
355
358
|
* node of the binary search tree (BST) that you want to check if it is a subtree of another BST.
|
|
356
359
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
357
360
|
* type of iteration to use when checking if a subtree is a binary search tree (BST). It can have two
|
|
358
361
|
* possible values:
|
|
359
362
|
* @returns a boolean value.
|
|
360
363
|
*/
|
|
361
|
-
isSubtreeBST(beginRoot: BTNodeKeyOrNode<N>, iterationType?: IterationType): boolean;
|
|
364
|
+
isSubtreeBST(beginRoot: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): boolean;
|
|
362
365
|
/**
|
|
363
366
|
* Time Complexity: O(n)
|
|
364
367
|
* Space Complexity: O(1)
|
|
@@ -379,9 +382,9 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
379
382
|
* Time Complexity: O(n)
|
|
380
383
|
* Space Complexity: O(1)
|
|
381
384
|
*/
|
|
382
|
-
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
383
|
-
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
384
|
-
subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
385
|
+
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
386
|
+
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
387
|
+
subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
385
388
|
/**
|
|
386
389
|
* Time complexity: O(n)
|
|
387
390
|
* Space complexity: O(log n)
|
|
@@ -406,29 +409,29 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
406
409
|
*/
|
|
407
410
|
isNodeOrNull(node: any): node is N | null;
|
|
408
411
|
/**
|
|
409
|
-
* The function "
|
|
412
|
+
* The function "isNotNodeInstance" checks if a potential key is a number.
|
|
410
413
|
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
411
414
|
* data type.
|
|
412
415
|
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
413
416
|
*/
|
|
414
|
-
|
|
415
|
-
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
416
|
-
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
417
|
-
dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
417
|
+
isNotNodeInstance(potentialKey: BTNodeKeyOrNode<K, N>): potentialKey is K;
|
|
418
|
+
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
419
|
+
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
420
|
+
dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
418
421
|
/**
|
|
419
422
|
* Time complexity: O(n)
|
|
420
423
|
* Space complexity: O(n)
|
|
421
424
|
*/
|
|
422
|
-
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
423
|
-
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
424
|
-
bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
425
|
+
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
426
|
+
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
427
|
+
bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
425
428
|
/**
|
|
426
429
|
* Time complexity: O(n)
|
|
427
430
|
* Space complexity: O(n)
|
|
428
431
|
*/
|
|
429
|
-
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
430
|
-
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
|
|
431
|
-
listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
432
|
+
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
433
|
+
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
|
|
434
|
+
listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
432
435
|
/**
|
|
433
436
|
* Time complexity: O(n)
|
|
434
437
|
* Space complexity: O(n)
|
|
@@ -436,11 +439,11 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
436
439
|
getPredecessor(node: N): N;
|
|
437
440
|
/**
|
|
438
441
|
* The function `getSuccessor` returns the next node in a binary tree given a current node.
|
|
439
|
-
* @param {
|
|
442
|
+
* @param {K | N | null} [x] - The parameter `x` can be of type `K`, `N`, or `null`.
|
|
440
443
|
* @returns the successor of the given node or key. The successor is the node that comes immediately
|
|
441
444
|
* after the given node in the inorder traversal of the binary tree.
|
|
442
445
|
*/
|
|
443
|
-
getSuccessor(x?:
|
|
446
|
+
getSuccessor(x?: K | N | null): N | null | undefined;
|
|
444
447
|
/**
|
|
445
448
|
* Time complexity: O(n)
|
|
446
449
|
* Space complexity: O(1)
|
|
@@ -452,39 +455,14 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
452
455
|
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
|
|
453
456
|
* determines the order in which the nodes of a binary tree are traversed. It can have one of the
|
|
454
457
|
* following values:
|
|
455
|
-
* @param {
|
|
458
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
|
|
456
459
|
* for the traversal. It can be specified as a key, a node object, or `null`/`undefined` to indicate
|
|
457
460
|
* the root of the tree. If no value is provided, the default value is the root of the tree.
|
|
458
461
|
* @returns The function `morris` returns an array of values that are the result of invoking the
|
|
459
462
|
* `callback` function on each node in the binary tree. The type of the array elements is determined
|
|
460
463
|
* by the return type of the `callback` function.
|
|
461
464
|
*/
|
|
462
|
-
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<N>): ReturnType<C>[];
|
|
463
|
-
/**
|
|
464
|
-
* Time complexity: O(n)
|
|
465
|
-
* Space complexity: O(n)
|
|
466
|
-
*/
|
|
467
|
-
/**
|
|
468
|
-
* Time complexity: O(n)
|
|
469
|
-
* Space complexity: O(n)
|
|
470
|
-
*
|
|
471
|
-
* The function "keys" returns an array of keys from a given object.
|
|
472
|
-
* @returns an array of BTNKey objects.
|
|
473
|
-
*/
|
|
474
|
-
keys(): BTNKey[];
|
|
475
|
-
/**
|
|
476
|
-
* Time complexity: O(n)
|
|
477
|
-
* Space complexity: O(n)
|
|
478
|
-
*/
|
|
479
|
-
/**
|
|
480
|
-
* Time complexity: O(n)
|
|
481
|
-
* Space complexity: O(n)
|
|
482
|
-
*
|
|
483
|
-
* The function "values" returns an array of values from a map-like object.
|
|
484
|
-
* @returns The `values()` method is returning an array of values (`V`) from the entries in the
|
|
485
|
-
* object.
|
|
486
|
-
*/
|
|
487
|
-
values(): (V | undefined)[];
|
|
465
|
+
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<K, N>): ReturnType<C>[];
|
|
488
466
|
/**
|
|
489
467
|
* Time complexity: O(n)
|
|
490
468
|
* Space complexity: O(n)
|
|
@@ -499,72 +477,63 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
499
477
|
*/
|
|
500
478
|
clone(): TREE;
|
|
501
479
|
/**
|
|
502
|
-
* Time
|
|
503
|
-
* Space
|
|
480
|
+
* Time Complexity: O(n)
|
|
481
|
+
* Space Complexity: O(n)
|
|
504
482
|
*/
|
|
505
483
|
/**
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
* tree
|
|
510
|
-
|
|
511
|
-
|
|
484
|
+
* Time Complexity: O(n)
|
|
485
|
+
* Space Complexity: O(n)
|
|
486
|
+
*
|
|
487
|
+
* The `filter` function creates a new tree by iterating over the elements of the current tree and
|
|
488
|
+
* adding only the elements that satisfy the given predicate function.
|
|
489
|
+
* @param predicate - The `predicate` parameter is a function that takes three arguments: `value`,
|
|
490
|
+
* `key`, and `index`. It should return a boolean value indicating whether the pair should be
|
|
491
|
+
* included in the filtered tree or not.
|
|
492
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
493
|
+
* to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
|
|
494
|
+
* it will be passed as the first argument to the `predicate` function. If `thisArg` is
|
|
495
|
+
* @returns The `filter` method is returning a new tree object that contains the key-value pairs that
|
|
496
|
+
* pass the given predicate function.
|
|
497
|
+
*/
|
|
498
|
+
filter(predicate: PairCallback<K, V | undefined, boolean>, thisArg?: any): TREE;
|
|
512
499
|
/**
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
* @param predicate - The `predicate` parameter is a function that takes two arguments: `entry` and
|
|
516
|
-
* `tree`.
|
|
517
|
-
* @returns The `filter` method is returning a new tree object that contains only the entries that
|
|
518
|
-
* satisfy the given predicate function.
|
|
500
|
+
* Time Complexity: O(n)
|
|
501
|
+
* Space Complexity: O(n)
|
|
519
502
|
*/
|
|
520
|
-
filter(predicate: (entry: [BTNKey, V | undefined], tree: this) => boolean): TREE;
|
|
521
503
|
/**
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
504
|
+
* Time Complexity: O(n)
|
|
505
|
+
* Space Complexity: O(n)
|
|
506
|
+
*
|
|
507
|
+
* The `map` function creates a new tree by applying a callback function to each key-value pair in
|
|
508
|
+
* the original tree.
|
|
509
|
+
* @param callback - The callback parameter is a function that will be called for each key-value pair
|
|
510
|
+
* in the tree. It takes four arguments: the value of the current pair, the key of the current pair,
|
|
511
|
+
* the index of the current pair, and a reference to the tree itself. The callback function should
|
|
512
|
+
* return a new
|
|
513
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
514
|
+
* specify the value of `this` within the callback function. If you pass a value for `thisArg`, it
|
|
515
|
+
* will be used as the `this` value when the callback function is called. If you don't pass a value
|
|
525
516
|
* @returns The `map` method is returning a new tree object.
|
|
526
517
|
*/
|
|
527
|
-
map(callback:
|
|
528
|
-
/**
|
|
529
|
-
* The `reduce` function iterates over the entries of a tree and applies a callback function to each
|
|
530
|
-
* entry, accumulating a single value.
|
|
531
|
-
* @param callback - The callback parameter is a function that takes three arguments: accumulator,
|
|
532
|
-
* entry, and tree. It is called for each entry in the tree and is used to accumulate a single value
|
|
533
|
-
* based on the logic defined in the callback function.
|
|
534
|
-
* @param {T} initialValue - The initialValue parameter is the initial value of the accumulator. It
|
|
535
|
-
* is the value that will be passed as the first argument to the callback function when reducing the
|
|
536
|
-
* elements of the tree.
|
|
537
|
-
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
538
|
-
* all the entries in the tree and applying the callback function to each entry.
|
|
539
|
-
*/
|
|
540
|
-
reduce<T>(callback: (accumulator: T, entry: [BTNKey, V | undefined], tree: this) => T, initialValue: T): T;
|
|
541
|
-
/**
|
|
542
|
-
* The above function is an iterator for a binary tree that can be used to traverse the tree in
|
|
543
|
-
* either an iterative or recursive manner.
|
|
544
|
-
* @param node - The `node` parameter represents the current node in the binary tree from which the
|
|
545
|
-
* iteration starts. It is an optional parameter with a default value of `this.root`, which means
|
|
546
|
-
* that if no node is provided, the iteration will start from the root of the binary tree.
|
|
547
|
-
* @returns The `*[Symbol.iterator]` method returns a generator object that yields the keys of the
|
|
548
|
-
* binary tree nodes in a specific order.
|
|
549
|
-
*/
|
|
550
|
-
[Symbol.iterator](node?: N | null | undefined): Generator<[BTNKey, V | undefined], void, undefined>;
|
|
518
|
+
map(callback: PairCallback<K, V | undefined, V>, thisArg?: any): TREE;
|
|
551
519
|
/**
|
|
552
520
|
* The `print` function is used to display a binary tree structure in a visually appealing way.
|
|
553
|
-
* @param {
|
|
521
|
+
* @param {K | N | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `K | N | null |
|
|
554
522
|
* undefined`. It represents the root node of a binary tree. The root node can have one of the
|
|
555
523
|
* following types:
|
|
556
524
|
* @param {BinaryTreePrintOptions} [options={ isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false}] - Options object that controls printing behavior. You can specify whether to display undefined, null, or sentinel nodes.
|
|
557
525
|
*/
|
|
558
|
-
print(beginRoot?: BTNodeKeyOrNode<N>, options?: BinaryTreePrintOptions): void;
|
|
526
|
+
print(beginRoot?: BTNodeKeyOrNode<K, N>, options?: BinaryTreePrintOptions): void;
|
|
527
|
+
protected _getIterator(node?: N | null | undefined): IterableIterator<[K, V | undefined]>;
|
|
559
528
|
protected _displayAux(node: N | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
560
|
-
protected _defaultOneParamCallback: (node: N) =>
|
|
529
|
+
protected _defaultOneParamCallback: (node: N) => K;
|
|
561
530
|
/**
|
|
562
531
|
* Swap the data of two nodes in the binary tree.
|
|
563
532
|
* @param {N} srcNode - The source node to swap.
|
|
564
533
|
* @param {N} destNode - The destination node to swap.
|
|
565
534
|
* @returns {N} - The destination node after the swap.
|
|
566
535
|
*/
|
|
567
|
-
protected _swapProperties(srcNode: BTNodeKeyOrNode<N>, destNode: BTNodeKeyOrNode<N>): N | undefined;
|
|
536
|
+
protected _swapProperties(srcNode: BTNodeKeyOrNode<K, N>, destNode: BTNodeKeyOrNode<K, N>): N | undefined;
|
|
568
537
|
/**
|
|
569
538
|
* The function replaces an old node with a new node in a binary tree.
|
|
570
539
|
* @param {N} oldNode - The oldNode parameter represents the node that needs to be replaced in the
|
|
@@ -585,7 +554,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
585
554
|
* the binary tree. If neither the left nor right child is available, the function returns undefined.
|
|
586
555
|
* If the parent node is null, the function also returns undefined.
|
|
587
556
|
*/
|
|
588
|
-
protected _addTo(newNode: N | null | undefined, parent: BTNodeKeyOrNode<N>): N | null | undefined;
|
|
557
|
+
protected _addTo(newNode: N | null | undefined, parent: BTNodeKeyOrNode<K, N>): N | null | undefined;
|
|
589
558
|
/**
|
|
590
559
|
* The function sets the root property of an object to a given value, and if the value is not null,
|
|
591
560
|
* it also sets the parent property of the value to undefined.
|