directed-graph-typed 1.48.0 → 1.49.0

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