linked-list-typed 1.52.6 → 1.52.9

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 (77) hide show
  1. package/dist/constants/index.d.ts +4 -0
  2. package/dist/constants/index.js +8 -0
  3. package/dist/data-structures/base/iterable-element-base.d.ts +8 -1
  4. package/dist/data-structures/base/iterable-element-base.js +10 -1
  5. package/dist/data-structures/base/iterable-entry-base.d.ts +8 -1
  6. package/dist/data-structures/base/iterable-entry-base.js +10 -10
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +43 -44
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +23 -24
  10. package/dist/data-structures/binary-tree/avl-tree.js +71 -64
  11. package/dist/data-structures/binary-tree/binary-indexed-tree.js +2 -2
  12. package/dist/data-structures/binary-tree/binary-tree.d.ts +591 -402
  13. package/dist/data-structures/binary-tree/binary-tree.js +690 -604
  14. package/dist/data-structures/binary-tree/bst.d.ts +72 -65
  15. package/dist/data-structures/binary-tree/bst.js +122 -125
  16. package/dist/data-structures/binary-tree/rb-tree.d.ts +21 -24
  17. package/dist/data-structures/binary-tree/rb-tree.js +42 -39
  18. package/dist/data-structures/binary-tree/segment-tree.d.ts +2 -2
  19. package/dist/data-structures/binary-tree/segment-tree.js +2 -2
  20. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +27 -31
  21. package/dist/data-structures/binary-tree/tree-multi-map.js +45 -43
  22. package/dist/data-structures/graph/abstract-graph.d.ts +2 -2
  23. package/dist/data-structures/graph/abstract-graph.js +7 -4
  24. package/dist/data-structures/graph/directed-graph.d.ts +2 -2
  25. package/dist/data-structures/graph/directed-graph.js +4 -2
  26. package/dist/data-structures/graph/undirected-graph.d.ts +2 -2
  27. package/dist/data-structures/hash/hash-map.d.ts +2 -2
  28. package/dist/data-structures/hash/hash-map.js +1 -1
  29. package/dist/data-structures/heap/heap.js +3 -3
  30. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  31. package/dist/data-structures/linked-list/doubly-linked-list.js +7 -7
  32. package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  33. package/dist/data-structures/linked-list/singly-linked-list.js +6 -6
  34. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  35. package/dist/data-structures/matrix/matrix.d.ts +2 -2
  36. package/dist/data-structures/matrix/navigator.d.ts +2 -2
  37. package/dist/data-structures/matrix/navigator.js +4 -2
  38. package/dist/data-structures/queue/deque.d.ts +3 -3
  39. package/dist/data-structures/queue/deque.js +29 -29
  40. package/dist/data-structures/queue/queue.d.ts +1 -1
  41. package/dist/data-structures/stack/stack.d.ts +2 -2
  42. package/dist/data-structures/trie/trie.d.ts +2 -2
  43. package/dist/data-structures/trie/trie.js +1 -1
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.js +1 -0
  46. package/dist/interfaces/binary-tree.d.ts +2 -2
  47. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
  48. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -6
  49. package/package.json +2 -2
  50. package/src/constants/index.ts +4 -0
  51. package/src/data-structures/base/iterable-element-base.ts +11 -1
  52. package/src/data-structures/base/iterable-entry-base.ts +11 -19
  53. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +46 -50
  54. package/src/data-structures/binary-tree/avl-tree.ts +68 -71
  55. package/src/data-structures/binary-tree/binary-indexed-tree.ts +2 -2
  56. package/src/data-structures/binary-tree/binary-tree.ts +716 -748
  57. package/src/data-structures/binary-tree/bst.ts +137 -146
  58. package/src/data-structures/binary-tree/rb-tree.ts +46 -46
  59. package/src/data-structures/binary-tree/segment-tree.ts +2 -2
  60. package/src/data-structures/binary-tree/tree-multi-map.ts +49 -49
  61. package/src/data-structures/graph/abstract-graph.ts +6 -6
  62. package/src/data-structures/graph/directed-graph.ts +4 -4
  63. package/src/data-structures/graph/undirected-graph.ts +2 -2
  64. package/src/data-structures/hash/hash-map.ts +3 -3
  65. package/src/data-structures/heap/heap.ts +3 -3
  66. package/src/data-structures/linked-list/doubly-linked-list.ts +9 -9
  67. package/src/data-structures/linked-list/singly-linked-list.ts +8 -8
  68. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  69. package/src/data-structures/matrix/matrix.ts +2 -2
  70. package/src/data-structures/matrix/navigator.ts +4 -4
  71. package/src/data-structures/queue/deque.ts +31 -31
  72. package/src/data-structures/queue/queue.ts +1 -1
  73. package/src/data-structures/stack/stack.ts +2 -2
  74. package/src/data-structures/trie/trie.ts +3 -3
  75. package/src/index.ts +2 -1
  76. package/src/interfaces/binary-tree.ts +3 -3
  77. package/src/types/data-structures/binary-tree/binary-tree.ts +3 -5
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNCallback, BTNEntry, BTNKeyOrNodeOrEntry, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeDisplayLayout, OptBTNOrNull } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNCallback, BTNEntry, BTNKeyOrNodeOrEntry, BTNPredicate, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeDisplayLayout, OptBTNOrNull } from '../../types';
9
9
  import { IBinaryTree } from '../../interfaces';
10
10
  import { IterableEntryBase } from '../base';
11
11
  /**
@@ -17,45 +17,13 @@ export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNod
17
17
  key: K;
18
18
  value?: V;
19
19
  parent?: NODE;
20
- /**
21
- * The constructor function initializes an object with a key and an optional value.
22
- * @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
23
- * constructor. It is used to set the key property of the object being created.
24
- * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
25
- * value associated with the key in the constructor.
26
- */
27
20
  constructor(key: K, value?: V);
28
21
  protected _left?: OptBTNOrNull<NODE>;
29
- /**
30
- * The function returns the value of the `_left` property, which can be of type `NODE`, `null`, or
31
- * `undefined`.
32
- * @returns The left node of the current node is being returned. It can be either a NODE object,
33
- * null, or undefined.
34
- */
35
22
  get left(): OptBTNOrNull<NODE>;
36
- /**
37
- * The function sets the left child of a node and updates its parent reference.
38
- * @param {OptBTNOrNull<NODE>} v - The parameter `v` can be of type `NODE`, `null`, or
39
- * `undefined`.
40
- */
41
23
  set left(v: OptBTNOrNull<NODE>);
42
24
  protected _right?: OptBTNOrNull<NODE>;
43
- /**
44
- * The function returns the right node of a binary tree or null if it doesn't exist.
45
- * @returns The method is returning the value of the `_right` property, which can be a `NODE` object,
46
- * `null`, or `undefined`.
47
- */
48
25
  get right(): OptBTNOrNull<NODE>;
49
- /**
50
- * The function sets the right child of a node and updates its parent.
51
- * @param {OptBTNOrNull<NODE>} v - The parameter `v` can be of type `NODE`, `null`, or
52
- * `undefined`.
53
- */
54
26
  set right(v: OptBTNOrNull<NODE>);
55
- /**
56
- * Get the position of the node within its family.
57
- * @returns {FamilyPosition} - The family position of the node.
58
- */
59
27
  get familyPosition(): FamilyPosition;
60
28
  }
61
29
  /**
@@ -68,129 +36,137 @@ export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNod
68
36
  export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTree<K, V, R, NODE, BinaryTreeNested<K, V, R, NODE>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, R, NODE, TREE> {
69
37
  iterationType: IterationType;
70
38
  /**
71
- * The constructor function initializes a binary tree object with optional keysOrNodesOrEntriesOrRawElements and options.
72
- * @param [keysOrNodesOrEntriesOrRawElements] - Optional iterable of BTNKeyOrNodeOrEntry objects. These objects represent the
73
- * nodes to be added to the binary tree.
74
- * @param [options] - The `options` parameter is an optional object that can contain additional
75
- * configuration options for the binary tree. In this case, it is of type
76
- * `Partial<BinaryTreeOptions>`, which means that not all properties of `BinaryTreeOptions` are
77
- * required.
39
+ * The constructor initializes a binary tree with optional options and adds keys, nodes, entries, or
40
+ * raw data if provided.
41
+ * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter in the constructor
42
+ * is an iterable that can contain elements of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`. It is
43
+ * initialized with an empty array `[]` by default.
44
+ * @param [options] - The `options` parameter in the constructor is an object that can contain the
45
+ * following properties:
78
46
  */
79
- constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: BinaryTreeOptions<K, V, R>);
47
+ constructor(keysOrNodesOrEntriesOrRaws?: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE> | R>, options?: BinaryTreeOptions<K, V, R>);
80
48
  protected _root?: OptBTNOrNull<NODE>;
81
- /**
82
- * The function returns the root node, which can be of type NODE, null, or undefined.
83
- * @returns The method is returning the value of the `_root` property, which can be of type `NODE`,
84
- * `null`, or `undefined`.
85
- */
86
49
  get root(): OptBTNOrNull<NODE>;
