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