bst-typed 1.52.6 → 1.52.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/index.d.ts +4 -0
- package/dist/constants/index.js +8 -0
- package/dist/data-structures/base/iterable-element-base.d.ts +8 -1
- package/dist/data-structures/base/iterable-element-base.js +10 -1
- package/dist/data-structures/base/iterable-entry-base.d.ts +8 -1
- package/dist/data-structures/base/iterable-entry-base.js +10 -10
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +43 -44
- package/dist/data-structures/binary-tree/avl-tree.d.ts +23 -24
- package/dist/data-structures/binary-tree/avl-tree.js +71 -64
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +2 -2
- package/dist/data-structures/binary-tree/binary-tree.d.ts +534 -402
- package/dist/data-structures/binary-tree/binary-tree.js +668 -597
- package/dist/data-structures/binary-tree/bst.d.ts +72 -65
- package/dist/data-structures/binary-tree/bst.js +115 -113
- package/dist/data-structures/binary-tree/rb-tree.d.ts +21 -24
- package/dist/data-structures/binary-tree/rb-tree.js +40 -39
- package/dist/data-structures/binary-tree/segment-tree.d.ts +2 -2
- package/dist/data-structures/binary-tree/segment-tree.js +2 -2
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
- package/dist/data-structures/binary-tree/tree-multi-map.js +44 -43
- package/dist/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/data-structures/graph/abstract-graph.js +7 -4
- package/dist/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/data-structures/graph/directed-graph.js +4 -2
- package/dist/data-structures/graph/undirected-graph.d.ts +2 -2
- package/dist/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/data-structures/hash/hash-map.js +1 -1
- package/dist/data-structures/heap/heap.js +3 -3
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/data-structures/linked-list/doubly-linked-list.js +7 -7
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/data-structures/linked-list/singly-linked-list.js +6 -6
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/data-structures/matrix/matrix.d.ts +2 -2
- package/dist/data-structures/matrix/navigator.d.ts +2 -2
- package/dist/data-structures/matrix/navigator.js +4 -2
- package/dist/data-structures/queue/deque.d.ts +3 -3
- package/dist/data-structures/queue/deque.js +29 -29
- package/dist/data-structures/queue/queue.d.ts +1 -1
- package/dist/data-structures/stack/stack.d.ts +2 -2
- package/dist/data-structures/trie/trie.d.ts +2 -2
- package/dist/data-structures/trie/trie.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interfaces/binary-tree.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
- package/dist/types/data-structures/binary-tree/binary-tree.js +0 -6
- package/package.json +2 -2
- package/src/constants/index.ts +4 -0
- package/src/data-structures/base/iterable-element-base.ts +11 -1
- package/src/data-structures/base/iterable-entry-base.ts +11 -19
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +47 -50
- package/src/data-structures/binary-tree/avl-tree.ts +69 -71
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +697 -725
- package/src/data-structures/binary-tree/bst.ts +123 -129
- package/src/data-structures/binary-tree/rb-tree.ts +44 -46
- package/src/data-structures/binary-tree/segment-tree.ts +2 -2
- package/src/data-structures/binary-tree/tree-multi-map.ts +48 -49
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +4 -4
- package/src/data-structures/graph/undirected-graph.ts +2 -2
- package/src/data-structures/hash/hash-map.ts +3 -3
- package/src/data-structures/heap/heap.ts +3 -3
- package/src/data-structures/linked-list/doubly-linked-list.ts +9 -9
- package/src/data-structures/linked-list/singly-linked-list.ts +8 -8
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +2 -2
- package/src/data-structures/matrix/navigator.ts +4 -4
- package/src/data-structures/queue/deque.ts +31 -31
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/data-structures/stack/stack.ts +2 -2
- package/src/data-structures/trie/trie.ts +3 -3
- package/src/index.ts +2 -1
- package/src/interfaces/binary-tree.ts +3 -3
- 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
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
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
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* `
|
|
77
|
-
*
|
|
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(
|
|
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
|
-
*
|
|
107
|
-
* @param {K} key - The key
|
|
108
|
-
* @param {V} value - The value
|
|
109
|
-
*
|
|
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
|
|
114
|
-
* @param [options] - The `options` parameter
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
* into a node object
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* `
|
|
127
|
-
*
|
|
128
|
-
* @
|
|
129
|
-
*
|
|
130
|
-
|
|
131
|
-
|
|
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`
|
|
137
|
-
*
|
|
138
|
-
* @param {
|
|
139
|
-
* `
|
|
140
|
-
* a raw
|
|
141
|
-
* @param {IterationType}
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* @returns The
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* an instance of
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* `
|
|
166
|
-
*
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
*
|
|
173
|
-
* @
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
|
|
193
|
-
|
|
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
|
|
211
|
-
* and finding the
|
|
212
|
-
* @param {
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
* @returns a boolean value. It returns `true` if the insertion
|
|
220
|
-
* insertion position
|
|
221
|
-
|
|
222
|
-
|
|
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
|
|
228
|
-
* optional
|
|
229
|
-
*
|
|
230
|
-
* @param
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* in the `
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
|
|
237
|
-
|
|
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
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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 | BTNPredicate<NODE>} keyOrNodeOrEntryOrRawOrPredicate
|
|
239
|
+
* - The `delete` method you provided is used to delete a node from a binary tree based on the key,
|
|
240
|
+
* node, entry, raw data, or a custom predicate. 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(keyOrNodeOrEntryOrRawOrPredicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): 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`
|
|
264
|
-
* @param {K} key - The key parameter is the value
|
|
265
|
-
*
|
|
266
|
-
* @param {IterationType}
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* @returns
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
290
|
-
*
|
|
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
|
|
298
|
-
* height
|
|
299
|
-
* @param {
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
|
|
305
|
-
|
|
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
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
|
|
320
|
-
|
|
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
|
|
326
|
-
* @param {
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
* @param {
|
|
330
|
-
* represents the starting point from which to calculate the depth
|
|
331
|
-
* node
|
|
332
|
-
* `
|
|
333
|
-
* @returns the depth of a node
|
|
334
|
-
|
|
335
|
-
|
|
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 {
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
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?:
|
|
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 {
|
|
357
|
-
* starting
|
|
358
|
-
*
|
|
359
|
-
* tree.
|
|
360
|
-
* @param {IterationType} iterationType - The `iterationType` parameter
|
|
361
|
-
* iteration to
|
|
362
|
-
* values:
|
|
363
|
-
* @returns The
|
|
364
|
-
*
|
|
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?:
|
|
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`
|
|
372
|
-
*
|
|
373
|
-
* @param {
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
|
|
380
|
-
|
|
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
|
|
389
|
-
* if not
|
|
390
|
-
* @param {
|
|
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
|
|
393
|
-
* the
|
|
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
|
|
399
|
-
* it returns the result of the callback function applied to `undefined`. If the `beginRoot`
|
|
400
|
-
* real node, it returns the result of the callback
|
|
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?:
|
|
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,260 @@ 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
|
|
411
|
-
*
|
|
412
|
-
*
|
|
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
|
|
415
|
-
*
|
|
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
|
|
418
|
-
*
|
|
419
|
-
* @returns The `getRightMost` function returns the result of the callback function `C
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
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?:
|
|
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
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
*
|
|
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
|
|
441
|
-
*
|
|
442
|
-
* @
|
|
443
|
-
*
|
|
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?:
|
|
447
|
-
dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?:
|
|
448
|
-
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?:
|
|
449
|
-
bfs<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?:
|
|
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
|
|
455
|
-
*
|
|
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
|
|
458
|
-
*
|
|
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
|
|
462
|
-
*
|
|
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
|
|
570
|
+
* provided callback function to each leaf node in the binary tree.
|
|
468
571
|
*/
|
|
469
|
-
leaves<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?:
|
|
470
|
-
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?:
|
|
471
|
-
listLevels<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?:
|
|
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
|
|
477
|
-
* algorithm.
|
|
478
|
-
* @param {C} callback - The `callback` parameter is a function that will be
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
* the
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
* @returns The
|
|
489
|
-
* callback function
|
|
490
|
-
|
|
491
|
-
|
|
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
|
|
497
|
-
*
|
|
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
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
* of the
|
|
509
|
-
* @param {any} [thisArg] - The `thisArg` parameter
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
*
|
|
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
|
|
521
|
-
* tree.
|
|
522
|
-
* @param callback - The callback parameter is a function that will be called
|
|
523
|
-
* tree. It takes
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
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 `
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
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
|
+
protected _dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType): ReturnType<C>[];
|
|
661
|
+
protected _dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNodeOrEntry<K, V, NODE> | R, iterationType?: IterationType, includeNull?: boolean): ReturnType<C>[];
|
|
549
662
|
/**
|
|
550
663
|
* Time Complexity: O(1)
|
|
551
664
|
* Space Complexity: O(1)
|
|
552
665
|
*
|
|
553
|
-
* The function `_getIterator`
|
|
554
|
-
*
|
|
555
|
-
* @param node - The `node` parameter
|
|
556
|
-
* initially set to the root node of the
|
|
557
|
-
*
|
|
666
|
+
* The function `_getIterator` returns an iterable iterator for a binary tree data structure, either
|
|
667
|
+
* using an iterative approach or a recursive approach based on the specified iteration type.
|
|
668
|
+
* @param node - The `node` parameter in the `_getIterator` method represents the current node being
|
|
669
|
+
* processed during iteration. It is initially set to the root node of the data structure (or the
|
|
670
|
+
* node passed as an argument), and then it is traversed through the data structure based on the
|
|
671
|
+
* iteration type specified (`ITER
|
|
672
|
+
* @returns The `_getIterator` method returns an IterableIterator containing key-value pairs of nodes
|
|
673
|
+
* in a binary tree structure. The method uses an iterative approach to traverse the tree based on
|
|
674
|
+
* the `iterationType` property. If the `iterationType` is set to 'ITERATIVE', the method uses a
|
|
675
|
+
* stack to perform an in-order traversal of the tree. If the `iterationType` is not 'ITERATIVE
|
|
558
676
|
*/
|
|
559
677
|
protected _getIterator(node?: OptBTNOrNull<NODE>): IterableIterator<[K, V | undefined]>;
|
|
560
678
|
/**
|
|
561
679
|
* Time Complexity: O(n)
|
|
562
680
|
* Space Complexity: O(n)
|
|
563
681
|
*
|
|
564
|
-
* The `_displayAux`
|
|
565
|
-
*
|
|
566
|
-
* @param
|
|
567
|
-
* It can be
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
* 3. `totalHeight`: The total height of the node display.
|
|
575
|
-
* 4. `middleIndex`: The index of the middle character
|
|
682
|
+
* The function `_displayAux` in TypeScript is responsible for generating the display layout of nodes
|
|
683
|
+
* in a binary tree based on specified options.
|
|
684
|
+
* @param node - The `node` parameter in the `_displayAux` function represents a node in a binary
|
|
685
|
+
* tree. It can be either a valid node containing a key or a special type of node like null,
|
|
686
|
+
* undefined, or a Red-Black tree NIL node. The function checks the type of the node and its
|
|
687
|
+
* @param {BinaryTreePrintOptions} options - The `options` parameter in the `_displayAux` function
|
|
688
|
+
* contains the following properties:
|
|
689
|
+
* @returns The `_displayAux` function returns a `NodeDisplayLayout`, which is an array containing
|
|
690
|
+
* information about how to display a node in a binary tree. The `NodeDisplayLayout` consists of four
|
|
691
|
+
* elements:
|
|
576
692
|
*/
|
|
577
693
|
protected _displayAux(node: OptBTNOrNull<NODE>, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
578
|
-
protected
|
|
694
|
+
protected _DEFAULT_BTN_CALLBACK: (node: OptBTNOrNull<NODE>) => K | undefined;
|
|
579
695
|
/**
|
|
580
696
|
* Time Complexity: O(1)
|
|
581
697
|
* Space Complexity: O(1)
|
|
582
698
|
*
|
|
583
|
-
* The function
|
|
584
|
-
* @param {
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
* @param {
|
|
588
|
-
* the properties will be swapped with
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
|
|
592
|
-
|
|
699
|
+
* The _swapProperties function swaps key and value properties between two nodes in a binary tree.
|
|
700
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} srcNode - The `srcNode` parameter in the
|
|
701
|
+
* `_swapProperties` method can be either a BTNKeyOrNodeOrEntry object containing key and value
|
|
702
|
+
* properties, or it can be of type R.
|
|
703
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} destNode - The `destNode` parameter in the
|
|
704
|
+
* `_swapProperties` method represents the node or entry where the properties will be swapped with
|
|
705
|
+
* the `srcNode`. It can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`. The method ensures that
|
|
706
|
+
* both `srcNode
|
|
707
|
+
* @returns The `_swapProperties` method returns either the `destNode` with its key and value swapped
|
|
708
|
+
* with the `srcNode`, or `undefined` if either `srcNode` or `destNode` is falsy.
|
|
709
|
+
*/
|
|
710
|
+
protected _swapProperties(srcNode: BTNKeyOrNodeOrEntry<K, V, NODE> | R, destNode: BTNKeyOrNodeOrEntry<K, V, NODE> | R): NODE | undefined;
|
|
593
711
|
/**
|
|
594
712
|
* Time Complexity: O(1)
|
|
595
713
|
* Space Complexity: O(1)
|
|
596
714
|
*
|
|
597
|
-
* The function replaces
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
715
|
+
* The _replaceNode function replaces an old node with a new node in a binary tree structure.
|
|
716
|
+
* @param {NODE} oldNode - The `oldNode` parameter represents the node that you want to replace in a
|
|
717
|
+
* tree data structure.
|
|
718
|
+
* @param {NODE} newNode - The `newNode` parameter in the `_replaceNode` function represents the node
|
|
719
|
+
* that will replace the `oldNode` in a tree data structure. This function is responsible for
|
|
720
|
+
* updating the parent, left child, right child, and root (if necessary) references when replacing a
|
|
721
|
+
* node in the tree.
|
|
722
|
+
* @returns The method `_replaceNode` is returning the `newNode` that was passed as a parameter after
|
|
723
|
+
* replacing the `oldNode` with it in the binary tree structure.
|
|
604
724
|
*/
|
|
605
725
|
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
|
|
606
726
|
/**
|
|
607
727
|
* Time Complexity: O(1)
|
|
608
728
|
* Space Complexity: O(1)
|
|
609
729
|
*
|
|
610
|
-
* The function sets the root
|
|
611
|
-
*
|
|
612
|
-
* @param
|
|
613
|
-
*
|
|
730
|
+
* The function _setRoot sets the root node of a data structure while updating the parent reference
|
|
731
|
+
* of the previous root node.
|
|
732
|
+
* @param v - The parameter `v` in the `_setRoot` method is of type `OptBTNOrNull<NODE>`, which means
|
|
733
|
+
* it can either be an optional `NODE` type or `null`.
|
|
614
734
|
*/
|
|
615
735
|
protected _setRoot(v: OptBTNOrNull<NODE>): void;
|
|
616
736
|
/**
|
|
617
737
|
* Time Complexity: O(1)
|
|
618
738
|
* Space Complexity: O(1)
|
|
619
739
|
*
|
|
620
|
-
* The function `
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
* the
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
* @returns the callback parameter.
|
|
740
|
+
* The function `_ensurePredicate` in TypeScript ensures that the input is converted into a valid
|
|
741
|
+
* predicate function for a binary tree node.
|
|
742
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrEntryOrRawOrPredicate - The
|
|
743
|
+
* `_ensurePredicate` method in the provided code snippet is responsible for ensuring that the input
|
|
744
|
+
* parameter `keyOrEntryOrRawOrPredicate` is transformed into a valid predicate function that can be
|
|
745
|
+
* used for filtering nodes in a binary tree.
|
|
746
|
+
* @returns A BTNPredicate<NODE> function is being returned.
|
|
628
747
|
*/
|
|
629
|
-
protected
|
|
748
|
+
protected _ensurePredicate(keyOrEntryOrRawOrPredicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BTNPredicate<NODE>;
|
|
749
|
+
/**
|
|
750
|
+
* Time Complexity: O(1)
|
|
751
|
+
* Space Complexity: O(1)
|
|
752
|
+
*
|
|
753
|
+
* The function `_isPredicated` checks if a given parameter is a function.
|
|
754
|
+
* @param {any} p - The parameter `p` is a variable of type `any`, which means it can hold any type
|
|
755
|
+
* of value. In this context, the function `_isPredicated` is checking if `p` is a function that
|
|
756
|
+
* satisfies the type `BTNPredicate<NODE>`.
|
|
757
|
+
* @returns The function is checking if the input `p` is a function and returning a boolean value
|
|
758
|
+
* based on that check. If `p` is a function, it will return `true`, indicating that `p` is a
|
|
759
|
+
* predicate function for a binary tree node. If `p` is not a function, it will return `false`.
|
|
760
|
+
*/
|
|
761
|
+
protected _isPredicated(p: any): p is BTNPredicate<NODE>;
|
|
630
762
|
}
|