87
50
  protected _size: number;
88
- /**
89
- * The function returns the size of an object.
90
- * @returns The size of the object, which is a number.
91
- */
92
51
  get size(): number;
93
52
  protected _NIL: NODE;
94
- /**
95
- * The function returns the value of the _NIL property.
96
- * @returns The method is returning the value of the `_NIL` property.
97
- */
98
53
  get NIL(): NODE;
99
54
  protected _toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
100
- /**
101
- * The function returns the value of the _toEntryFn property.
102
- * @returns The function being returned is `this._toEntryFn`.
103
- */
104
55
  get toEntryFn(): ((rawElement: R) => BTNEntry<K, V>) | undefined;
105
56
  /**
106
- * Creates a new instance of BinaryTreeNode with the given key and value.
107
- * @param {K} key - The key for the new node.
108
- * @param {V} value - The value for the new node.
109
- * @returns {NODE} - The newly created BinaryTreeNode.
57
+ * The function creates a new binary tree node with a specified key and optional value.
58
+ * @param {K} key - The `key` parameter is the key of the node being created in the binary tree.
59
+ * @param {V} [value] - The `value` parameter in the `createNode` function is optional, meaning it is
60
+ * not required to be provided when calling the function. If a `value` is provided, it should be of
61
+ * type `V`, which is the type of the value associated with the node.
62
+ * @returns A new BinaryTreeNode instance with the provided key and value is being returned, casted
63
+ * as NODE.
110
64
  */
111
65
  createNode(key: K, value?: V): NODE;
