tree-multimap-typed 1.53.7 → 1.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/index.js +5 -0
- package/dist/data-structures/base/iterable-entry-base.js +4 -4
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
- package/dist/data-structures/binary-tree/avl-tree-counter.js +407 -0
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -170
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +133 -328
- package/dist/data-structures/binary-tree/avl-tree.d.ts +103 -69
- package/dist/data-structures/binary-tree/avl-tree.js +130 -70
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +3 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +268 -202
- package/dist/data-structures/binary-tree/binary-tree.js +311 -263
- package/dist/data-structures/binary-tree/bst.d.ts +193 -139
- package/dist/data-structures/binary-tree/bst.js +248 -164
- package/dist/data-structures/binary-tree/index.d.ts +3 -1
- package/dist/data-structures/binary-tree/index.js +3 -1
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +286 -0
- package/dist/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +176 -107
- package/dist/data-structures/binary-tree/tree-counter.d.ts +212 -0
- package/dist/data-structures/binary-tree/tree-counter.js +444 -0
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +78 -170
- package/dist/data-structures/binary-tree/tree-multi-map.js +145 -367
- package/dist/data-structures/graph/abstract-graph.js +2 -2
- package/dist/data-structures/graph/directed-graph.d.ts +3 -0
- package/dist/data-structures/graph/directed-graph.js +3 -0
- package/dist/data-structures/graph/map-graph.d.ts +3 -0
- package/dist/data-structures/graph/map-graph.js +3 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +3 -0
- package/dist/data-structures/graph/undirected-graph.js +3 -0
- package/dist/data-structures/hash/hash-map.d.ts +31 -1
- package/dist/data-structures/hash/hash-map.js +35 -5
- package/dist/data-structures/heap/heap.d.ts +20 -3
- package/dist/data-structures/heap/heap.js +31 -11
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +46 -11
- package/dist/data-structures/linked-list/doubly-linked-list.js +68 -21
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +47 -11
- package/dist/data-structures/linked-list/singly-linked-list.js +73 -26
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +3 -0
- package/dist/data-structures/linked-list/skip-linked-list.js +3 -0
- package/dist/data-structures/matrix/matrix.d.ts +3 -0
- package/dist/data-structures/matrix/matrix.js +3 -0
- package/dist/data-structures/matrix/navigator.d.ts +3 -0
- package/dist/data-structures/matrix/navigator.js +3 -0
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +3 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +3 -0
- package/dist/data-structures/queue/deque.d.ts +37 -8
- package/dist/data-structures/queue/deque.js +73 -29
- package/dist/data-structures/queue/queue.d.ts +41 -1
- package/dist/data-structures/queue/queue.js +51 -9
- package/dist/data-structures/stack/stack.d.ts +27 -10
- package/dist/data-structures/stack/stack.js +39 -20
- package/dist/data-structures/trie/trie.d.ts +8 -7
- package/dist/data-structures/trie/trie.js +8 -7
- package/dist/interfaces/binary-tree.d.ts +8 -8
- package/dist/types/data-structures/base/base.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/avl-tree-counter.js +2 -0
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -4
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -3
- package/dist/types/data-structures/binary-tree/bst.d.ts +4 -4
- package/dist/types/data-structures/binary-tree/index.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/index.js +2 -0
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -5
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/types/data-structures/binary-tree/tree-counter.js +2 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -5
- package/package.json +2 -2
- package/src/common/index.ts +7 -1
- package/src/data-structures/base/iterable-entry-base.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +151 -370
- package/src/data-structures/binary-tree/avl-tree.ts +162 -105
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
- package/src/data-structures/binary-tree/binary-tree.ts +488 -416
- package/src/data-structures/binary-tree/bst.ts +326 -251
- package/src/data-structures/binary-tree/index.ts +3 -1
- package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +219 -145
- package/src/data-structures/binary-tree/tree-counter.ts +504 -0
- package/src/data-structures/binary-tree/tree-multi-map.ts +159 -401
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/graph/directed-graph.ts +3 -0
- package/src/data-structures/graph/map-graph.ts +3 -0
- package/src/data-structures/graph/undirected-graph.ts +3 -0
- package/src/data-structures/hash/hash-map.ts +37 -7
- package/src/data-structures/heap/heap.ts +33 -10
- package/src/data-structures/linked-list/doubly-linked-list.ts +75 -21
- package/src/data-structures/linked-list/singly-linked-list.ts +80 -27
- package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
- package/src/data-structures/matrix/matrix.ts +3 -0
- package/src/data-structures/matrix/navigator.ts +3 -0
- package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
- package/src/data-structures/queue/deque.ts +72 -28
- package/src/data-structures/queue/queue.ts +50 -7
- package/src/data-structures/stack/stack.ts +39 -20
- package/src/data-structures/trie/trie.ts +8 -7
- package/src/index.ts +2 -2
- package/src/interfaces/binary-tree.ts +10 -21
- package/src/types/data-structures/base/base.ts +1 -1
- package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -6
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/binary-tree.ts +0 -5
- package/src/types/data-structures/binary-tree/bst.ts +6 -6
- package/src/types/data-structures/binary-tree/index.ts +3 -1
- package/src/types/data-structures/binary-tree/red-black-tree.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -7
- package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -209
- package/src/types/data-structures/binary-tree/rb-tree.ts +0 -10
|
@@ -5,26 +5,43 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import { BinaryTreeDeleteResult,
|
|
8
|
+
import type { BinaryTreeDeleteResult, BinaryTreeOptions, BinaryTreePrintOptions, BTNEntry, BTNRep, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeCallback, NodeDisplayLayout, NodePredicate, OptNodeOrNull, RBTNColor, ToEntryFn } from '../../types';
|
|
9
9
|
import { IBinaryTree } from '../../interfaces';
|
|
10
10
|
import { IterableEntryBase } from '../base';
|
|
11
11
|
import { Range } from '../../common';
|
|
12
12
|
/**
|
|
13
13
|
* Represents a node in a binary tree.
|
|
14
14
|
* @template V - The type of data stored in the node.
|
|
15
|
-
* @template
|
|
15
|
+
* @template BinaryTreeNode<K, V> - The type of the family relationship in the binary tree.
|
|
16
16
|
*/
|
|
17
|
-
export declare class BinaryTreeNode<K = any, V = any
|
|
17
|
+
export declare class BinaryTreeNode<K = any, V = any> {
|
|
18
|
+
/**
|
|
19
|
+
* The constructor function initializes an object with a key and an optional value in TypeScript.
|
|
20
|
+
* @param {K} key - The `key` parameter in the constructor function is used to store the key value
|
|
21
|
+
* for the key-value pair.
|
|
22
|
+
* @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
|
|
23
|
+
* have to be provided when creating an instance of the class. If a `value` is not provided, it will
|
|
24
|
+
* default to `undefined`.
|
|
25
|
+
*/
|
|
26
|
+
constructor(key: K, value?: V);
|
|
18
27
|
key: K;
|
|
19
28
|
value?: V;
|
|
20
|
-
parent?:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
parent?: BinaryTreeNode<K, V>;
|
|
30
|
+
_left?: OptNodeOrNull<BinaryTreeNode<K, V>>;
|
|
31
|
+
get left(): OptNodeOrNull<BinaryTreeNode<K, V>>;
|
|
32
|
+
set left(v: OptNodeOrNull<BinaryTreeNode<K, V>>);
|
|
33
|
+
_right?: OptNodeOrNull<BinaryTreeNode<K, V>>;
|
|
34
|
+
get right(): OptNodeOrNull<BinaryTreeNode<K, V>>;
|
|
35
|
+
set right(v: OptNodeOrNull<BinaryTreeNode<K, V>>);
|
|
36
|
+
_height: number;
|
|
37
|
+
get height(): number;
|
|
38
|
+
set height(value: number);
|
|
39
|
+
_color: RBTNColor;
|
|
40
|
+
get color(): RBTNColor;
|
|
41
|
+
set color(value: RBTNColor);
|
|
42
|
+
_count: number;
|
|
43
|
+
get count(): number;
|
|
44
|
+
set count(value: number);
|
|
28
45
|
get familyPosition(): FamilyPosition;
|
|
29
46
|
}
|
|
30
47
|
/**
|
|
@@ -34,41 +51,47 @@ export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNod
|
|
|
34
51
|
* 4. Subtrees: Each child of a node forms the root of a subtree.
|
|
35
52
|
* 5. Leaf Nodes: Nodes without children are leaves.
|
|
36
53
|
*/
|
|
37
|
-
export declare class BinaryTree<K = any, V = any, R = object,
|
|
38
|
-
iterationType: IterationType;
|
|
54
|
+
export declare class BinaryTree<K = any, V = any, R = object, MK = any, MV = any, MR = object> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, R, MK, MV, MR> {
|
|
39
55
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* @param [options] - The `options` parameter in the constructor is an object that can
|
|
46
|
-
* following properties:
|
|
56
|
+
* This TypeScript constructor function initializes a binary tree with optional options and adds
|
|
57
|
+
* elements based on the provided input.
|
|
58
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
59
|
+
* iterable that can contain either objects of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It
|
|
60
|
+
* is used to initialize the binary tree with keys, nodes, entries, or raw data.
|
|
61
|
+
* @param [options] - The `options` parameter in the constructor is an optional object that can
|
|
62
|
+
* contain the following properties:
|
|
47
63
|
*/
|
|
48
|
-
constructor(keysNodesEntriesOrRaws?: Iterable<BTNRep<K, V,
|
|
64
|
+
constructor(keysNodesEntriesOrRaws?: Iterable<BTNRep<K, V, BinaryTreeNode<K, V>> | R>, options?: BinaryTreeOptions<K, V, R>);
|
|
65
|
+
iterationType: IterationType;
|
|
49
66
|
protected _isMapMode: boolean;
|
|
50
67
|
get isMapMode(): boolean;
|
|
51
68
|
protected _store: Map<K, V | undefined>;
|
|
52
69
|
get store(): Map<K, V | undefined>;
|
|
53
|
-
protected _root?: OptNodeOrNull<
|
|
54
|
-
get root(): OptNodeOrNull<
|
|
70
|
+
protected _root?: OptNodeOrNull<BinaryTreeNode<K, V>>;
|
|
71
|
+
get root(): OptNodeOrNull<BinaryTreeNode<K, V>>;
|
|
55
72
|
protected _size: number;
|
|
56
73
|
get size(): number;
|
|
57
|
-
protected _NIL:
|
|
58
|
-
get NIL():
|
|
74
|
+
protected _NIL: BinaryTreeNode<K, V>;
|
|
75
|
+
get NIL(): BinaryTreeNode<K, V>;
|
|
59
76
|
protected _toEntryFn?: ToEntryFn<K, V, R>;
|
|
60
77
|
get toEntryFn(): ToEntryFn<K, V, R> | undefined;
|
|
61
78
|
/**
|
|
79
|
+
* Time Complexity: O(1)
|
|
80
|
+
* Space Complexity: O(1)
|
|
81
|
+
*
|
|
62
82
|
* The function creates a new binary tree node with a specified key and optional value.
|
|
63
83
|
* @param {K} key - The `key` parameter is the key of the node being created in the binary tree.
|
|
64
84
|
* @param {V} [value] - The `value` parameter in the `createNode` function is optional, meaning it is
|
|
65
85
|
* not required to be provided when calling the function. If a `value` is provided, it should be of
|
|
66
86
|
* type `V`, which is the type of the value associated with the node.
|
|
67
87
|
* @returns A new BinaryTreeNode instance with the provided key and value is being returned, casted
|
|
68
|
-
* as
|
|
88
|
+
* as BinaryTreeNode<K, V>.
|
|
69
89
|
*/
|
|
70
|
-
createNode(key: K, value?: V):
|
|
90
|
+
createNode(key: K, value?: V): BinaryTreeNode<K, V>;
|
|
71
91
|
/**
|
|
92
|
+
* Time Complexity: O(1)
|
|
93
|
+
* Space Complexity: O(1)
|
|
94
|
+
*
|
|
72
95
|
* The function creates a binary tree with the specified options.
|
|
73
96
|
* @param [options] - The `options` parameter in the `createTree` function is an optional parameter
|
|
74
97
|
* that allows you to provide partial configuration options for creating a binary tree. It is of type
|
|
@@ -76,31 +99,15 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
76
99
|
* of properties
|
|
77
100
|
* @returns A new instance of a binary tree with the specified options is being returned.
|
|
78
101
|
*/
|
|
79
|
-
createTree(options?: BinaryTreeOptions<K, V, R>):
|
|
80
|
-
/**
|
|
81
|
-
* The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
|
|
82
|
-
* or returns null.
|
|
83
|
-
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
84
|
-
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
|
|
85
|
-
* can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
|
|
86
|
-
* node, an entry
|
|
87
|
-
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
88
|
-
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
89
|
-
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
90
|
-
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
91
|
-
* (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
|
|
92
|
-
* input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
|
|
93
|
-
* value.
|
|
94
|
-
*/
|
|
95
|
-
keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): [OptNodeOrNull<NODE>, V | undefined];
|
|
102
|
+
createTree(options?: BinaryTreeOptions<K, V, R>): BinaryTree<K, V, R, MK, MV, MR>;
|
|
96
103
|
/**
|
|
97
104
|
* Time Complexity: O(n)
|
|
98
105
|
* Space Complexity: O(log n)
|
|
99
106
|
*
|
|
100
107
|
* The function `ensureNode` in TypeScript checks if a given input is a node, entry, key, or raw
|
|
101
108
|
* value and returns the corresponding node or null.
|
|
102
|
-
* @param {BTNRep<K, V,
|
|
103
|
-
* parameter in the `ensureNode` function can be of type `BTNRep<K, V,
|
|
109
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
110
|
+
* parameter in the `ensureNode` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It
|
|
104
111
|
* is used to determine whether the input is a key, node, entry, or raw data. The
|
|
105
112
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `ensureNode` function
|
|
106
113
|
* is used to specify the type of iteration to be performed. It has a default value of
|
|
@@ -108,99 +115,134 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
108
115
|
* @returns The `ensureNode` function returns either a node, `null`, or `undefined` based on the
|
|
109
116
|
* conditions specified in the code snippet.
|
|
110
117
|
*/
|
|
111
|
-
ensureNode(
|
|
118
|
+
ensureNode(keyNodeOrEntry: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType): OptNodeOrNull<BinaryTreeNode<K, V>>;
|
|
112
119
|
/**
|
|
120
|
+
* Time Complexity: O(1)
|
|
121
|
+
* Space Complexity: O(1)
|
|
122
|
+
*
|
|
113
123
|
* The function isNode checks if the input is an instance of BinaryTreeNode.
|
|
114
|
-
* @param {BTNRep<K, V,
|
|
115
|
-
* `
|
|
124
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
125
|
+
* `keyNodeOrEntry` can be either a key, a node, an entry, or raw data. The function is
|
|
116
126
|
* checking if the input is an instance of a `BinaryTreeNode` and returning a boolean value
|
|
117
127
|
* accordingly.
|
|
118
|
-
* @returns The function `isNode` is checking if the input `
|
|
128
|
+
* @returns The function `isNode` is checking if the input `keyNodeOrEntry` is an instance of
|
|
119
129
|
* `BinaryTreeNode`. If it is, the function returns `true`, indicating that the input is a node. If
|
|
120
130
|
* it is not an instance of `BinaryTreeNode`, the function returns `false`, indicating that the input
|
|
121
131
|
* is not a node.
|
|
122
132
|
*/
|
|
123
|
-
isNode(
|
|
133
|
+
isNode(keyNodeOrEntry: BTNRep<K, V, BinaryTreeNode<K, V>>): keyNodeOrEntry is BinaryTreeNode<K, V>;
|
|
124
134
|
/**
|
|
135
|
+
* Time Complexity: O(1)
|
|
136
|
+
* Space Complexity: O(1)
|
|
137
|
+
*
|
|
125
138
|
* The function `isRaw` checks if the input parameter is of type `R` by verifying if it is an object.
|
|
126
|
-
* @param {BTNRep<K, V,
|
|
139
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | R} keyNodeEntryOrRaw - BTNRep<K, V, BinaryTreeNode<K, V>>
|
|
127
140
|
* @returns The function `isRaw` is checking if the `keyNodeEntryOrRaw` parameter is of type `R` by
|
|
128
141
|
* checking if it is an object. If the parameter is an object, the function will return `true`,
|
|
129
142
|
* indicating that it is of type `R`.
|
|
130
143
|
*/
|
|
131
|
-
isRaw(keyNodeEntryOrRaw: BTNRep<K, V,
|
|
144
|
+
isRaw(keyNodeEntryOrRaw: BTNRep<K, V, BinaryTreeNode<K, V>> | R): keyNodeEntryOrRaw is R;
|
|
132
145
|
/**
|
|
146
|
+
* Time Complexity: O(1)
|
|
147
|
+
* Space Complexity: O(1)
|
|
148
|
+
*
|
|
133
149
|
* The function `isRealNode` checks if a given input is a valid node in a binary tree.
|
|
134
|
-
* @param {BTNRep<K, V,
|
|
135
|
-
* parameter in the `isRealNode` function can be of type `BTNRep<K, V,
|
|
136
|
-
* The function checks if the input parameter is a `
|
|
137
|
-
* @returns The function `isRealNode` is checking if the input `
|
|
150
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
151
|
+
* parameter in the `isRealNode` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`.
|
|
152
|
+
* The function checks if the input parameter is a `BinaryTreeNode<K, V>` type by verifying if it is not equal
|
|
153
|
+
* @returns The function `isRealNode` is checking if the input `keyNodeOrEntry` is a valid
|
|
138
154
|
* node by comparing it to `this._NIL`, `null`, and `undefined`. If the input is not one of these
|
|
139
155
|
* values, it then calls the `isNode` method to further determine if the input is a node. The
|
|
140
156
|
* function will return a boolean value indicating whether the
|
|
141
157
|
*/
|
|
142
|
-
isRealNode(
|
|
158
|
+
isRealNode(keyNodeOrEntry: BTNRep<K, V, BinaryTreeNode<K, V>>): keyNodeOrEntry is BinaryTreeNode<K, V>;
|
|
143
159
|
/**
|
|
160
|
+
* Time Complexity: O(1)
|
|
161
|
+
* Space Complexity: O(1)
|
|
162
|
+
*
|
|
144
163
|
* The function checks if a given input is a valid node or null.
|
|
145
|
-
* @param {BTNRep<K, V,
|
|
146
|
-
* `
|
|
147
|
-
* V,
|
|
164
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
165
|
+
* `keyNodeOrEntry` in the `isRealNodeOrNull` function can be of type `BTNRep<K,
|
|
166
|
+
* V, BinaryTreeNode<K, V>>` or `R`. It is a union type that can either be a key, a node, an entry, or
|
|
148
167
|
* @returns The function `isRealNodeOrNull` is returning a boolean value. It checks if the input
|
|
149
|
-
* `
|
|
168
|
+
* `keyNodeOrEntry` is either `null` or a real node, and returns `true` if it is a node or
|
|
150
169
|
* `null`, and `false` otherwise.
|
|
151
170
|
*/
|
|
152
|
-
isRealNodeOrNull(
|
|
171
|
+
isRealNodeOrNull(keyNodeOrEntry: BTNRep<K, V, BinaryTreeNode<K, V>>): keyNodeOrEntry is BinaryTreeNode<K, V> | null;
|
|
153
172
|
/**
|
|
173
|
+
* Time Complexity: O(1)
|
|
174
|
+
* Space Complexity: O(1)
|
|
175
|
+
*
|
|
154
176
|
* The function isNIL checks if a given key, node, entry, or raw value is equal to the _NIL value.
|
|
155
|
-
* @param {BTNRep<K, V,
|
|
156
|
-
*
|
|
157
|
-
* @returns The function is checking if the `
|
|
177
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - BTNRep<K, V,
|
|
178
|
+
* BinaryTreeNode<K, V>>
|
|
179
|
+
* @returns The function is checking if the `keyNodeOrEntry` parameter is equal to the `_NIL`
|
|
158
180
|
* property of the current object and returning a boolean value based on that comparison.
|
|
159
181
|
*/
|
|
160
|
-
isNIL(
|
|
161
|
-
|
|
182
|
+
isNIL(keyNodeOrEntry: BTNRep<K, V, BinaryTreeNode<K, V>>): boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Time Complexity: O(1)
|
|
185
|
+
* Space Complexity: O(1)
|
|
186
|
+
*
|
|
187
|
+
* The function `isRange` checks if the input parameter is an instance of the `Range` class.
|
|
188
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>> | Range<K>}
|
|
189
|
+
* keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate` parameter in the `isRange` function can be
|
|
190
|
+
* of type `BTNRep<K, V, BinaryTreeNode<K, V>>`, `NodePredicate<BinaryTreeNode<K, V>>`, or
|
|
191
|
+
* `Range<K>`. The function checks if the `keyNodeEntry
|
|
192
|
+
* @returns The `isRange` function is checking if the `keyNodeEntryOrPredicate` parameter is an
|
|
193
|
+
* instance of the `Range` class. If it is an instance of `Range`, the function will return `true`,
|
|
194
|
+
* indicating that the parameter is a `Range<K>`. If it is not an instance of `Range`, the function
|
|
195
|
+
* will return `false`.
|
|
196
|
+
*/
|
|
197
|
+
isRange(keyNodeEntryOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>> | Range<K>): keyNodeEntryOrPredicate is Range<K>;
|
|
162
198
|
/**
|
|
199
|
+
* Time Complexity: O(1)
|
|
200
|
+
* Space Complexity: O(1)
|
|
201
|
+
*
|
|
163
202
|
* The function determines whether a given key, node, entry, or raw data is a leaf node in a binary
|
|
164
203
|
* tree.
|
|
165
|
-
* @param {BTNRep<K, V,
|
|
166
|
-
* `
|
|
204
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
|
|
205
|
+
* `keyNodeOrEntry` can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It represents a
|
|
167
206
|
* key, node, entry, or raw data in a binary tree structure. The function `isLeaf` checks whether the
|
|
168
207
|
* provided
|
|
169
208
|
* @returns The function `isLeaf` returns a boolean value indicating whether the input
|
|
170
|
-
* `
|
|
209
|
+
* `keyNodeOrEntry` is a leaf node in a binary tree.
|
|
171
210
|
*/
|
|
172
|
-
isLeaf(
|
|
211
|
+
isLeaf(keyNodeOrEntry: BTNRep<K, V, BinaryTreeNode<K, V>>): boolean;
|
|
173
212
|
/**
|
|
213
|
+
* Time Complexity: O(1)
|
|
214
|
+
* Space Complexity: O(1)
|
|
215
|
+
*
|
|
174
216
|
* The function `isEntry` checks if the input is a BTNEntry object by verifying if it is an array
|
|
175
217
|
* with a length of 2.
|
|
176
|
-
* @param {BTNRep<K, V,
|
|
177
|
-
* parameter in the `isEntry` function can be of type `BTNRep<K, V,
|
|
178
|
-
* The function checks if the provided `
|
|
179
|
-
* @returns The `isEntry` function is checking if the `
|
|
218
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
219
|
+
* parameter in the `isEntry` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or type `R`.
|
|
220
|
+
* The function checks if the provided `keyNodeOrEntry` is of type `BTN
|
|
221
|
+
* @returns The `isEntry` function is checking if the `keyNodeOrEntry` parameter is an array
|
|
180
222
|
* with a length of 2. If it is, then it returns `true`, indicating that the parameter is of type
|
|
181
223
|
* `BTNEntry<K, V>`. If the condition is not met, it returns `false`.
|
|
182
224
|
*/
|
|
183
|
-
isEntry(
|
|
225
|
+
isEntry(keyNodeOrEntry: BTNRep<K, V, BinaryTreeNode<K, V>>): keyNodeOrEntry is BTNEntry<K, V>;
|
|
184
226
|
/**
|
|
185
227
|
* Time Complexity O(1)
|
|
186
228
|
* Space Complexity O(1)
|
|
187
229
|
*
|
|
188
|
-
* The function `
|
|
230
|
+
* The function `isValidKey` checks if a given key is comparable.
|
|
189
231
|
* @param {any} key - The `key` parameter is of type `any`, which means it can be any data type in
|
|
190
232
|
* TypeScript.
|
|
191
|
-
* @returns The function `
|
|
233
|
+
* @returns The function `isValidKey` is checking if the `key` parameter is `null` or if it is comparable.
|
|
192
234
|
* If the `key` is `null`, the function returns `true`. Otherwise, it returns the result of the
|
|
193
235
|
* `isComparable` function, which is not provided in the code snippet.
|
|
194
236
|
*/
|
|
195
|
-
|
|
237
|
+
isValidKey(key: any): key is K;
|
|
196
238
|
/**
|
|
197
239
|
* Time Complexity O(n)
|
|
198
240
|
* Space Complexity O(1)
|
|
199
241
|
*
|
|
200
242
|
* The `add` function in TypeScript adds a new node to a binary tree while handling duplicate keys
|
|
201
243
|
* and finding the correct insertion position.
|
|
202
|
-
* @param {BTNRep<K, V,
|
|
203
|
-
* seems to be for adding a new node to a binary tree structure. The `
|
|
244
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `add` method you provided
|
|
245
|
+
* seems to be for adding a new node to a binary tree structure. The `keyNodeOrEntry`
|
|
204
246
|
* parameter in the method can accept different types of values:
|
|
205
247
|
* @param {V} [value] - The `value` parameter in the `add` method represents the value associated
|
|
206
248
|
* with the key that you want to add to the binary tree. When adding a key-value pair to the binary
|
|
@@ -210,17 +252,17 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
210
252
|
* node was successful, and `false` if the insertion position could not be found or if a duplicate
|
|
211
253
|
* key was found and the node was replaced instead of inserted.
|
|
212
254
|
*/
|
|
213
|
-
add(
|
|
255
|
+
add(keyNodeOrEntry: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V): boolean;
|
|
214
256
|
/**
|
|
215
257
|
* Time Complexity: O(k * n)
|
|
216
|
-
* Space Complexity: O(
|
|
258
|
+
* Space Complexity: O(k)
|
|
217
259
|
*
|
|
218
260
|
* The `addMany` function takes in multiple keys or nodes or entries or raw values along with
|
|
219
261
|
* optional values, and adds them to a data structure while returning an array indicating whether
|
|
220
262
|
* each insertion was successful.
|
|
221
263
|
* @param keysNodesEntriesOrRaws - `keysNodesEntriesOrRaws` is an iterable that can contain a
|
|
222
264
|
* mix of keys, nodes, entries, or raw values. Each element in this iterable can be of type
|
|
223
|
-
* `BTNRep<K, V,
|
|
265
|
+
* `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`.
|
|
224
266
|
* @param [values] - The `values` parameter in the `addMany` function is an optional parameter that
|
|
225
267
|
* accepts an iterable of values. These values correspond to the keys or nodes being added in the
|
|
226
268
|
* `keysNodesEntriesOrRaws` parameter. If provided, the function will iterate over the values and
|
|
@@ -229,16 +271,16 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
229
271
|
* node, entry, or raw value was successfully added to the data structure. Each boolean value
|
|
230
272
|
* corresponds to the success of adding the corresponding key or value in the input iterable.
|
|
231
273
|
*/
|
|
232
|
-
addMany(keysNodesEntriesOrRaws: Iterable<BTNRep<K, V,
|
|
274
|
+
addMany(keysNodesEntriesOrRaws: Iterable<BTNRep<K, V, BinaryTreeNode<K, V>> | R>, values?: Iterable<V | undefined>): boolean[];
|
|
233
275
|
/**
|
|
234
276
|
* Time Complexity: O(k * n)
|
|
235
277
|
* Space Complexity: O(1)
|
|
236
278
|
*
|
|
237
279
|
* The `merge` function in TypeScript merges another binary tree into the current tree by adding all
|
|
238
280
|
* elements from the other tree.
|
|
239
|
-
* @param anotherTree -
|
|
281
|
+
* @param anotherTree - BinaryTree<K, V, R, MK, MV, MR>
|
|
240
282
|
*/
|
|
241
|
-
merge(anotherTree: BinaryTree<K, V, R,
|
|
283
|
+
merge(anotherTree: BinaryTree<K, V, R, MK, MV, MR>): void;
|
|
242
284
|
/**
|
|
243
285
|
* Time Complexity: O(k * n)
|
|
244
286
|
* Space Complexity: O(1)
|
|
@@ -246,19 +288,19 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
246
288
|
* The `refill` function clears the existing data structure and then adds new key-value pairs based
|
|
247
289
|
* on the provided input.
|
|
248
290
|
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the `refill`
|
|
249
|
-
* method can accept an iterable containing a mix of `BTNRep<K, V,
|
|
291
|
+
* method can accept an iterable containing a mix of `BTNRep<K, V, BinaryTreeNode<K, V>>` objects or `R`
|
|
250
292
|
* objects.
|
|
251
293
|
* @param [values] - The `values` parameter in the `refill` method is an optional parameter that
|
|
252
294
|
* accepts an iterable of values of type `V` or `undefined`.
|
|
253
295
|
*/
|
|
254
|
-
refill(keysNodesEntriesOrRaws: Iterable<BTNRep<K, V,
|
|
296
|
+
refill(keysNodesEntriesOrRaws: Iterable<BTNRep<K, V, BinaryTreeNode<K, V>> | R>, values?: Iterable<V | undefined>): void;
|
|
255
297
|
/**
|
|
256
298
|
* Time Complexity: O(n)
|
|
257
299
|
* Space Complexity: O(1)
|
|
258
300
|
*
|
|
259
301
|
* The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
|
|
260
302
|
* the deleted node along with information for tree balancing.
|
|
261
|
-
* @param {BTNRep<K, V,
|
|
303
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry
|
|
262
304
|
* - The `delete` method you provided is used to delete a node from a binary tree based on the key,
|
|
263
305
|
* node, entry or raw data. The method returns an array of
|
|
264
306
|
* `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
|
|
@@ -267,22 +309,22 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
267
309
|
* the array contains information about the node that was deleted (`deleted`) and the node that may
|
|
268
310
|
* need to be balanced (`needBalanced`).
|
|
269
311
|
*/
|
|
270
|
-
delete(
|
|
312
|
+
delete(keyNodeOrEntry: BTNRep<K, V, BinaryTreeNode<K, V>>): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
|
|
271
313
|
/**
|
|
272
314
|
* Time Complexity: O(n)
|
|
273
315
|
* Space Complexity: O(k + log n)
|
|
274
316
|
*
|
|
275
317
|
* The `search` function in TypeScript performs a depth-first or breadth-first search on a tree
|
|
276
318
|
* structure based on a given predicate or key, with options to return multiple results or just one.
|
|
277
|
-
* @param {BTNRep<K, V,
|
|
278
|
-
* `
|
|
319
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
320
|
+
* `keyNodeEntryOrPredicate` parameter in the `search` function can accept three types of values:
|
|
279
321
|
* @param [onlyOne=false] - The `onlyOne` parameter in the `search` function is a boolean flag that
|
|
280
322
|
* determines whether the search should stop after finding the first matching node. If `onlyOne` is
|
|
281
323
|
* set to `true`, the search will return as soon as a matching node is found. If `onlyOne` is
|
|
282
324
|
* @param {C} callback - The `callback` parameter in the `search` function is a callback function
|
|
283
325
|
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
284
|
-
* extends `NodeCallback<
|
|
285
|
-
* @param {BTNRep<K, V,
|
|
326
|
+
* extends `NodeCallback<BinaryTreeNode<K, V>>`. The default value for `callback` is `this._DEFAULT_NODE_CALLBACK` if
|
|
327
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `search` function is
|
|
286
328
|
* used to specify the node from which the search operation should begin. It represents the starting
|
|
287
329
|
* point in the binary tree where the search will be performed. If no specific `startNode` is
|
|
288
330
|
* provided, the search operation will start from the root
|
|
@@ -292,19 +334,19 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
292
334
|
* @returns The `search` function returns an array of values that match the provided criteria based
|
|
293
335
|
* on the search algorithm implemented within the function.
|
|
294
336
|
*/
|
|
295
|
-
search<C extends NodeCallback<
|
|
337
|
+
search<C extends NodeCallback<BinaryTreeNode<K, V>>>(keyNodeEntryOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>, onlyOne?: boolean, callback?: C, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType): ReturnType<C>[];
|
|
296
338
|
/**
|
|
297
339
|
* Time Complexity: O(n)
|
|
298
340
|
* Space Complexity: O(k + log n)
|
|
299
341
|
*
|
|
300
342
|
* The function `getNodes` retrieves nodes from a binary tree based on a key, node, entry, raw data,
|
|
301
343
|
* or predicate, with options for recursive or iterative traversal.
|
|
302
|
-
* @param {BTNRep<K, V,
|
|
344
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
303
345
|
* - The `getNodes` function you provided takes several parameters:
|
|
304
346
|
* @param [onlyOne=false] - The `onlyOne` parameter in the `getNodes` function is a boolean flag that
|
|
305
347
|
* determines whether to return only the first node that matches the criteria specified by the
|
|
306
|
-
* `
|
|
307
|
-
* @param {BTNRep<K, V,
|
|
348
|
+
* `keyNodeEntryOrPredicate` parameter. If `onlyOne` is set to `true`, the function will
|
|
349
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
308
350
|
* `getNodes` function is used to specify the starting point for traversing the binary tree. It
|
|
309
351
|
* represents the root node of the binary tree or the node from which the traversal should begin. If
|
|
310
352
|
* not provided, the default value is set to `this._root
|
|
@@ -314,17 +356,17 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
314
356
|
* @returns The `getNodes` function returns an array of nodes that satisfy the provided condition
|
|
315
357
|
* based on the input parameters and the iteration type specified.
|
|
316
358
|
*/
|
|
317
|
-
getNodes(
|
|
359
|
+
getNodes(keyNodeEntryOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>, onlyOne?: boolean, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType): BinaryTreeNode<K, V>[];
|
|
318
360
|
/**
|
|
319
361
|
* Time Complexity: O(n)
|
|
320
|
-
* Space Complexity: O(log n)
|
|
362
|
+
* Space Complexity: O(log n)
|
|
321
363
|
*
|
|
322
364
|
* The `getNode` function retrieves a node based on the provided key, node, entry, raw data, or
|
|
323
365
|
* predicate.
|
|
324
|
-
* @param {BTNRep<K, V,
|
|
325
|
-
* - The `
|
|
366
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
367
|
+
* - The `keyNodeEntryOrPredicate` parameter in the `getNode` function can accept a key,
|
|
326
368
|
* node, entry, raw data, or a predicate function.
|
|
327
|
-
* @param {BTNRep<K, V,
|
|
369
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
328
370
|
* `getNode` function is used to specify the starting point for searching for a node in a binary
|
|
329
371
|
* tree. If no specific starting point is provided, the default value is set to `this._root`, which
|
|
330
372
|
* is typically the root node of the binary tree.
|
|
@@ -335,17 +377,17 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
335
377
|
* @returns The `getNode` function is returning the first node that matches the specified criteria,
|
|
336
378
|
* or `null` if no matching node is found.
|
|
337
379
|
*/
|
|
338
|
-
getNode(
|
|
380
|
+
getNode(keyNodeEntryOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType): OptNodeOrNull<BinaryTreeNode<K, V>>;
|
|
339
381
|
/**
|
|
340
382
|
* Time Complexity: O(n)
|
|
341
383
|
* Space Complexity: O(log n)
|
|
342
384
|
*
|
|
343
385
|
* This function overrides the `get` method to retrieve the value associated with a specified key,
|
|
344
386
|
* node, entry, raw data, or predicate in a data structure.
|
|
345
|
-
* @param {BTNRep<K, V,
|
|
346
|
-
* - The `
|
|
387
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
388
|
+
* - The `keyNodeEntryOrPredicate` parameter in the `get` method can accept one of the
|
|
347
389
|
* following types:
|
|
348
|
-
* @param {BTNRep<K, V,
|
|
390
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `get`
|
|
349
391
|
* method is used to specify the starting point for searching for a key or node in the binary tree.
|
|
350
392
|
* If no specific starting point is provided, the default starting point is the root of the binary
|
|
351
393
|
* tree (`this._root`).
|
|
@@ -358,17 +400,17 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
358
400
|
* the method returns the corresponding value. If the key or node is not found, it returns
|
|
359
401
|
* `undefined`.
|
|
360
402
|
*/
|
|
361
|
-
get(
|
|
403
|
+
get(keyNodeEntryOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>>, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType): V | undefined;
|
|
362
404
|
/**
|
|
363
405
|
* Time Complexity: O(n)
|
|
364
406
|
* Space Complexity: O(log n)
|
|
365
407
|
*
|
|
366
408
|
* The `has` function in TypeScript checks if a specified key, node, entry, raw data, or predicate
|
|
367
409
|
* exists in the data structure.
|
|
368
|
-
* @param {BTNRep<K, V,
|
|
369
|
-
* - The `
|
|
410
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
|
|
411
|
+
* - The `keyNodeEntryOrPredicate` parameter in the `override has` method can accept one of
|
|
370
412
|
* the following types:
|
|
371
|
-
* @param {BTNRep<K, V,
|
|
413
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
372
414
|
* `override` method is used to specify the starting point for the search operation within the data
|
|
373
415
|
* structure. It defaults to `this._root` if not provided explicitly.
|
|
374
416
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `override has` method
|
|
@@ -380,12 +422,12 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
380
422
|
* are matching nodes, it returns `true`, indicating that the tree contains the specified element.
|
|
381
423
|
* Otherwise, it returns `false`.
|
|
382
424
|
*/
|
|
383
|
-
has(
|
|
425
|
+
has(keyNodeEntryOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType): boolean;
|
|
384
426
|
/**
|
|
385
427
|
* Time Complexity: O(1)
|
|
386
428
|
* Space Complexity: O(1)
|
|
387
429
|
*
|
|
388
|
-
* The
|
|
430
|
+
* The clear function removes nodes and values in map mode.
|
|
389
431
|
*/
|
|
390
432
|
clear(): void;
|
|
391
433
|
/**
|
|
@@ -404,7 +446,7 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
404
446
|
*
|
|
405
447
|
* The function checks if a binary tree is perfectly balanced by comparing its minimum height with
|
|
406
448
|
* its height.
|
|
407
|
-
* @param {BTNRep<K, V,
|
|
449
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
408
450
|
* point for checking if the binary tree is perfectly balanced. It represents the root node of the
|
|
409
451
|
* binary tree or a specific node from which the balance check should begin.
|
|
410
452
|
* @returns The method `isPerfectlyBalanced` is returning a boolean value, which indicates whether
|
|
@@ -413,14 +455,14 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
413
455
|
* height plus 1 is greater than or equal to the height of the tree, then it is considered perfectly
|
|
414
456
|
* balanced and
|
|
415
457
|
*/
|
|
416
|
-
isPerfectlyBalanced(startNode?: BTNRep<K, V,
|
|
458
|
+
isPerfectlyBalanced(startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>): boolean;
|
|
417
459
|
/**
|
|
418
460
|
* Time Complexity: O(n)
|
|
419
|
-
* Space Complexity: O(
|
|
461
|
+
* Space Complexity: O(log n)
|
|
420
462
|
*
|
|
421
463
|
* The function `isBST` in TypeScript checks if a binary search tree is valid using either recursive
|
|
422
464
|
* or iterative methods.
|
|
423
|
-
* @param {BTNRep<K, V,
|
|
465
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `isBST`
|
|
424
466
|
* function represents the starting point for checking whether a binary search tree (BST) is valid.
|
|
425
467
|
* It can be a node in the BST or a reference to the root of the BST. If no specific node is
|
|
426
468
|
* provided, the function will default to
|
|
@@ -432,16 +474,16 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
432
474
|
* the tree satisfies the BST property, where for every node, all nodes in its left subtree have keys
|
|
433
475
|
* less than the node's key, and all nodes in its right subtree have keys greater than the node's
|
|
434
476
|
*/
|
|
435
|
-
isBST(startNode?: BTNRep<K, V,
|
|
477
|
+
isBST(startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType): boolean;
|
|
436
478
|
/**
|
|
437
479
|
* Time Complexity: O(n)
|
|
438
|
-
* Space Complexity: O(
|
|
480
|
+
* Space Complexity: O(log n)
|
|
439
481
|
*
|
|
440
482
|
* The `getDepth` function calculates the depth between two nodes in a binary tree.
|
|
441
|
-
* @param {BTNRep<K, V,
|
|
483
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} dist - The `dist` parameter in the `getDepth`
|
|
442
484
|
* function represents the node or entry in a binary tree map, or a reference to a node in the tree.
|
|
443
485
|
* It is the target node for which you want to calculate the depth from the `startNode` node.
|
|
444
|
-
* @param {BTNRep<K, V,
|
|
486
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
445
487
|
* `getDepth` function represents the starting point from which you want to calculate the depth of a
|
|
446
488
|
* given node or entry in a binary tree. If no specific starting point is provided, the default value
|
|
447
489
|
* for `startNode` is set to the root of the binary
|
|
@@ -449,14 +491,14 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
449
491
|
* `startNode` node in a binary tree. If the `dist` node is not found in the path to the `startNode`
|
|
450
492
|
* node, it returns the depth of the `dist` node from the root of the tree.
|
|
451
493
|
*/
|
|
452
|
-
getDepth(dist: BTNRep<K, V,
|
|
494
|
+
getDepth(dist: BTNRep<K, V, BinaryTreeNode<K, V>>, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>): number;
|
|
453
495
|
/**
|
|
454
496
|
* Time Complexity: O(n)
|
|
455
|
-
* Space Complexity: O(
|
|
497
|
+
* Space Complexity: O(log n)
|
|
456
498
|
*
|
|
457
499
|
* The `getHeight` function calculates the maximum height of a binary tree using either a recursive
|
|
458
500
|
* or iterative approach in TypeScript.
|
|
459
|
-
* @param {BTNRep<K, V,
|
|
501
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter is the starting
|
|
460
502
|
* point from which the height of the binary tree will be calculated. It can be a node in the binary
|
|
461
503
|
* tree or a reference to the root of the tree. If not provided, it defaults to the root of the
|
|
462
504
|
* binary tree data structure.
|
|
@@ -467,14 +509,14 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
467
509
|
* root node. The height is calculated based on the maximum depth of the tree, considering either a
|
|
468
510
|
* recursive approach or an iterative approach depending on the `iterationType` parameter.
|
|
469
511
|
*/
|
|
470
|
-
getHeight(startNode?: BTNRep<K, V,
|
|
512
|
+
getHeight(startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType): number;
|
|
471
513
|
/**
|
|
472
514
|
* Time Complexity: O(n)
|
|
473
515
|
* Space Complexity: O(log n)
|
|
474
516
|
*
|
|
475
517
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
476
518
|
* recursive or iterative approach in TypeScript.
|
|
477
|
-
* @param {BTNRep<K, V,
|
|
519
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
478
520
|
* `getMinHeight` function represents the starting node from which the minimum height of the binary
|
|
479
521
|
* tree will be calculated. It is either a node in the binary tree or a reference to the root of the
|
|
480
522
|
* tree. If not provided, the default value is the root
|
|
@@ -486,7 +528,7 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
486
528
|
* leaf node in the tree. The method uses either a recursive approach or an iterative approach (using
|
|
487
529
|
* a stack) based on the `iterationType` parameter.
|
|
488
530
|
*/
|
|
489
|
-
getMinHeight(startNode?: BTNRep<K, V,
|
|
531
|
+
getMinHeight(startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType): number;
|
|
490
532
|
/**
|
|
491
533
|
* Time Complexity: O(log n)
|
|
492
534
|
* Space Complexity: O(log n)
|
|
@@ -497,7 +539,7 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
497
539
|
* the path to the root. It is expected to be a function that takes a node as an argument and returns
|
|
498
540
|
* a value based on that node. The return type of the callback function is determined by the generic
|
|
499
541
|
* type `C
|
|
500
|
-
* @param {BTNRep<K, V,
|
|
542
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} beginNode - The `beginNode` parameter in the
|
|
501
543
|
* `getPathToRoot` function can be either a key, a node, an entry, or any other value of type `R`.
|
|
502
544
|
* @param [isReverse=true] - The `isReverse` parameter in the `getPathToRoot` function determines
|
|
503
545
|
* whether the resulting path from the given `beginNode` to the root should be in reverse order or
|
|
@@ -507,17 +549,17 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
507
549
|
* array is either in reverse order or in the original order based on the value of the `isReverse`
|
|
508
550
|
* parameter.
|
|
509
551
|
*/
|
|
510
|
-
getPathToRoot<C extends NodeCallback<OptNodeOrNull<
|
|
552
|
+
getPathToRoot<C extends NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>>(beginNode: BTNRep<K, V, BinaryTreeNode<K, V>>, callback?: C, isReverse?: boolean): ReturnType<C>[];
|
|
511
553
|
/**
|
|
512
554
|
* Time Complexity: O(log n)
|
|
513
|
-
* Space Complexity: O(
|
|
555
|
+
* Space Complexity: O(log n)
|
|
514
556
|
*
|
|
515
557
|
* The function `getLeftMost` retrieves the leftmost node in a binary tree using either recursive or
|
|
516
558
|
* tail-recursive iteration.
|
|
517
559
|
* @param {C} callback - The `callback` parameter is a function that will be called with the leftmost
|
|
518
560
|
* node of a binary tree or with `undefined` if the tree is empty. It is provided with a default
|
|
519
561
|
* value of `_DEFAULT_NODE_CALLBACK` if not specified.
|
|
520
|
-
* @param {BTNRep<K, V,
|
|
562
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
521
563
|
* `getLeftMost` function represents the starting point for finding the leftmost node in a binary
|
|
522
564
|
* tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
|
|
523
565
|
* starting point is provided, the function will default
|
|
@@ -529,18 +571,18 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
529
571
|
* `NIL`, it returns the result of the callback function applied to `undefined`. If the `startNode`
|
|
530
572
|
* node is not a real node, it returns the result of the callback
|
|
531
573
|
*/
|
|
532
|
-
getLeftMost<C extends NodeCallback<OptNodeOrNull<
|
|
574
|
+
getLeftMost<C extends NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>>(callback?: C, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType): ReturnType<C>;
|
|
533
575
|
/**
|
|
534
576
|
* Time Complexity: O(log n)
|
|
535
|
-
* Space Complexity: O(
|
|
577
|
+
* Space Complexity: O(log n)
|
|
536
578
|
*
|
|
537
579
|
* The function `getRightMost` retrieves the rightmost node in a binary tree using either recursive
|
|
538
580
|
* or iterative traversal methods.
|
|
539
581
|
* @param {C} callback - The `callback` parameter is a function that will be called with the result
|
|
540
|
-
* of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<
|
|
582
|
+
* of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`,
|
|
541
583
|
* which means it is a callback function that can accept either an optional binary tree node or null
|
|
542
584
|
* as
|
|
543
|
-
* @param {BTNRep<K, V,
|
|
585
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
544
586
|
* `getRightMost` function represents the starting point for finding the rightmost node in a binary
|
|
545
587
|
* tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
|
|
546
588
|
* starting point is provided, the function will default
|
|
@@ -552,39 +594,39 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
552
594
|
* the binary tree structure, determined based on the specified iteration type ('RECURSIVE' or
|
|
553
595
|
* other).
|
|
554
596
|
*/
|
|
555
|
-
getRightMost<C extends NodeCallback<OptNodeOrNull<
|
|
597
|
+
getRightMost<C extends NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>>(callback?: C, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType): ReturnType<C>;
|
|
556
598
|
/**
|
|
557
599
|
* Time Complexity: O(log n)
|
|
558
|
-
* Space Complexity: O(
|
|
600
|
+
* Space Complexity: O(log n)
|
|
559
601
|
*
|
|
560
602
|
* The function `getPredecessor` in TypeScript returns the predecessor node of a given node in a
|
|
561
603
|
* binary tree.
|
|
562
|
-
* @param {
|
|
604
|
+
* @param {BinaryTreeNode<K, V>} node - The `getPredecessor` function you provided seems to be attempting to find the
|
|
563
605
|
* predecessor of a given node in a binary tree. However, there seems to be a logical issue in the
|
|
564
606
|
* while loop condition that might cause an infinite loop.
|
|
565
|
-
* @returns The `getPredecessor` function returns the predecessor node of the input `
|
|
607
|
+
* @returns The `getPredecessor` function returns the predecessor node of the input `BinaryTreeNode<K, V>` parameter.
|
|
566
608
|
* If the left child of the input node exists, it traverses to the rightmost node of the left subtree
|
|
567
609
|
* to find the predecessor. If the left child does not exist, it returns the input node itself.
|
|
568
610
|
*/
|
|
569
|
-
getPredecessor(node:
|
|
611
|
+
getPredecessor(node: BinaryTreeNode<K, V>): BinaryTreeNode<K, V>;
|
|
570
612
|
/**
|
|
571
613
|
* Time Complexity: O(log n)
|
|
572
|
-
* Space Complexity: O(
|
|
614
|
+
* Space Complexity: O(log n)
|
|
573
615
|
*
|
|
574
616
|
* The function `getSuccessor` in TypeScript returns the next node in an in-order traversal of a
|
|
575
617
|
* binary tree.
|
|
576
|
-
* @param {K |
|
|
577
|
-
* type `K`, `
|
|
618
|
+
* @param {K | BinaryTreeNode<K, V> | null} [x] - The `getSuccessor` function takes a parameter `x`, which can be of
|
|
619
|
+
* type `K`, `BinaryTreeNode<K, V>`, or `null`.
|
|
578
620
|
* @returns The `getSuccessor` function returns the successor node of the input node `x`. If `x` has
|
|
579
621
|
* a right child, the function returns the leftmost node in the right subtree of `x`. If `x` does not
|
|
580
622
|
* have a right child, the function traverses up the parent nodes until it finds a node that is not
|
|
581
623
|
* the right child of its parent, and returns that node
|
|
582
624
|
*/
|
|
583
|
-
getSuccessor(x?: K |
|
|
584
|
-
dfs<C extends NodeCallback<
|
|
585
|
-
dfs<C extends NodeCallback<
|
|
586
|
-
bfs<C extends NodeCallback<
|
|
587
|
-
bfs<C extends NodeCallback<
|
|
625
|
+
getSuccessor(x?: K | BinaryTreeNode<K, V> | null): OptNodeOrNull<BinaryTreeNode<K, V>>;
|
|
626
|
+
dfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType): ReturnType<C>[];
|
|
627
|
+
dfs<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, pattern?: DFSOrderPattern, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType, includeNull?: boolean): ReturnType<C>[];
|
|
628
|
+
bfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
629
|
+
bfs<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
588
630
|
/**
|
|
589
631
|
* Time complexity: O(n)
|
|
590
632
|
* Space complexity: O(n)
|
|
@@ -593,7 +635,7 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
593
635
|
* structure based on a specified callback and iteration type.
|
|
594
636
|
* @param {C} callback - The `callback` parameter is a function that will be called on each leaf node
|
|
595
637
|
* in the binary tree. It is optional and defaults to a default callback function if not provided.
|
|
596
|
-
* @param {BTNRep<K, V,
|
|
638
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `leaves`
|
|
597
639
|
* method is used to specify the starting point for finding and processing the leaves of a binary
|
|
598
640
|
* tree. It can be provided as either a key, a node, or an entry in the binary tree structure. If not
|
|
599
641
|
* explicitly provided, the default value
|
|
@@ -603,9 +645,9 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
603
645
|
* @returns The `leaves` method returns an array of values that are the result of applying the
|
|
604
646
|
* provided callback function to each leaf node in the binary tree.
|
|
605
647
|
*/
|
|
606
|
-
leaves<C extends NodeCallback<
|
|
607
|
-
listLevels<C extends NodeCallback<
|
|
608
|
-
listLevels<C extends NodeCallback<
|
|
648
|
+
leaves<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType): ReturnType<C>[];
|
|
649
|
+
listLevels<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
650
|
+
listLevels<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
609
651
|
/**
|
|
610
652
|
* Time complexity: O(n)
|
|
611
653
|
* Space complexity: O(n)
|
|
@@ -614,11 +656,11 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
614
656
|
* Morris Traversal algorithm with different order patterns.
|
|
615
657
|
* @param {C} callback - The `callback` parameter in the `morris` function is a function that will be
|
|
616
658
|
* called on each node in the binary tree during the traversal. It is of type `C`, which extends the
|
|
617
|
-
* `NodeCallback<
|
|
659
|
+
* `NodeCallback<BinaryTreeNode<K, V>>` type. The default value for `callback` is `this._DEFAULT
|
|
618
660
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function specifies
|
|
619
661
|
* the type of Depth-First Search (DFS) order pattern to traverse the binary tree. The possible
|
|
620
662
|
* values for the `pattern` parameter are:
|
|
621
|
-
* @param {BTNRep<K, V,
|
|
663
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `morris`
|
|
622
664
|
* function is the starting point for the Morris traversal algorithm. It represents the root node of
|
|
623
665
|
* the binary tree or the node from which the traversal should begin. It can be provided as either a
|
|
624
666
|
* key, a node, an entry, or a reference
|
|
@@ -626,7 +668,7 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
626
668
|
* provided callback function to each node in the binary tree in the specified order pattern (IN,
|
|
627
669
|
* PRE, or POST).
|
|
628
670
|
*/
|
|
629
|
-
morris<C extends NodeCallback<
|
|
671
|
+
morris<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>): ReturnType<C>[];
|
|
630
672
|
/**
|
|
631
673
|
* Time complexity: O(n)
|
|
632
674
|
* Space complexity: O(n)
|
|
@@ -638,7 +680,8 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
638
680
|
* original tree using breadth-first search (bfs), and adds the nodes to the new tree. If a node in
|
|
639
681
|
* the original tree is null, a null node is added to the cloned tree. If a node
|
|
640
682
|
*/
|
|
641
|
-
clone():
|
|
683
|
+
clone(): BinaryTree<K, V, R, MK, MV, MR>;
|
|
684
|
+
protected _clone(cloned: BinaryTree<K, V, R, MK, MV, MR>): void;
|
|
642
685
|
/**
|
|
643
686
|
* Time Complexity: O(n)
|
|
644
687
|
* Space Complexity: O(n)
|
|
@@ -655,30 +698,34 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
655
698
|
* @returns The `filter` method is returning a new tree that contains entries that pass the provided
|
|
656
699
|
* predicate function.
|
|
657
700
|
*/
|
|
658
|
-
filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: any):
|
|
701
|
+
filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: any): BinaryTree<K, V, R, MK, MV, MR>;
|
|
659
702
|
/**
|
|
660
703
|
* Time Complexity: O(n)
|
|
661
704
|
* Space Complexity: O(n)
|
|
662
705
|
*
|
|
663
|
-
* The `map` function
|
|
664
|
-
*
|
|
665
|
-
* @param callback -
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
*
|
|
671
|
-
*
|
|
672
|
-
*
|
|
673
|
-
|
|
674
|
-
|
|
706
|
+
* The `map` function in TypeScript creates a new BinaryTree by applying a callback function to each
|
|
707
|
+
* entry in the original BinaryTree.
|
|
708
|
+
* @param callback - A function that will be called for each entry in the current binary tree. It
|
|
709
|
+
* takes the key, value (which can be undefined), and an array containing the mapped key and value as
|
|
710
|
+
* arguments.
|
|
711
|
+
* @param [options] - The `options` parameter in the `map` method is of type `BinaryTreeOptions<MK,
|
|
712
|
+
* MV, MR>`. It is an optional parameter that allows you to specify additional options for the binary
|
|
713
|
+
* tree being created during the mapping process. These options could include things like custom
|
|
714
|
+
* comparators, initial
|
|
715
|
+
* @param {any} [thisArg] - The `thisArg` parameter in the `map` method is used to specify the value
|
|
716
|
+
* of `this` when executing the `callback` function. It allows you to set the context (value of
|
|
717
|
+
* `this`) within the callback function. If `thisArg` is provided, it will be passed
|
|
718
|
+
* @returns The `map` function is returning a new `BinaryTree` instance filled with entries that are
|
|
719
|
+
* the result of applying the provided `callback` function to each entry in the original tree.
|
|
720
|
+
*/
|
|
721
|
+
map(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: BinaryTreeOptions<MK, MV, MR>, thisArg?: any): BinaryTree<MK, MV, MR>;
|
|
675
722
|
/**
|
|
676
723
|
* Time Complexity: O(n)
|
|
677
724
|
* Space Complexity: O(n)
|
|
678
725
|
*
|
|
679
726
|
* The function `toVisual` in TypeScript overrides the visual representation of a binary tree with
|
|
680
727
|
* customizable options for displaying undefined, null, and sentinel nodes.
|
|
681
|
-
* @param {BTNRep<K, V,
|
|
728
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
682
729
|
* `toVisual` method is used to specify the starting point for visualizing the binary tree structure.
|
|
683
730
|
* It can be a node, key, entry, or the root of the tree. If no specific starting point is provided,
|
|
684
731
|
* the default is set to the root
|
|
@@ -690,7 +737,7 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
690
737
|
* the lines to the output string. The final output string contains the visual representation of the
|
|
691
738
|
* binary tree with the specified options.
|
|
692
739
|
*/
|
|
693
|
-
toVisual(startNode?: BTNRep<K, V,
|
|
740
|
+
toVisual(startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, options?: BinaryTreePrintOptions): string;
|
|
694
741
|
/**
|
|
695
742
|
* Time Complexity: O(n)
|
|
696
743
|
* Space Complexity: O(n)
|
|
@@ -701,12 +748,31 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
701
748
|
* printing options for the binary tree. It is an optional parameter that allows you to customize how
|
|
702
749
|
* the binary tree is printed, such as choosing between different traversal orders or formatting
|
|
703
750
|
* options.
|
|
704
|
-
* @param {BTNRep<K, V,
|
|
751
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
|
|
705
752
|
* `override print` method is used to specify the starting point for printing the binary tree. It can
|
|
706
753
|
* be either a key, a node, an entry, or the root of the tree. If no specific starting point is
|
|
707
754
|
* provided, the default value is set to
|
|
708
755
|
*/
|
|
709
|
-
print(options?: BinaryTreePrintOptions, startNode?: BTNRep<K, V,
|
|
756
|
+
print(options?: BinaryTreePrintOptions, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>): void;
|
|
757
|
+
/**
|
|
758
|
+
* Time Complexity: O(1)
|
|
759
|
+
* Space Complexity: O(1)
|
|
760
|
+
*
|
|
761
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
|
|
762
|
+
* or returns null.
|
|
763
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The
|
|
764
|
+
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeOrEntry`, which
|
|
765
|
+
* can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. This parameter represents either a key, a
|
|
766
|
+
* node, an entry
|
|
767
|
+
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
768
|
+
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
769
|
+
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
770
|
+
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
771
|
+
* (`OptNodeOrNull<BinaryTreeNode<K, V>>`) based on the input parameters provided. The function checks the type of the
|
|
772
|
+
* input parameter (`keyNodeOrEntry`) and processes it accordingly to return a node or null
|
|
773
|
+
* value.
|
|
774
|
+
*/
|
|
775
|
+
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V): [OptNodeOrNull<BinaryTreeNode<K, V>>, V | undefined];
|
|
710
776
|
/**
|
|
711
777
|
* Time complexity: O(n)
|
|
712
778
|
* Space complexity: O(n)
|
|
@@ -715,11 +781,11 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
715
781
|
* the specified order pattern and callback function.
|
|
716
782
|
* @param {C} callback - The `callback` parameter in the `_dfs` method is a function that will be
|
|
717
783
|
* called on each node visited during the depth-first search traversal. It is of type `C`, which
|
|
718
|
-
* extends `NodeCallback<OptNodeOrNull<
|
|
784
|
+
* extends `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`. The default value for this parameter is `this._DEFAULT
|
|
719
785
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `_dfs` method specifies the
|
|
720
786
|
* order in which the nodes are visited during the Depth-First Search traversal. It can have one of
|
|
721
787
|
* the following values:
|
|
722
|
-
* @param {BTNRep<K, V,
|
|
788
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `_dfs`
|
|
723
789
|
* method is used to specify the starting point for the depth-first search traversal in a binary
|
|
724
790
|
* tree. It can be provided as either a `BTNRep` object or a reference to the root node
|
|
725
791
|
* of the tree. If no specific
|
|
@@ -749,7 +815,7 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
749
815
|
* @returns The function `_dfs` returns an array of the return type of the callback function provided
|
|
750
816
|
* as input.
|
|
751
817
|
*/
|
|
752
|
-
protected _dfs<C extends NodeCallback<OptNodeOrNull<
|
|
818
|
+
protected _dfs<C extends NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>>(callback?: C, pattern?: DFSOrderPattern, startNode?: BTNRep<K, V, BinaryTreeNode<K, V>>, iterationType?: IterationType, includeNull?: boolean, shouldVisitLeft?: (node: OptNodeOrNull<BinaryTreeNode<K, V>>) => boolean, shouldVisitRight?: (node: OptNodeOrNull<BinaryTreeNode<K, V>>) => boolean, shouldVisitRoot?: (node: OptNodeOrNull<BinaryTreeNode<K, V>>) => boolean, shouldProcessRoot?: (node: OptNodeOrNull<BinaryTreeNode<K, V>>) => boolean): ReturnType<C>[];
|
|
753
819
|
/**
|
|
754
820
|
* Time Complexity: O(1)
|
|
755
821
|
* Space Complexity: O(1)
|
|
@@ -765,7 +831,7 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
765
831
|
* the `iterationType` property. If the `iterationType` is set to 'ITERATIVE', the method uses a
|
|
766
832
|
* stack to perform an in-order traversal of the tree. If the `iterationType` is not 'ITERATIVE
|
|
767
833
|
*/
|
|
768
|
-
protected _getIterator(node?: OptNodeOrNull<
|
|
834
|
+
protected _getIterator(node?: OptNodeOrNull<BinaryTreeNode<K, V>>): IterableIterator<[K, V | undefined]>;
|
|
769
835
|
/**
|
|
770
836
|
* Time Complexity: O(n)
|
|
771
837
|
* Space Complexity: O(n)
|
|
@@ -781,62 +847,62 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
781
847
|
* information about how to display a node in a binary tree. The `NodeDisplayLayout` consists of four
|
|
782
848
|
* elements:
|
|
783
849
|
*/
|
|
784
|
-
protected _displayAux(node: OptNodeOrNull<
|
|
785
|
-
protected _DEFAULT_NODE_CALLBACK: (node: OptNodeOrNull<
|
|
850
|
+
protected _displayAux(node: OptNodeOrNull<BinaryTreeNode<K, V>>, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
851
|
+
protected _DEFAULT_NODE_CALLBACK: (node: OptNodeOrNull<BinaryTreeNode<K, V>>) => K | undefined;
|
|
786
852
|
/**
|
|
787
853
|
* Time Complexity: O(1)
|
|
788
854
|
* Space Complexity: O(1)
|
|
789
855
|
*
|
|
790
856
|
* The _swapProperties function swaps key and value properties between two nodes in a binary tree.
|
|
791
|
-
* @param {BTNRep<K, V,
|
|
857
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} srcNode - The `srcNode` parameter in the
|
|
792
858
|
* `_swapProperties` method can be either a BTNRep object containing key and value
|
|
793
859
|
* properties, or it can be of type R.
|
|
794
|
-
* @param {BTNRep<K, V,
|
|
860
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} destNode - The `destNode` parameter in the
|
|
795
861
|
* `_swapProperties` method represents the node or entry where the properties will be swapped with
|
|
796
|
-
* the `srcNode`. It can be of type `BTNRep<K, V,
|
|
862
|
+
* the `srcNode`. It can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. The method ensures that
|
|
797
863
|
* both `srcNode
|
|
798
864
|
* @returns The `_swapProperties` method returns either the `destNode` with its key and value swapped
|
|
799
865
|
* with the `srcNode`, or `undefined` if either `srcNode` or `destNode` is falsy.
|
|
800
866
|
*/
|
|
801
|
-
protected _swapProperties(srcNode: BTNRep<K, V,
|
|
867
|
+
protected _swapProperties(srcNode: BTNRep<K, V, BinaryTreeNode<K, V>>, destNode: BTNRep<K, V, BinaryTreeNode<K, V>>): BinaryTreeNode<K, V> | undefined;
|
|
802
868
|
/**
|
|
803
869
|
* Time Complexity: O(1)
|
|
804
870
|
* Space Complexity: O(1)
|
|
805
871
|
*
|
|
806
872
|
* The _replaceNode function replaces an old node with a new node in a binary tree structure.
|
|
807
|
-
* @param {
|
|
873
|
+
* @param {BinaryTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that you want to replace in a
|
|
808
874
|
* tree data structure.
|
|
809
|
-
* @param {
|
|
875
|
+
* @param {BinaryTreeNode<K, V>} newNode - The `newNode` parameter in the `_replaceNode` function represents the node
|
|
810
876
|
* that will replace the `oldNode` in a tree data structure. This function is responsible for
|
|
811
877
|
* updating the parent, left child, right child, and root (if necessary) references when replacing a
|
|
812
878
|
* node in the tree.
|
|
813
879
|
* @returns The method `_replaceNode` is returning the `newNode` that was passed as a parameter after
|
|
814
880
|
* replacing the `oldNode` with it in the binary tree structure.
|
|
815
881
|
*/
|
|
816
|
-
protected _replaceNode(oldNode:
|
|
882
|
+
protected _replaceNode(oldNode: BinaryTreeNode<K, V>, newNode: BinaryTreeNode<K, V>): BinaryTreeNode<K, V>;
|
|
817
883
|
/**
|
|
818
884
|
* Time Complexity: O(1)
|
|
819
885
|
* Space Complexity: O(1)
|
|
820
886
|
*
|
|
821
887
|
* The function _setRoot sets the root node of a data structure while updating the parent reference
|
|
822
888
|
* of the previous root node.
|
|
823
|
-
* @param v - The parameter `v` in the `_setRoot` method is of type `OptNodeOrNull<
|
|
824
|
-
* it can either be an optional `
|
|
889
|
+
* @param v - The parameter `v` in the `_setRoot` method is of type `OptNodeOrNull<BinaryTreeNode<K, V>>`, which means
|
|
890
|
+
* it can either be an optional `BinaryTreeNode<K, V>` type or `null`.
|
|
825
891
|
*/
|
|
826
|
-
protected _setRoot(v: OptNodeOrNull<
|
|
892
|
+
protected _setRoot(v: OptNodeOrNull<BinaryTreeNode<K, V>>): void;
|
|
827
893
|
/**
|
|
828
894
|
* Time Complexity: O(1)
|
|
829
895
|
* Space Complexity: O(1)
|
|
830
896
|
*
|
|
831
897
|
* The function `_ensurePredicate` in TypeScript ensures that the input is converted into a valid
|
|
832
898
|
* predicate function for a binary tree node.
|
|
833
|
-
* @param {BTNRep<K, V,
|
|
899
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
834
900
|
* `_ensurePredicate` method in the provided code snippet is responsible for ensuring that the input
|
|
835
|
-
* parameter `
|
|
901
|
+
* parameter `keyNodeEntryOrPredicate` is transformed into a valid predicate function that can be
|
|
836
902
|
* used for filtering nodes in a binary tree.
|
|
837
|
-
* @returns A NodePredicate<
|
|
903
|
+
* @returns A NodePredicate<BinaryTreeNode<K, V>> function is being returned.
|
|
838
904
|
*/
|
|
839
|
-
protected _ensurePredicate(
|
|
905
|
+
protected _ensurePredicate(keyNodeEntryOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>): NodePredicate<BinaryTreeNode<K, V>>;
|
|
840
906
|
/**
|
|
841
907
|
* Time Complexity: O(1)
|
|
842
908
|
* Space Complexity: O(1)
|
|
@@ -844,26 +910,26 @@ export declare class BinaryTree<K = any, V = any, R = object, NODE extends Binar
|
|
|
844
910
|
* The function `_isPredicate` checks if a given parameter is a function.
|
|
845
911
|
* @param {any} p - The parameter `p` is a variable of type `any`, which means it can hold any type
|
|
846
912
|
* of value. In this context, the function `_isPredicate` is checking if `p` is a function that
|
|
847
|
-
* satisfies the type `NodePredicate<
|
|
913
|
+
* satisfies the type `NodePredicate<BinaryTreeNode<K, V>>`.
|
|
848
914
|
* @returns The function is checking if the input `p` is a function and returning a boolean value
|
|
849
915
|
* based on that check. If `p` is a function, it will return `true`, indicating that `p` is a
|
|
850
916
|
* predicate function for a binary tree node. If `p` is not a function, it will return `false`.
|
|
851
917
|
*/
|
|
852
|
-
protected _isPredicate(p: any): p is NodePredicate<
|
|
918
|
+
protected _isPredicate(p: any): p is NodePredicate<BinaryTreeNode<K, V>>;
|
|
853
919
|
/**
|
|
854
920
|
* Time Complexity: O(1)
|
|
855
921
|
* Space Complexity: O(1)
|
|
856
922
|
*
|
|
857
923
|
* The function `_extractKey` in TypeScript returns the key from a given input, which can be a node,
|
|
858
924
|
* entry, raw data, or null/undefined.
|
|
859
|
-
* @param {BTNRep<K, V,
|
|
860
|
-
* TypeScript method that takes in a parameter `
|
|
861
|
-
* where `BTNRep` is a generic type with keys `K`, `V`, and `
|
|
862
|
-
* @returns The `_extractKey` method returns the key value extracted from the `
|
|
925
|
+
* @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `_extractKey` method you provided is a
|
|
926
|
+
* TypeScript method that takes in a parameter `keyNodeOrEntry` of type `BTNRep<K, V, BinaryTreeNode<K, V>>`,
|
|
927
|
+
* where `BTNRep` is a generic type with keys `K`, `V`, and `BinaryTreeNode<K, V>`, and `
|
|
928
|
+
* @returns The `_extractKey` method returns the key value extracted from the `keyNodeOrEntry`
|
|
863
929
|
* parameter. The return value can be a key value of type `K`, `null`, or `undefined`, depending on
|
|
864
930
|
* the conditions checked in the method.
|
|
865
931
|
*/
|
|
866
|
-
protected _extractKey(
|
|
932
|
+
protected _extractKey(keyNodeOrEntry: BTNRep<K, V, BinaryTreeNode<K, V>>): K | null | undefined;
|
|
867
933
|
/**
|
|
868
934
|
* Time Complexity: O(1)
|
|
869
935
|
* Space Complexity: O(1)
|