112
66
  /**
113
- * The function creates a binary tree with the given options.
114
- * @param [options] - The `options` parameter is an optional object that allows you to customize the
115
- * behavior of the `BinaryTree` class. It is of type `Partial<BinaryTreeOptions>`, which means that
116
- * you can provide only a subset of the properties defined in the `BinaryTreeOptions` interface.
117
- * @returns a new instance of a binary tree.
118
- */
119
- createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): TREE;
120
- /**
121
- * The function `keyValueOrEntryOrRawElementToNode` converts a key-value pair, entry, or raw element
122
- * into a node object.
123
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
124
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
125
- * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
126
- * `keyValueOrEntryOrRawElementToNode` function. It represents the value associated with a key in a
127
- * key-value pair. If provided, it will be used to create a node with the specified key and value.
128
- * @returns The function `keyValueOrEntryOrRawElementToNode` returns either a `NODE` object, `null`,
129
- * or `undefined`.
130
- */
131
- keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): OptBTNOrNull<NODE>;
67
+ * The function creates a binary tree with the specified options.
68
+ * @param [options] - The `options` parameter in the `createTree` function is an optional parameter
69
+ * that allows you to provide partial configuration options for creating a binary tree. It is of type
70
+ * `Partial<BinaryTreeOptions<K, V, R>>`, which means you can pass in an object containing a subset
71
+ * of properties
72
+ * @returns A new instance of a binary tree with the specified options is being returned.
73
+ */
74
+ createTree(options?: BinaryTreeOptions<K, V, R>): TREE;
75
+ /**
76
+ * The function `keyValueOrEntryOrRawElementToNode` converts various input types into a node object
77
+ * or returns null.
78
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
79
+ * `keyValueOrEntryOrRawElementToNode` function takes in a parameter `keyOrNodeOrEntryOrRaw`, which
80
+ * can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`. This parameter represents either a key, a
81
+ * node, an entry
82
+ * @param {V} [value] - The `value` parameter in the `keyValueOrEntryOrRawElementToNode` function is
83
+ * an optional parameter of type `V`. It represents the value associated with the key in the node
84
+ * being created. If a `value` is provided, it will be used when creating the node. If
85
+ * @returns The `keyValueOrEntryOrRawElementToNode` function returns an optional node
86
+ * (`OptBTNOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
87
+ * input parameter (`keyOrNodeOrEntryOrRaw`) and processes it accordingly to return a node or null
88
+ * value.
89
+ */
90
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): OptBTNOrNull<NODE>;
132
91
  /**
133
92
  * Time Complexity: O(n)
134
93
  * Space Complexity: O(log n)
135
94
  *
136
- * The `ensureNode` function checks if the input is a valid node and returns it, or converts it to a
137
- * node if it is a key or entry.
138
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
139
- * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
140
- * a raw element.
141
- * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
142
- * parameter that specifies the type of iteration to be used when searching for a node. It has a
143
- * default value of `'ITERATIVE'`.
144
- * @returns The function `ensureNode` returns either a `NODE` object, `null`, or `undefined`.
145
- */
146
- ensureNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBTNOrNull<NODE>;
147
- /**
148
- * The function checks if the input is an instance of the BinaryTreeNode class.
149
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
150
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
151
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
152
- * an instance of the `BinaryTreeNode` class.
153
- */
154
- isNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
155
- /**
156
- * The function checks if a given node is a valid node in a binary search tree.
157
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
158
- * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
159
- * @returns a boolean value.
160
- */
161
- isRealNode(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): node is NODE;
162
- /**
163
- * The function checks if a given node is a real node or null.
164
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
165
- * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
166
- * @returns a boolean value.
167
- */
168
- isRealNodeOrNull(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): node is NODE | null;
169
- /**
170
- * The function checks if a given node is equal to the NIL value.
171
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
172
- * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
173
- * @returns a boolean value.
174
- */
175
- isNIL(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): boolean;
176
- /**
177
- * The function `isLeaf` determines whether a given node is a leaf node in a binary tree structure.
178
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The `node` parameter in the `isLeaf` function
179
- * can be either a regular node (`R`) or a `BTNKeyOrNodeOrEntry<K, V, NODE>`.
180
- * @returns The `isLeaf` function is checking if the provided node is a leaf node in a binary tree.
181
- * If the node is `undefined`, it returns `false`. If the node is `null`, it returns `true`.
182
- * Otherwise, it checks if both the left and right children of the node are not real nodes, and
183
- * returns `true` if they are not, indicating that the node is a
184
- */
185
- isLeaf(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): boolean;
186
- /**
187
- * The function checks if the input is an array with two elements, indicating it is a binary tree
188
- * node entry.
189
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
190
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
191
- * @returns a boolean value.
192
- */
193
- isEntry(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is BTNEntry<K, V>;
95
+ * The function `ensureNode` in TypeScript checks if a given input is a node, entry, key, or raw
96
+ * value and returns the corresponding node or null.
97
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
98
+ * parameter in the `ensureNode` function can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`. It
99
+ * is used to determine whether the input is a key, node, entry, or raw data. The
100
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `ensureNode` function
101
+ * is used to specify the type of iteration to be performed. It has a default value of
102
+ * `this.iterationType` if not explicitly provided.
103
+ * @returns The `ensureNode` function returns either a node, `null`, or `undefined` based on the
104
+ * conditions specified in the code snippet.
105
+ */
106
+ ensureNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): OptBTNOrNull<NODE>;
107
+ /**
108
+ * The function isNode checks if the input is an instance of BinaryTreeNode.
109
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
110
+ * `keyOrNodeOrEntryOrRaw` can be either a key, a node, an entry, or raw data. The function is
111
+ * checking if the input is an instance of a `BinaryTreeNode` and returning a boolean value
112
+ * accordingly.
113
+ * @returns The function `isNode` is checking if the input `keyOrNodeOrEntryOrRaw` is an instance of
114
+ * `BinaryTreeNode`. If it is, the function returns `true`, indicating that the input is a node. If
115
+ * it is not an instance of `BinaryTreeNode`, the function returns `false`, indicating that the input
116
+ * is not a node.
117
+ */
118
+ isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE;
119
+ /**
120
+ * The function `isRealNode` checks if a given input is a valid node in a binary tree.
121
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
122
+ * parameter in the `isRealNode` function can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`.
123
+ * The function checks if the input parameter is a `NODE` type by verifying if it is not equal
124
+ * @returns The function `isRealNode` is checking if the input `keyOrNodeOrEntryOrRaw` is a valid
125
+ * node by comparing it to `this._NIL`, `null`, and `undefined`. If the input is not one of these
126
+ * values, it then calls the `isNode` method to further determine if the input is a node. The
127
+ * function will return a boolean value indicating whether the
128
+ */
129
+ isRealNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE;
130
+ /**
131
+ * The function checks if a given input is a valid node or null.
132
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
133
+ * `keyOrNodeOrEntryOrRaw` in the `isRealNodeOrNull` function can be of type `BTNKeyOrNodeOrEntry<K,
134
+ * V, NODE>` or `R`. It is a union type that can either be a key, a node, an entry, or
135
+ * @returns The function `isRealNodeOrNull` is returning a boolean value. It checks if the input
136
+ * `keyOrNodeOrEntryOrRaw` is either `null` or a real node, and returns `true` if it is a node or
137
+ * `null`, and `false` otherwise.
138
+ */
139
+ isRealNodeOrNull(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE | null;
140
+ /**
141
+ * The function isNIL checks if a given key, node, entry, or raw value is equal to the _NIL value.
142
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - BTNKeyOrNodeOrEntry<K, V,
143
+ * NODE> | R
144
+ * @returns The function is checking if the `keyOrNodeOrEntryOrRaw` parameter is equal to the `_NIL`
145
+ * property of the current object and returning a boolean value based on that comparison.
146
+ */
147
+ isNIL(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): boolean;
148
+ /**
149
+ * The function determines whether a given key, node, entry, or raw data is a leaf node in a binary
150
+ * tree.
151
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
152
+ * `keyOrNodeOrEntryOrRaw` can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`. It represents a
153
+ * key, node, entry, or raw data in a binary tree structure. The function `isLeaf` checks whether the
154
+ * provided
155
+ * @returns The function `isLeaf` returns a boolean value indicating whether the input
156
+ * `keyOrNodeOrEntryOrRaw` is a leaf node in a binary tree.
157
+ */
158
+ isLeaf(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): boolean;
159
+ /**
160
+ * The function `isEntry` checks if the input is a BTNEntry object by verifying if it is an array
161
+ * with a length of 2.
162
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
163
+ * parameter in the `isEntry` function can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or type `R`.
164
+ * The function checks if the provided `keyOrNodeOrEntryOrRaw` is of type `BTN
165
+ * @returns The `isEntry` function is checking if the `keyOrNodeOrEntryOrRaw` parameter is an array
166
+ * with a length of 2. If it is, then it returns `true`, indicating that the parameter is of type
167
+ * `BTNEntry<K, V>`. If the condition is not met, it returns `false`.
168
+ */
169
+ isEntry(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is BTNEntry<K, V>;
194
170
  /**
195
171
  * Time Complexity O(1)
196
172
  * Space Complexity O(1)
@@ -207,177 +183,297 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
207
183
  * Time Complexity O(n)
208
184
  * Space Complexity O(1)
209
185
  *
210
- * The `add` function is used to insert a new node into a binary tree, checking for duplicate keys
211
- * and finding the appropriate insertion position.
212
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
213
- * `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which represents the key,
214
- * node, entry, or raw element to be added to the tree. It can also accept a value of type
215
- * `BTNKeyOrNodeOrEntry<K, V, NODE>
216
- * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
217
- * key being added to the tree. It represents the value that will be stored in the tree for the given
218
- * key.
219
- * @returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
220
- * insertion position cannot be found or if there are duplicate keys.
221
- */
222
- add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
186
+ * The `add` function in TypeScript adds a new node to a binary tree while handling duplicate keys
187
+ * and finding the correct insertion position.
188
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `add` method you provided
189
+ * seems to be for adding a new node to a binary tree structure. The `keyOrNodeOrEntryOrRaw`
190
+ * parameter in the method can accept different types of values:
191
+ * @param {V} [value] - The `value` parameter in the `add` method represents the value associated
192
+ * with the key that you want to add to the binary tree. When adding a key-value pair to the binary
193
+ * tree, you provide the key and its corresponding value. The `add` method then creates a new node
194
+ * with this
195
+ * @returns The `add` method returns a boolean value. It returns `true` if the insertion of the new
196
+ * node was successful, and `false` if the insertion position could not be found or if a duplicate
197
+ * key was found and the node was replaced instead of inserted.
198
+ */
199
+ add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): boolean;
223
200
  /**
224
201
  * Time Complexity: O(k * n)
225
202
  * Space Complexity: O(1)
226
203
  *
227
- * The `addMany` function takes in an iterable of keys or nodes or entries or raw elements, and an
228
- * optional iterable of values, and adds each key or node or entry with its corresponding value to a
229
- * data structure, returning an array of booleans indicating whether each insertion was successful.
230
- * @param keysOrNodesOrEntriesOrRawElements - An iterable containing keys, nodes, entries, or raw
231
- * elements. These elements will be added to the data structure.
232
- * @param [values] - An optional iterable of values that correspond to the keys or nodes or entries
233
- * in the `keysOrNodesOrEntriesOrRawElements` parameter.
234
- * @returns The function `addMany` returns an array of booleans indicating whether each element was
235
- * successfully added to the data structure.
236
- */
237
- addMany(keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
204
+ * The `addMany` function takes in multiple keys or nodes or entries or raw values along with
205
+ * optional values, and adds them to a data structure while returning an array indicating whether
206
+ * each insertion was successful.
207
+ * @param keysOrNodesOrEntriesOrRaws - `keysOrNodesOrEntriesOrRaws` is an iterable that can contain a
208
+ * mix of keys, nodes, entries, or raw values. Each element in this iterable can be of type
209
+ * `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`.
210
+ * @param [values] - The `values` parameter in the `addMany` function is an optional parameter that
211
+ * accepts an iterable of values. These values correspond to the keys or nodes being added in the
212
+ * `keysOrNodesOrEntriesOrRaws` parameter. If provided, the function will iterate over the values and
213
+ * assign them
214
+ * @returns The `addMany` method returns an array of boolean values indicating whether each key,
215
+ * node, entry, or raw value was successfully added to the data structure. Each boolean value
216
+ * corresponds to the success of adding the corresponding key or value in the input iterable.
217
+ */
218
+ addMany(keysOrNodesOrEntriesOrRaws: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE> | R>, values?: Iterable<V | undefined>): boolean[];
238
219
  /**
239
220
  * Time Complexity: O(k * n)
240
221
  * Space Complexity: O(1)
241
222
  *
242
- * The `refill` function clears the current data and adds new data to the collection.
243
- * @param keysOrNodesOrEntriesOrRawElements - An iterable collection of keys, nodes, entries, or raw
244
- * elements. These can be of any type (R) or a specific type (BTNKeyOrNodeOrEntry<K, V, NODE>).
245
- * @param [values] - The `values` parameter is an optional iterable of values that will be associated
246
- * with the keys or nodes being added. If provided, the values will be assigned to the corresponding
247
- * keys or nodes. If not provided, the values will be set to `undefined`.
248
- */
249
- refill(keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): void;
250
- delete<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C): BinaryTreeDeleteResult<NODE>[];
251
- delete<C extends BTNCallback<NODE, NODE>>(identifier: OptBTNOrNull<NODE>, callback?: C): BinaryTreeDeleteResult<NODE>[];
252
- delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C): BinaryTreeDeleteResult<NODE>[];
253
- getNodes<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
254
- getNodes<C extends BTNCallback<NODE, NODE>>(identifier: OptBTNOrNull<NODE>, callback?: C, onlyOne?: boolean, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
255
- getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
256
- getNode<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBTNOrNull<NODE>;
257
- getNode<C extends BTNCallback<NODE, NODE>>(identifier: OptBTNOrNull<NODE>, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBTNOrNull<NODE>;
258
- getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBTNOrNull<NODE>;
223
+ * The `refill` function clears the existing data structure and then adds new key-value pairs based
224
+ * on the provided input.
225
+ * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter in the `refill`
226
+ * method can accept an iterable containing a mix of `BTNKeyOrNodeOrEntry<K, V, NODE>` objects or `R`
227
+ * objects.
228
+ * @param [values] - The `values` parameter in the `refill` method is an optional parameter that
229
+ * accepts an iterable of values of type `V` or `undefined`.
230
+ */
231
+ refill(keysOrNodesOrEntriesOrRaws: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE> | R>, values?: Iterable<V | undefined>): void;
232
+ /**
233
+ * Time Complexity: O(n)
234
+ * Space Complexity: O(1)
235
+ *
236
+ * The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
237
+ * the deleted node along with information for tree balancing.
238
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw
239
+ * - The `delete` method you provided is used to delete a node from a binary tree based on the key,
240
+ * node, entry or raw data. The method returns an array of
241
+ * `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
242
+ * balancing is needed.
243
+ * @returns The `delete` method returns an array of `BinaryTreeDeleteResult` objects. Each object in
244
+ * the array contains information about the node that was deleted (`deleted`) and the node that may
245
+ * need to be balanced (`needBalanced`).
246
+ */
247
+ delete(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): BinaryTreeDeleteResult<NODE>[];
248
+ /**
249
+ * Time Complexity: O(n)
250
+ * Space Complexity: O(k + log n)
251
+ *
252
+ * The function `getNodes` retrieves nodes from a binary tree based on a key, node, entry, raw data,
253
+ * or predicate, with options for recursive or iterative traversal.
254
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrNodeOrEntryOrRawOrPredicate
255
+ * - The `getNodes` function you provided takes several parameters:
256
+ * @param [onlyOne=false] - The `onlyOne` parameter in the `getNodes` function is a boolean flag that
257
+ * determines whether to return only the first node that matches the criteria specified by the
258
+ * `keyOrNodeOrEntryOrRawOrPredicate` parameter. If `onlyOne` is set to `true`, the function will
259
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
260
+ * `getNodes` function is used to specify the starting point for traversing the binary tree. It
261
+ * represents the root node of the binary tree or the node from which the traversal should begin. If
262
+ * not provided, the default value is set to `this._root
263
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `getNodes` function
264
+ * determines the type of iteration to be performed when traversing the nodes of a binary tree. It
265
+ * can have two possible values:
266
+ * @returns The `getNodes` function returns an array of nodes that satisfy the provided condition
267
+ * based on the input parameters and the iteration type specified.
268
+ */
269
+ getNodes(keyOrNodeOrEntryOrRawOrPredicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, onlyOne?: boolean, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): NODE[];
270
+ /**
271
+ * Time Complexity: O(n)
272
+ * Space Complexity: O(log n).
273
+ *
274
+ * The `getNode` function retrieves a node based on the provided key, node, entry, raw data, or
275
+ * predicate.
276
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrNodeOrEntryOrRawOrPredicate
277
+ * - The `keyOrNodeOrEntryOrRawOrPredicate` parameter in the `getNode` function can accept a key,
278
+ * node, entry, raw data, or a predicate function.
279
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
280
+ * `getNode` function is used to specify the starting point for searching for a node in a binary
281
+ * tree. If no specific starting point is provided, the default value is set to `this._root`, which
282
+ * is typically the root node of the binary tree.
283
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `getNode` method is
284
+ * used to specify the type of iteration to be performed when searching for a node. It has a default
285
+ * value of `this.iterationType`, which means it will use the iteration type defined in the current
286
+ * context if no specific value is provided
287
+ * @returns The `getNode` function is returning the first node that matches the specified criteria,
288
+ * or `null` if no matching node is found.
289
+ */
290
+ getNode(keyOrNodeOrEntryOrRawOrPredicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): OptBTNOrNull<NODE>;
259
291
  /**
260
292
  * Time Complexity: O(n)
261
293
  * Space Complexity: O(log n)
262
294
  *
263
- * The function `getNodeByKey` returns a node with a specific key value from a tree structure.
264
- * @param {K} key - The key parameter is the value that you want to search for in the tree. It is
265
- * used to find the node with the matching key value.
266
- * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
267
- * parameter that specifies the type of iteration to be used when searching for a node in the tree.
268
- * It has a default value of `'ITERATIVE'`.
269
- * @returns a value of type NODE, null, or undefined.
295
+ * The function `getNodeByKey` retrieves a node by its key from a binary tree structure.
296
+ * @param {K} key - The `key` parameter is the value used to search for a specific node in a data
297
+ * structure.
298
+ * @param {IterationType} iterationType - The `iterationType` parameter is a type of iteration that
299
+ * specifies how the tree nodes should be traversed when searching for a node with the given key. It
300
+ * is an optional parameter with a default value of `this.iterationType`.
301
+ * @returns The `getNodeByKey` function is returning an optional binary tree node
302
+ * (`OptBTNOrNull<NODE>`).
270
303
  */
271
304
  getNodeByKey(key: K, iterationType?: IterationType): OptBTNOrNull<NODE>;
272
- get<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
273
- get<C extends BTNCallback<NODE, NODE>>(identifier: OptBTNOrNull<NODE>, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
274
- get<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
275
- has<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
276
- has<C extends BTNCallback<NODE, NODE>>(identifier: OptBTNOrNull<NODE>, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
277
- has<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
305
+ /**
306
+ * Time Complexity: O(n)
307
+ * Space Complexity: O(log n)
308
+ *
309
+ * This function overrides the `get` method to retrieve the value associated with a specified key,
310
+ * node, entry, raw data, or predicate in a data structure.
311
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrNodeOrEntryOrRawOrPredicate
312
+ * - The `keyOrNodeOrEntryOrRawOrPredicate` parameter in the `get` method can accept one of the
313
+ * following types:
314
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the `get`
315
+ * method is used to specify the starting point for searching for a key or node in the binary tree.
316
+ * If no specific starting point is provided, the default starting point is the root of the binary
317
+ * tree (`this._root`).
318
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `get` method is used
319
+ * to specify the type of iteration to be performed when searching for a key in the binary tree. It
320
+ * is an optional parameter with a default value of `this.iterationType`, which means it will use the
321
+ * iteration type defined in the
322
+ * @returns The `get` method is returning the value associated with the specified key, node, entry,
323
+ * raw data, or predicate in the binary tree map. If the specified key or node is found in the tree,
324
+ * the method returns the corresponding value. If the key or node is not found, it returns
325
+ * `undefined`.
326
+ */
327
+ get(keyOrNodeOrEntryOrRawOrPredicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): V | undefined;
328
+ /**
329
+ * Time Complexity: O(n)
330
+ * Space Complexity: O(log n)
331
+ *
332
+ * The `has` function in TypeScript checks if a specified key, node, entry, raw data, or predicate
333
+ * exists in the data structure.
334
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrNodeOrEntryOrRawOrPredicate
335
+ * - The `keyOrNodeOrEntryOrRawOrPredicate` parameter in the `override has` method can accept one of
336
+ * the following types:
337
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
338
+ * `override` method is used to specify the starting point for the search operation within the data
339
+ * structure. It defaults to `this._root` if not provided explicitly.
340
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `override has` method
341
+ * is used to specify the type of iteration to be performed. It has a default value of
342
+ * `this.iterationType`, which means it will use the iteration type defined in the current context if
343
+ * no value is provided when calling the method.
344
+ * @returns The `override has` method is returning a boolean value. It checks if there are any nodes
345
+ * that match the provided key, node, entry, raw data, or predicate in the tree structure. If there
346
+ * are matching nodes, it returns `true`, indicating that the tree contains the specified element.
347
+ * Otherwise, it returns `false`.
348
+ */
349
+ has(keyOrNodeOrEntryOrRawOrPredicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): boolean;
278
350
  /**
279
351
  * Time Complexity: O(1)
280
352
  * Space Complexity: O(1)
281
353
  *
282
- * Clear the binary tree, removing all nodes.
354
+ * The `clear` function resets the root node and size of a data structure to empty.
283
355
  */
284
356
  clear(): void;
285
357
  /**
286
358
  * Time Complexity: O(1)
287
359
  * Space Complexity: O(1)
288
360
  *
289
- * Check if the binary tree is empty.
290
- * @returns {boolean} - True if the binary tree is empty, false otherwise.
361
+ * The `isEmpty` function in TypeScript checks if a data structure has no elements and returns a
362
+ * boolean value.
363
+ * @returns The `isEmpty()` method is returning a boolean value, specifically `true` if the `_size`
364
+ * property is equal to 0, indicating that the data structure is empty, and `false` otherwise.
291
365
  */
292
366
  isEmpty(): boolean;
293
367
  /**
294
368
  * Time Complexity: O(n)
295
369
  * Space Complexity: O(log n)
296
370
  *
297
- * The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
298
- * height of the tree.
299
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The parameter `beginRoot` is optional and
300
- * has a default value of `this.root`. It represents the starting point for checking if the tree is
301
- * perfectly balanced. It can be either a root node (`R`), a key or node or entry
302
- * (`BTNKeyOrNodeOrEntry<K, V, NODE
303
- * @returns a boolean value.
304
- */
305
- isPerfectlyBalanced(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>): boolean;
371
+ * The function checks if a binary tree is perfectly balanced by comparing its minimum height with
372
+ * its height.
373
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter is the starting
374
+ * point for checking if the binary tree is perfectly balanced. It represents the root node of the
375
+ * binary tree or a specific node from which the balance check should begin.
376
+ * @returns The method `isPerfectlyBalanced` is returning a boolean value, which indicates whether
377
+ * the tree starting from the `beginRoot` node is perfectly balanced or not. The return value is
378
+ * determined by comparing the minimum height of the tree with the height of the tree. If the minimum
379
+ * height plus 1 is greater than or equal to the height of the tree, then it is considered perfectly
380
+ * balanced and
381
+ */
382
+ isPerfectlyBalanced(beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R): boolean;
306
383
  /**
307
384
  * Time Complexity: O(n)
308
385
  * Space Complexity: O(1)
309
386
  *
310
- * The function `isBST` checks if a binary search tree is valid, either recursively or iteratively.
311
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
312
- * starting point for checking if a binary search tree (BST) is valid. It can be either a root node
313
- * of the BST, a key value of a node in the BST, or an entry object containing both the key and value
314
- * of a node in the BST
315
- * @param {IterationType} iterationType - The `iterationType` parameter is used to determine the type
316
- * of iteration to be performed while checking if the binary search tree (BST) is valid. It can have
317
- * two possible values:
318
- * @returns a boolean value.
319
- */
320
- isBST(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
387
+ * The function `isBST` in TypeScript checks if a binary search tree is valid using either recursive
388
+ * or iterative methods.
389
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the `isBST`
390
+ * function represents the starting point for checking whether a binary search tree (BST) is valid.
391
+ * It can be a node in the BST or a reference to the root of the BST. If no specific node is
392
+ * provided, the function will default to
393
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `isBST` function
394
+ * determines whether the function should use a recursive approach or an iterative approach to check
395
+ * if the binary search tree (BST) is valid.
396
+ * @returns The `isBST` method is returning a boolean value, which indicates whether the binary
397
+ * search tree (BST) represented by the given root node is a valid BST or not. The method checks if
398
+ * the tree satisfies the BST property, where for every node, all nodes in its left subtree have keys
399
+ * less than the node's key, and all nodes in its right subtree have keys greater than the node's
400
+ */
401
+ isBST(beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): boolean;
321
402
  /**
322
403
  * Time Complexity: O(n)
323
404
  * Space Complexity: O(1)
324
405
  *
325
- * The function calculates the depth of a given node or key in a tree-like data structure.
326
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} dist - The `dist` parameter can be either a `R`
327
- * (representing a root node), or a `BTNKeyOrNodeOrEntry<K, V, NODE>` (representing a key, node, or
328
- * entry).
329
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is optional and
330
- * represents the starting point from which to calculate the depth. It can be either a reference to a
331
- * node in the tree or a key-value pair or an entry object. If not provided, the default value is
332
- * `this.root`, which refers to the root node
333
- * @returns the depth of a node in a tree structure.
334
- */
335
- getDepth(dist: R | BTNKeyOrNodeOrEntry<K, V, NODE>, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>): number;
406
+ * The `getDepth` function calculates the depth between two nodes in a binary tree.
407
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} dist - The `dist` parameter in the `getDepth`
408
+ * function represents the node or entry in a binary tree map, or a reference to a node in the tree.
409
+ * It is the target node for which you want to calculate the depth from the `beginRoot` node.
410
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
411
+ * `getDepth` function represents the starting point from which you want to calculate the depth of a
412
+ * given node or entry in a binary tree. If no specific starting point is provided, the default value
413
+ * for `beginRoot` is set to the root of the binary
414
+ * @returns The `getDepth` method returns the depth of a given node `dist` relative to the
415
+ * `beginRoot` node in a binary tree. If the `dist` node is not found in the path to the `beginRoot`
416
+ * node, it returns the depth of the `dist` node from the root of the tree.
417
+ */
418
+ getDepth(dist: BTNKeyOrNodeOrEntry<K, V, NODE> | R, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R): number;
336
419
  /**
337
420
  * Time Complexity: O(n)
338
421
  * Space Complexity: O(1)
339
422
  *
340
423
  * The `getHeight` function calculates the maximum height of a binary tree using either a recursive
341
- * or iterative approach.
342
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
343
- * starting point for calculating the height of a tree. It can be either a root node (`R`), a key or
344
- * node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current tree.
345
- * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
346
- * iteration used to calculate the height of the tree. It can have two possible values:
347
- * @returns the maximum height of the binary tree.
424
+ * or iterative approach in TypeScript.
425
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter is the starting
426
+ * point from which the height of the binary tree will be calculated. It can be a node in the binary
427
+ * tree or a reference to the root of the tree. If not provided, it defaults to the root of the
428
+ * binary tree data structure.
429
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to determine the type
430
+ * of iteration to be performed while calculating the height of the binary tree. It can have two
431
+ * possible values:
432
+ * @returns The `getHeight` method returns the height of the binary tree starting from the specified
433
+ * root node. The height is calculated based on the maximum depth of the tree, considering either a
434
+ * recursive approach or an iterative approach depending on the `iterationType` parameter.
348
435
  */
349
- getHeight(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
436
+ getHeight(beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): number;
350
437
  /**
351
438
  * Time Complexity: O(n)
352
439
  * Space Complexity: O(log n)
353
440
  *
354
441
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a
355
- * recursive or iterative approach.
356
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
357
- * starting point for calculating the minimum height of a tree. It can be either a root node (`R`), a
358
- * key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current
359
- * tree.
360
- * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
361
- * iteration to be used when calculating the minimum height of the tree. It can have two possible
362
- * values:
363
- * @returns The function `getMinHeight` returns a number, which represents the minimum height of the
364
- * binary tree.
442
+ * recursive or iterative approach in TypeScript.
443
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
444
+ * `getMinHeight` function represents the starting node from which the minimum height of the binary
445
+ * tree will be calculated. It is either a node in the binary tree or a reference to the root of the
446
+ * tree. If not provided, the default value is the root
447
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `getMinHeight` method
448
+ * specifies the type of iteration to use when calculating the minimum height of a binary tree. It
449
+ * can have two possible values:
450
+ * @returns The `getMinHeight` method returns the minimum height of the binary tree starting from the
451
+ * specified root node. The height is calculated based on the shortest path from the root node to a
452
+ * leaf node in the tree. The method uses either a recursive approach or an iterative approach (using
453
+ * a stack) based on the `iterationType` parameter.
365
454
  */
366
- getMinHeight(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
455
+ getMinHeight(beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): number;
367
456
  /**
368
457
  * Time Complexity: O(log n)
369
458
  * Space Complexity: O(log n)
370
459
  *
371
- * The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
372
- * up to the root node, with an option to reverse the order of the nodes.
373
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginNode - The `beginNode` parameter can be either of
374
- * type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
375
- * @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
376
- * resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
377
- * reversed before returning it. If `isReverse` is set to `false` or not provided, the path will
378
- * @returns The function `getPathToRoot` returns an array of `NODE` objects.
379
- */
380
- getPathToRoot(beginNode: R | BTNKeyOrNodeOrEntry<K, V, NODE>, isReverse?: boolean): NODE[];
460
+ * The function `getPathToRoot` in TypeScript retrieves the path from a given node to the root of a
461
+ * tree structure, applying a specified callback function along the way.
462
+ * @param {C} callback - The `callback` parameter is a function that is used to process each node in
463
+ * the path to the root. It is expected to be a function that takes a node as an argument and returns
464
+ * a value based on that node. The return type of the callback function is determined by the generic
465
+ * type `C
466
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginNode - The `beginNode` parameter in the
467
+ * `getPathToRoot` function can be either a key, a node, an entry, or any other value of type `R`.
468
+ * @param [isReverse=true] - The `isReverse` parameter in the `getPathToRoot` function determines
469
+ * whether the resulting path from the given `beginNode` to the root should be in reverse order or
470
+ * not. If `isReverse` is set to `true`, the path will be reversed before being returned. If `is
471
+ * @returns The function `getPathToRoot` returns an array of the return values of the callback
472
+ * function `callback` applied to each node in the path from the `beginNode` to the root node. The
473
+ * array is either in reverse order or in the original order based on the value of the `isReverse`
474
+ * parameter.
475
+ */
476
+ getPathToRoot<C extends BTNCallback<OptBTNOrNull<NODE>>>(callback: C | undefined, beginNode: BTNKeyOrNodeOrEntry<K, V, NODE> | R, isReverse?: boolean): ReturnType<C>[];
381
477
  /**
382
478
  * Time Complexity: O(log n)
383
479
  * Space Complexity: O(1)
@@ -385,21 +481,21 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
385
481
  * The function `getLeftMost` retrieves the leftmost node in a binary tree using either recursive or
386
482
  * tail-recursive iteration.
387
483
  * @param {C} callback - The `callback` parameter is a function that will be called with the leftmost
388
- * node of a binary tree or null if the tree is empty. It has a default value of `_DEFAULT_CALLBACK`
389
- * if not provided explicitly.
390
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter in the
484
+ * node of a binary tree or with `undefined` if the tree is empty. It is provided with a default
485
+ * value of `_DEFAULT_BTN_CALLBACK` if not specified.
486
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
391
487
  * `getLeftMost` function represents the starting point for finding the leftmost node in a binary
392
- * tree. It can be either a reference to the root node of the tree (`R`), or a key, node, or entry in
393
- * the binary tree structure (`
488
+ * tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
489
+ * starting point is provided, the function will default
394
490
  * @param {IterationType} iterationType - The `iterationType` parameter in the `getLeftMost` function
395
491
  * specifies the type of iteration to be used when traversing the binary tree nodes. It can have two
396
492
  * possible values:
397
493
  * @returns The `getLeftMost` function returns the result of the callback function `C` applied to the
398
- * leftmost node in the binary tree starting from the `beginRoot` node. If the `beginRoot` is `NIL`,
399
- * it returns the result of the callback function applied to `undefined`. If the `beginRoot` is not a
400
- * real node, it returns the result of the callback function applied
494
+ * leftmost node in the binary tree starting from the `beginRoot` node. If the `beginRoot` node is
495
+ * `NIL`, it returns the result of the callback function applied to `undefined`. If the `beginRoot`
496
+ * node is not a real node, it returns the result of the callback
401
497
  */
402
- getLeftMost<C extends BTNCallback<OptBTNOrNull<NODE>>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>;
498
+ getLeftMost<C extends BTNCallback<OptBTNOrNull<NODE>>>(callback?: C, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): ReturnType<C>;
403
499
  /**
404
500
  * Time Complexity: O(log n)
405
501
  * Space Complexity: O(1)
@@ -407,224 +503,317 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
407
503
  * The function `getRightMost` retrieves the rightmost node in a binary tree using either recursive
408
504
  * or iterative traversal methods.
409
505
  * @param {C} callback - The `callback` parameter is a function that will be called with the result
410
- * of the operation. It has a generic type `C` which extends `BTNCallback<OptBTNOrNull<NODE>>`. The
411
- * default value for `callback` is `this._DEFAULT_CALLBACK` if it is not provided.
412
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter in the
506
+ * of finding the rightmost node in a binary tree. It is of type `BTNCallback<OptBTNOrNull<NODE>>`,
507
+ * which means it is a callback function that can accept either an optional binary tree node or null
508
+ * as
509
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
413
510
  * `getRightMost` function represents the starting point for finding the rightmost node in a binary
414
- * tree. It can be either a reference to the root node of the tree (`this.root`) or a specific key,
415
- * node, or entry in the tree. If
511
+ * tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
512
+ * starting point is provided, the function will default
416
513
  * @param {IterationType} iterationType - The `iterationType` parameter in the `getRightMost`
417
- * function specifies the type of iteration to be used when finding the rightmost node in a binary
418
- * tree. It can have two possible values:
419
- * @returns The `getRightMost` function returns the result of the callback function `C` applied to
420
- * the rightmost node in the binary tree. The rightmost node is found either through a recursive
421
- * depth-first search (if `iterationType` is 'RECURSIVE') or through an indirect implementation of
422
- * iteration using tail recursion optimization. The result of the callback function applied to the
423
- * rightmost node is returned
514
+ * function specifies the type of iteration to be used when traversing the binary tree nodes. It can
515
+ * have two possible values:
516
+ * @returns The `getRightMost` function returns the result of the callback function `C`, which is
517
+ * passed as a parameter to the function. The callback function is called with the rightmost node in
518
+ * the binary tree structure, determined based on the specified iteration type ('RECURSIVE' or
519
+ * other).
424
520
  */
425
- getRightMost<C extends BTNCallback<OptBTNOrNull<NODE>>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>;
521
+ getRightMost<C extends BTNCallback<OptBTNOrNull<NODE>>>(callback?: C, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): ReturnType<C>;
426
522
  /**
427
523
  * Time Complexity: O(log n)
428
524
  * Space Complexity: O(1)
429
525
  *
430
- * The function returns the predecessor node of a given node in a binary tree.
431
- * @param {NODE} node - The parameter "node" is of type "NODE", which represents a node in a binary
432
- * tree.
433
- * @returns the predecessor node of the given node.
526
+ * The function `getPredecessor` in TypeScript returns the predecessor node of a given node in a
527
+ * binary tree.
528
+ * @param {NODE} node - The `getPredecessor` function you provided seems to be attempting to find the
529
+ * predecessor of a given node in a binary tree. However, there seems to be a logical issue in the
530
+ * while loop condition that might cause an infinite loop.
531
+ * @returns The `getPredecessor` function returns the predecessor node of the input `NODE` parameter.
532
+ * If the left child of the input node exists, it traverses to the rightmost node of the left subtree
533
+ * to find the predecessor. If the left child does not exist, it returns the input node itself.
434
534
  */
435
535
  getPredecessor(node: NODE): NODE;
436
536
  /**
437
537
  * Time Complexity: O(log n)
438
538
  * Space Complexity: O(1)
439
539
  *
440
- * The function `getSuccessor` returns the next node in a binary tree given a current node.
441
- * @param {K | NODE | null} [x] - The parameter `x` can be of type `K`, `NODE`, or `null`.
442
- * @returns The function `getSuccessor` returns a `NODE` object if a successor exists, `null` if
443
- * there is no successor, and `undefined` if the input `x` is not a valid node.
540
+ * The function `getSuccessor` in TypeScript returns the next node in an in-order traversal of a
541
+ * binary tree.
542
+ * @param {K | NODE | null} [x] - The `getSuccessor` function takes a parameter `x`, which can be of
543
+ * type `K`, `NODE`, or `null`.
544
+ * @returns The `getSuccessor` function returns the successor node of the input node `x`. If `x` has
545
+ * a right child, the function returns the leftmost node in the right subtree of `x`. If `x` does not
546
+ * have a right child, the function traverses up the parent nodes until it finds a node that is not
547
+ * the right child of its parent, and returns that node
444
548
  */
445
549
  getSuccessor(x?: K | NODE | null): OptBTNOrNull<NODE>;
446
- dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
447
- dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: boolean): ReturnType<C>[];
448
- bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
449
- bfs<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
550
+ dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): ReturnType<C>[];
551
+ dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType, includeNull?: boolean): ReturnType<C>[];
552
+ bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
553
+ bfs<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
450
554
  /**
451
555
  * Time complexity: O(n)
452
556
  * Space complexity: O(n)
453
557
  *
454
- * The `leaves` function in TypeScript iterates through a binary tree to find and return the leaf
455
- * nodes based on a specified callback and iteration type.
558
+ * The `leaves` function in TypeScript returns an array of values from leaf nodes in a binary tree
559
+ * structure based on a specified callback and iteration type.
456
560
  * @param {C} callback - The `callback` parameter is a function that will be called on each leaf node
457
- * in the binary tree. It is a generic type `C` that extends `BTNCallback<NODE | null>`, where `NODE`
458
- * represents a node in the binary tree. The default value for `callback` is
459
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter in the `leaves`
561
+ * in the binary tree. It is optional and defaults to a default callback function if not provided.
562
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the `leaves`
460
563
  * method is used to specify the starting point for finding and processing the leaves of a binary
461
- * tree. It represents the root node of the binary tree or a specific key, node, or entry within the
462
- * tree from which the search for leaves should begin
564
+ * tree. It can be provided as either a key, a node, or an entry in the binary tree structure. If not
565
+ * explicitly provided, the default value
463
566
  * @param {IterationType} iterationType - The `iterationType` parameter in the `leaves` method
464
567
  * specifies the type of iteration to be performed when collecting the leaves of a binary tree. It
465
568
  * can have two possible values:
466
569
  * @returns The `leaves` method returns an array of values that are the result of applying the
467
- * provided callback function to the leaf nodes in the binary tree structure.
570
+ * provided callback function to each leaf node in the binary tree.
468
571
  */
469
- leaves<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
470
- listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
471
- listLevels<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
572
+ leaves<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): ReturnType<C>[];
573
+ listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
574
+ listLevels<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
472
575
  /**
473
576
  * Time complexity: O(n)
474
577
  * Space complexity: O(n)
475
578
  *
476
- * The `morris` function performs a depth-first traversal on a binary tree using the Morris traversal
477
- * algorithm.
478
- * @param {C} callback - The `callback` parameter is a function that will be called for each node in
479
- * the tree. It takes a single argument, which is the current node, and can return any value. The
480
- * return type of the `callback` function is determined by the `ReturnType<C>` type, which represents
481
- * the return
482
- * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function is used
483
- * to specify the order in which the nodes of a binary tree are traversed. It can take one of the
484
- * following values:
485
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
486
- * point for the traversal. It can be either a node object, a key, or an entry object. If no value is
487
- * provided, the `root` of the tree is used as the starting point.
488
- * @returns The function `morris` returns an array of values that are the return values of the
489
- * callback function `callback`.
490
- */
491
- morris<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>): ReturnType<C>[];
579
+ * The `morris` function in TypeScript performs a Depth-First Search traversal on a binary tree using
580
+ * Morris Traversal algorithm with different order patterns.
581
+ * @param {C} callback - The `callback` parameter in the `morris` function is a function that will be
582
+ * called on each node in the binary tree during the traversal. It is of type `C`, which extends the
583
+ * `BTNCallback<NODE>` type. The default value for `callback` is `this._DEFAULT
584
+ * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function specifies
585
+ * the type of Depth-First Search (DFS) order pattern to traverse the binary tree. The possible
586
+ * values for the `pattern` parameter are:
587
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the `morris`
588
+ * function is the starting point for the Morris traversal algorithm. It represents the root node of
589
+ * the binary tree or the node from which the traversal should begin. It can be provided as either a
590
+ * key, a node, an entry, or a reference
591
+ * @returns The `morris` function is returning an array of values that are the result of applying the
592
+ * provided callback function to each node in the binary tree in the specified order pattern (IN,
593
+ * PRE, or POST).
594
+ */
595
+ morris<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R): ReturnType<C>[];
492
596
  /**
493
597
  * Time complexity: O(n)
494
598
  * Space complexity: O(n)
495
599
  *
496
- * The `clone` function creates a deep copy of a tree object.
497
- * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
600
+ * The `clone` function creates a deep copy of a tree structure by traversing it using breadth-first
601
+ * search.
602
+ * @returns The `clone()` method is returning a cloned copy of the tree with the same structure and
603
+ * values as the original tree. The method creates a new tree, iterates over the nodes of the
604
+ * original tree using breadth-first search (bfs), and adds the nodes to the new tree. If a node in
605
+ * the original tree is null, a null node is added to the cloned tree. If a node
498
606
  */
499
607
  clone(): TREE;
500
608
  /**
501
609
  * Time Complexity: O(n)
502
610
  * Space Complexity: O(n)
503
611
  *
504
- * The `filter` function creates a new tree with entries that pass a given predicate function.
505
- * @param predicate - The `predicate` parameter is a callback function that is used to test each
506
- * element in the tree. It takes three arguments: `value`, `key`, and `index`. The `value` argument
507
- * represents the value of the current element being processed, the `key` argument represents the key
508
- * of the
509
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
510
- * specify the value of `this` within the `predicate` function. When the `predicate` function is
511
- * called, `thisArg` will be used as the value of `this` within the function. If `thisArg`
512
- * @returns The `filter` method is returning a new tree object that contains the entries that pass
513
- * the given predicate function.
612
+ * The `filter` function iterates over key-value pairs in a tree data structure and creates a new
613
+ * tree with elements that satisfy a given predicate.
614
+ * @param predicate - The `predicate` parameter in the `filter` method is a function that will be
615
+ * called with four arguments: the `value` of the current entry, the `key` of the current entry, the
616
+ * `index` of the current entry in the iteration, and the reference to the tree itself (`
617
+ * @param {any} [thisArg] - The `thisArg` parameter in the `filter` method allows you to specify the
618
+ * value of `this` that should be used when executing the `predicate` function. This is useful when
619
+ * the `predicate` function relies on the context of a specific object or value. By providing a
620
+ * `thisArg
621
+ * @returns The `filter` method is returning a new tree that contains entries that pass the provided
622
+ * predicate function.
514
623
  */
515
624
  filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: any): TREE;
516
625
  /**
517
626
  * Time Complexity: O(n)
518
627
  * Space Complexity: O(n)
519
628
  *
520
- * The `map` function creates a new tree by applying a callback function to each entry in the current
521
- * tree.
522
- * @param callback - The callback parameter is a function that will be called for each entry in the
523
- * tree. It takes three arguments: value, key, and index. The value argument represents the value of
524
- * the current entry, the key argument represents the key of the current entry, and the index
525
- * argument represents the index of the
526
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
527
- * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
528
- * passed as the `this` value to the `callback` function. If `thisArg` is
529
- * @returns The `map` method is returning a new tree object.
629
+ * The `map` function iterates over key-value pairs in a tree data structure, applies a callback
630
+ * function to each value, and returns a new tree with the updated values.
631
+ * @param callback - The `callback` parameter in the `map` method is a function that will be called
632
+ * on each entry in the tree. It takes four arguments:
633
+ * @param {any} [thisArg] - The `thisArg` parameter in the `map` function is an optional parameter
634
+ * that specifies the value to be passed as `this` when executing the callback function. If provided,
635
+ * the `thisArg` value will be used as the `this` value within the callback function. If `thisArg
636
+ * @returns The `map` method is returning a new tree with the entries modified by the provided
637
+ * callback function. Each entry in the original tree is passed to the callback function, and the
638
+ * result of the callback function is added to the new tree.
530
639
  */
531
640
  map(callback: EntryCallback<K, V | undefined, V>, thisArg?: any): TREE;
532
641
  /**
533
642
  * Time Complexity: O(n)
534
643
  * Space Complexity: O(n)
535
644
  *
536
- * The `print` function in TypeScript prints the binary tree structure with customizable options.
537
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
538
- * point for printing the binary tree. It can be either a node of the binary tree or a key or entry
539
- * that exists in the binary tree. If no value is provided, the root of the binary tree will be used
540
- * as the starting point.
541
- * @param {BinaryTreePrintOptions} [options] - The `options` parameter is an optional object that
542
- * allows you to customize the printing behavior. It has the following properties:
543
- * @returns Nothing is being returned. The function has a return type of `void`, which means it does
544
- * not return any value.
545
- */
546
- print(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, options?: BinaryTreePrintOptions): string;
547
- protected _dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
548
- protected _dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: boolean): ReturnType<C>[];
645
+ * The function `toVisual` in TypeScript overrides the visual representation of a binary tree with
646
+ * customizable options for displaying undefined, null, and sentinel nodes.
647
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
648
+ * `toVisual` method is used to specify the starting point for visualizing the binary tree structure.
649
+ * It can be a node, key, entry, or the root of the tree. If no specific starting point is provided,
650
+ * the default is set to the root
651
+ * @param {BinaryTreePrintOptions} [options] - The `options` parameter in the `toVisual` method is an
652
+ * object that contains the following properties:
653
+ * @returns The `override toVisual` method returns a string that represents the visual display of the
654
+ * binary tree based on the provided options for showing undefined, null, and Red-Black NIL nodes.
655
+ * The method constructs the visual representation by calling the `_displayAux` method and appending
656
+ * the lines to the output string. The final output string contains the visual representation of the
657
+ * binary tree with the specified options.
658
+ */
659
+ toVisual(beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, options?: BinaryTreePrintOptions): string;
660
+ /**
661
+ * Time Complexity: O(n)
662
+ * Space Complexity: O(n)
663
+ *
664
+ * The function `print` in TypeScript overrides the default print behavior to log a visual
665
+ * representation of the binary tree to the console.
666
+ * @param {BinaryTreePrintOptions} [options] - The `options` parameter is used to specify the
667
+ * printing options for the binary tree. It is an optional parameter that allows you to customize how
668
+ * the binary tree is printed, such as choosing between different traversal orders or formatting
669
+ * options.
670
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
671
+ * `override print` method is used to specify the starting point for printing the binary tree. It can
672
+ * be either a key, a node, an entry, or the root of the tree. If no specific starting point is
673
+ * provided, the default value is set to
674
+ */
675
+ print(options?: BinaryTreePrintOptions, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R): void;
676
+ /**
677
+ * Time complexity: O(n)
678
+ * Space complexity: O(n)
679
+ *
680
+ * The `_dfs` function performs a depth-first search traversal on a binary tree structure based on
681
+ * the specified order pattern and callback function.
682
+ * @param {C} callback - The `callback` parameter in the `_dfs` method is a function that will be
683
+ * called on each node visited during the depth-first search traversal. It is of type `C`, which
684
+ * extends `BTNCallback<OptBTNOrNull<NODE>>`. The default value for this parameter is `this._DEFAULT
685
+ * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `_dfs` method specifies the
686
+ * order in which the nodes are visited during the Depth-First Search traversal. It can have one of
687
+ * the following values:
688
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the `_dfs`
689
+ * method is used to specify the starting point for the depth-first search traversal in a binary
690
+ * tree. It can be provided as either a `BTNKeyOrNodeOrEntry` object or a reference to the root node
691
+ * of the tree. If no specific
692
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `_dfs` method
693
+ * specifies the type of iteration to be performed during the Depth-First Search (DFS) traversal of a
694
+ * binary tree. It can have two possible values:
695
+ * @param [includeNull=false] - The `includeNull` parameter in the `_dfs` method is a boolean flag
696
+ * that determines whether null nodes should be included in the depth-first search traversal. If
697
+ * `includeNull` is set to `true`, null nodes will be considered during the traversal process. If it
698
+ * is set to `false`,
699
+ * @param shouldVisitLeft - The `shouldVisitLeft` parameter is a function that takes a node as input
700
+ * and returns a boolean value. It is used to determine whether the left child of a node should be
701
+ * visited during the depth-first search traversal. By default, it checks if the node is truthy (not
702
+ * null or undefined
703
+ * @param shouldVisitRight - The `shouldVisitRight` parameter is a function that takes a node as an
704
+ * argument and returns a boolean value. It is used to determine whether the right child of a node
705
+ * should be visited during the depth-first search traversal. The default implementation checks if
706
+ * the node is truthy before visiting the right child
707
+ * @param shouldVisitRoot - The `shouldVisitRoot` parameter is a function that takes a node as an
708
+ * argument and returns a boolean value. It is used to determine whether the root node should be
709
+ * visited during the depth-first search traversal based on certain conditions. The default
710
+ * implementation checks if the node is a real node or null based
711
+ * @param shouldProcessRoot - The `shouldProcessRoot` parameter is a function that takes a node as an
712
+ * argument and returns a boolean value indicating whether the node should be processed during the
713
+ * depth-first search traversal. The default implementation checks if the node is a real node or null
714
+ * based on the `includeNull` flag. If `
715
+ * @returns The function `_dfs` returns an array of the return type of the callback function provided
716
+ * as input.
717
+ */
718
+ protected _dfs<C extends BTNCallback<OptBTNOrNull<NODE>>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType, includeNull?: boolean, shouldVisitLeft?: (node: OptBTNOrNull<NODE>) => boolean, shouldVisitRight?: (node: OptBTNOrNull<NODE>) => boolean, shouldVisitRoot?: (node: OptBTNOrNull<NODE>) => boolean, shouldProcessRoot?: (node: OptBTNOrNull<NODE>) => boolean): ReturnType<C>[];
549
719
  /**
550
720
  * Time Complexity: O(1)
551
721
  * Space Complexity: O(1)
552
722
  *
553
- * The function `_getIterator` is a generator function that returns an iterator for the key-value
554
- * pairs in a binary search tree.
555
- * @param node - The `node` parameter represents the current node in the binary search tree. It is
556
- * initially set to the root node of the tree.
557
- * @returns an IterableIterator<[K, V | undefined]>.
723
+ * The function `_getIterator` returns an iterable iterator for a binary tree data structure, either
724
+ * using an iterative approach or a recursive approach based on the specified iteration type.
725
+ * @param node - The `node` parameter in the `_getIterator` method represents the current node being
726
+ * processed during iteration. It is initially set to the root node of the data structure (or the
727
+ * node passed as an argument), and then it is traversed through the data structure based on the
728
+ * iteration type specified (`ITER
729
+ * @returns The `_getIterator` method returns an IterableIterator containing key-value pairs of nodes
730
+ * in a binary tree structure. The method uses an iterative approach to traverse the tree based on
731
+ * the `iterationType` property. If the `iterationType` is set to 'ITERATIVE', the method uses a
732
+ * stack to perform an in-order traversal of the tree. If the `iterationType` is not 'ITERATIVE
558
733
  */
559
734
  protected _getIterator(node?: OptBTNOrNull<NODE>): IterableIterator<[K, V | undefined]>;
560
735
  /**
561
736
  * Time Complexity: O(n)
562
737
  * Space Complexity: O(n)
563
738
  *
564
- * The `_displayAux` function is responsible for generating the display layout of a binary tree node,
565
- * taking into account various options such as whether to show null, undefined, or NaN nodes.
566
- * @param {OptBTNOrNull<NODE>} node - The `node` parameter represents a node in a binary tree.
567
- * It can be of type `NODE`, `null`, or `undefined`.
568
- * @param {BinaryTreePrintOptions} options - The `options` parameter is an object that contains the
569
- * following properties:
570
- * @returns The function `_displayAux` returns a `NodeDisplayLayout` which is an array containing the
571
- * following elements:
572
- * 1. `mergedLines`: An array of strings representing the lines of the node display.
573
- * 2. `totalWidth`: The total width of the node display.
574
- * 3. `totalHeight`: The total height of the node display.
575
- * 4. `middleIndex`: The index of the middle character
739
+ * The function `_displayAux` in TypeScript is responsible for generating the display layout of nodes
740
+ * in a binary tree based on specified options.
741
+ * @param node - The `node` parameter in the `_displayAux` function represents a node in a binary
742
+ * tree. It can be either a valid node containing a key or a special type of node like null,
743
+ * undefined, or a Red-Black tree NIL node. The function checks the type of the node and its
744
+ * @param {BinaryTreePrintOptions} options - The `options` parameter in the `_displayAux` function
745
+ * contains the following properties:
746
+ * @returns The `_displayAux` function returns a `NodeDisplayLayout`, which is an array containing
747
+ * information about how to display a node in a binary tree. The `NodeDisplayLayout` consists of four
748
+ * elements:
576
749
  */
577
750
  protected _displayAux(node: OptBTNOrNull<NODE>, options: BinaryTreePrintOptions): NodeDisplayLayout;
578
- protected _DEFAULT_CALLBACK: (node: OptBTNOrNull<NODE>) => K | undefined;
751
+ protected _DEFAULT_BTN_CALLBACK: (node: OptBTNOrNull<NODE>) => K | undefined;
579
752
  /**
580
753
  * Time Complexity: O(1)
581
754
  * Space Complexity: O(1)
582
755
  *
583
- * The function `_swapProperties` swaps the key-value properties between two nodes.
584
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} srcNode - The source node that will be swapped with the
585
- * destination node. It can be either an instance of the class `R`, or an object of type
586
- * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
587
- * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} destNode - The `destNode` parameter is the node where
588
- * the properties will be swapped with the `srcNode`.
589
- * @returns either the `destNode` object with its properties swapped with the `srcNode` object's
590
- * properties, or `undefined` if either `srcNode` or `destNode` is falsy.
591
- */
592
- protected _swapProperties(srcNode: R | BTNKeyOrNodeOrEntry<K, V, NODE>, destNode: R | BTNKeyOrNodeOrEntry<K, V, NODE>): NODE | undefined;
756
+ * The _swapProperties function swaps key and value properties between two nodes in a binary tree.
757
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} srcNode - The `srcNode` parameter in the
758
+ * `_swapProperties` method can be either a BTNKeyOrNodeOrEntry object containing key and value
759
+ * properties, or it can be of type R.
760
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} destNode - The `destNode` parameter in the
761
+ * `_swapProperties` method represents the node or entry where the properties will be swapped with
762
+ * the `srcNode`. It can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`. The method ensures that
763
+ * both `srcNode
764
+ * @returns The `_swapProperties` method returns either the `destNode` with its key and value swapped
765
+ * with the `srcNode`, or `undefined` if either `srcNode` or `destNode` is falsy.
766
+ */
767
+ protected _swapProperties(srcNode: BTNKeyOrNodeOrEntry<K, V, NODE> | R, destNode: BTNKeyOrNodeOrEntry<K, V, NODE> | R): NODE | undefined;
593
768
  /**
594
769
  * Time Complexity: O(1)
595
770
  * Space Complexity: O(1)
596
771
  *
597
- * The function replaces a node in a binary tree with a new node, updating the parent, left child,
598
- * right child, and root if necessary.
599
- * @param {NODE} oldNode - The oldNode parameter represents the node that needs to be replaced in the
600
- * tree.
601
- * @param {NODE} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
602
- * tree.
603
- * @returns the newNode.
772
+ * The _replaceNode function replaces an old node with a new node in a binary tree structure.
773
+ * @param {NODE} oldNode - The `oldNode` parameter represents the node that you want to replace in a
774
+ * tree data structure.
775
+ * @param {NODE} newNode - The `newNode` parameter in the `_replaceNode` function represents the node
776
+ * that will replace the `oldNode` in a tree data structure. This function is responsible for
777
+ * updating the parent, left child, right child, and root (if necessary) references when replacing a
778
+ * node in the tree.
779
+ * @returns The method `_replaceNode` is returning the `newNode` that was passed as a parameter after
780
+ * replacing the `oldNode` with it in the binary tree structure.
604
781
  */
605
782
  protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
606
783
  /**
607
784
  * Time Complexity: O(1)
608
785
  * Space Complexity: O(1)
609
786
  *
610
- * The function sets the root property of an object to the provided value, and also updates the
611
- * parent property of the new root.
612
- * @param {OptBTNOrNull<NODE>} v - The parameter `v` is of type `OptBTNOrNull<NODE>`. This
613
- * means that it can accept a value of type `NODE`, `null`, or `undefined`.
787
+ * The function _setRoot sets the root node of a data structure while updating the parent reference
788
+ * of the previous root node.
789
+ * @param v - The parameter `v` in the `_setRoot` method is of type `OptBTNOrNull<NODE>`, which means
790
+ * it can either be an optional `NODE` type or `null`.
614
791
  */
615
792
  protected _setRoot(v: OptBTNOrNull<NODE>): void;
616
793
  /**
617
794
  * Time Complexity: O(1)
618
795
  * Space Complexity: O(1)
619
796
  *
620
- * The function `_ensureCallback` ensures that a callback function is provided and returns it.
621
- * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is of type
622
- * `ReturnType<C> | null | undefined`. This means it can accept a value that is the return type of
623
- * the generic type `C`, or it can be `null` or `undefined`.
624
- * @param {C} callback - The `callback` parameter is a function that takes a `node` as an argument
625
- * and returns a value. It is of type `C`, which is a generic type that extends the
626
- * `BTNCallback<NODE>` type.
627
- * @returns the callback parameter.
797
+ * The function `_ensurePredicate` in TypeScript ensures that the input is converted into a valid
798
+ * predicate function for a binary tree node.
799
+ * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrEntryOrRawOrPredicate - The
800
+ * `_ensurePredicate` method in the provided code snippet is responsible for ensuring that the input
801
+ * parameter `keyOrEntryOrRawOrPredicate` is transformed into a valid predicate function that can be
802
+ * used for filtering nodes in a binary tree.
803
+ * @returns A BTNPredicate<NODE> function is being returned.
628
804
  */
629
- protected _ensureCallback<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback?: C): C;
805
+ protected _ensurePredicate(keyOrEntryOrRawOrPredicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BTNPredicate<NODE>;
806
+ /**
807
+ * Time Complexity: O(1)
808
+ * Space Complexity: O(1)
809
+ *
810
+ * The function `_isPredicated` checks if a given parameter is a function.
811
+ * @param {any} p - The parameter `p` is a variable of type `any`, which means it can hold any type
812
+ * of value. In this context, the function `_isPredicated` is checking if `p` is a function that
813
+ * satisfies the type `BTNPredicate<NODE>`.
814
+ * @returns The function is checking if the input `p` is a function and returning a boolean value
815
+ * based on that check. If `p` is a function, it will return `true`, indicating that `p` is a
816
+ * predicate function for a binary tree node. If `p` is not a function, it will return `false`.
817
+ */
818
+ protected _isPredicated(p: any): p is BTNPredicate<NODE>;
630
819
  }