deque-typed 1.48.2 → 1.48.4
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/data-structures/binary-tree/avl-tree.d.ts +16 -16
- package/dist/data-structures/binary-tree/avl-tree.js +7 -7
- package/dist/data-structures/binary-tree/binary-tree.d.ts +89 -87
- package/dist/data-structures/binary-tree/binary-tree.js +67 -58
- package/dist/data-structures/binary-tree/bst.d.ts +28 -47
- package/dist/data-structures/binary-tree/bst.js +54 -57
- package/dist/data-structures/binary-tree/rb-tree.d.ts +15 -15
- package/dist/data-structures/binary-tree/rb-tree.js +7 -7
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +22 -22
- package/dist/data-structures/binary-tree/tree-multimap.js +11 -11
- package/dist/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/data-structures/graph/abstract-graph.js +4 -0
- package/dist/data-structures/graph/directed-graph.d.ts +25 -7
- package/dist/data-structures/graph/directed-graph.js +58 -12
- package/dist/data-structures/graph/undirected-graph.d.ts +25 -6
- package/dist/data-structures/graph/undirected-graph.js +70 -7
- package/dist/interfaces/binary-tree.d.ts +6 -6
- package/dist/types/common.d.ts +11 -8
- package/dist/types/common.js +6 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +20 -21
- package/src/data-structures/binary-tree/binary-tree.ts +147 -136
- package/src/data-structures/binary-tree/bst.ts +86 -82
- package/src/data-structures/binary-tree/rb-tree.ts +25 -26
- package/src/data-structures/binary-tree/tree-multimap.ts +30 -35
- package/src/data-structures/graph/abstract-graph.ts +5 -0
- package/src/data-structures/graph/directed-graph.ts +61 -12
- package/src/data-structures/graph/undirected-graph.ts +75 -7
- package/src/interfaces/binary-tree.ts +5 -6
- package/src/types/common.ts +11 -8
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +6 -5
- package/src/types/data-structures/binary-tree/bst.ts +6 -6
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/tree-multimap.ts +3 -3
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
|
-
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BiTreeDeleteResult, BSTNodeKeyOrNode,
|
|
9
|
+
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BiTreeDeleteResult, BSTNodeKeyOrNode, BTNodeExemplar } from '../../types';
|
|
10
10
|
import { BTNCallback } from '../../types';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
|
-
export declare class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
|
|
12
|
+
export declare class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, N> {
|
|
13
13
|
height: number;
|
|
14
|
-
constructor(key:
|
|
14
|
+
constructor(key: K, value?: V);
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* 1. Height-Balanced: Each node's left and right subtrees differ in height by no more than one.
|
|
@@ -23,27 +23,27 @@ export declare class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeN
|
|
|
23
23
|
* 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
|
|
24
24
|
* 8. Memory Overhead: Stores balance factors (or heights) at each node, leading to slightly higher memory usage compared to a regular BST.
|
|
25
25
|
*/
|
|
26
|
-
export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>, TREE extends AVLTree<V, N, TREE> = AVLTree<V, N, AVLTreeNested<V, N>>> extends BST<V, N, TREE> implements IBinaryTree<V, N, TREE> {
|
|
26
|
+
export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, N, TREE> = AVLTree<K, V, N, AVLTreeNested<K, V, N>>> extends BST<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
|
|
27
27
|
/**
|
|
28
28
|
* The constructor function initializes an AVLTree object with optional elements and options.
|
|
29
|
-
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<V, N>`
|
|
29
|
+
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<K, V, N>`
|
|
30
30
|
* objects. It represents a collection of elements that will be added to the AVL tree during
|
|
31
31
|
* initialization.
|
|
32
32
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
33
33
|
* behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
|
|
34
34
|
* provide only a subset of the properties defined in the `AVLTreeOptions` interface.
|
|
35
35
|
*/
|
|
36
|
-
constructor(elements?: Iterable<BTNodeExemplar<V, N>>, options?: Partial<AVLTreeOptions
|
|
36
|
+
constructor(elements?: Iterable<BTNodeExemplar<K, V, N>>, options?: Partial<AVLTreeOptions<K>>);
|
|
37
37
|
/**
|
|
38
38
|
* The function creates a new AVL tree node with the specified key and value.
|
|
39
|
-
* @param {
|
|
39
|
+
* @param {K} key - The key parameter is the key value that will be associated with
|
|
40
40
|
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
41
41
|
* @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
|
|
42
42
|
* type `V`, which means it can be any value that is assignable to the `value` property of the
|
|
43
43
|
* node type `N`.
|
|
44
44
|
* @returns a new AVLTreeNode object with the specified key and value.
|
|
45
45
|
*/
|
|
46
|
-
createNode(key:
|
|
46
|
+
createNode(key: K, value?: V): N;
|
|
47
47
|
/**
|
|
48
48
|
* The function creates a new AVL tree with the specified options and returns it.
|
|
49
49
|
* @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be
|
|
@@ -51,13 +51,13 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
51
51
|
* being created.
|
|
52
52
|
* @returns a new AVLTree object.
|
|
53
53
|
*/
|
|
54
|
-
createTree(options?: AVLTreeOptions): TREE;
|
|
54
|
+
createTree(options?: AVLTreeOptions<K>): TREE;
|
|
55
55
|
/**
|
|
56
56
|
* The function checks if an exemplar is an instance of AVLTreeNode.
|
|
57
|
-
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`.
|
|
57
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
|
|
58
58
|
* @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
|
|
59
59
|
*/
|
|
60
|
-
isNode(exemplar: BTNodeExemplar<V, N>): exemplar is N;
|
|
60
|
+
isNode(exemplar: BTNodeExemplar<K, V, N>): exemplar is N;
|
|
61
61
|
/**
|
|
62
62
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
63
63
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -72,7 +72,7 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
72
72
|
* entry.
|
|
73
73
|
* @returns The method is returning either the inserted node or `undefined`.
|
|
74
74
|
*/
|
|
75
|
-
add(keyOrNodeOrEntry: BTNodeExemplar<V, N>): N | undefined;
|
|
75
|
+
add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>): N | undefined;
|
|
76
76
|
/**
|
|
77
77
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
78
78
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -96,14 +96,14 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
96
96
|
/**
|
|
97
97
|
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
|
|
98
98
|
* tree.
|
|
99
|
-
* @param {
|
|
100
|
-
* needs to be swapped with the destination node. It can be of type `
|
|
101
|
-
* @param {
|
|
99
|
+
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node that
|
|
100
|
+
* needs to be swapped with the destination node. It can be of type `K`, `N`, or `undefined`.
|
|
101
|
+
* @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
|
|
102
102
|
* node where the values from the source node will be swapped to.
|
|
103
103
|
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
104
104
|
* if either `srcNode` or `destNode` is undefined.
|
|
105
105
|
*/
|
|
106
|
-
protected _swapProperties(srcNode: BSTNodeKeyOrNode<N>, destNode: BSTNodeKeyOrNode<N>): N | undefined;
|
|
106
|
+
protected _swapProperties(srcNode: BSTNodeKeyOrNode<K, N>, destNode: BSTNodeKeyOrNode<K, N>): N | undefined;
|
|
107
107
|
/**
|
|
108
108
|
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
109
109
|
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
@@ -29,7 +29,7 @@ exports.AVLTreeNode = AVLTreeNode;
|
|
|
29
29
|
class AVLTree extends bst_1.BST {
|
|
30
30
|
/**
|
|
31
31
|
* The constructor function initializes an AVLTree object with optional elements and options.
|
|
32
|
-
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<V, N>`
|
|
32
|
+
* @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<K, V, N>`
|
|
33
33
|
* objects. It represents a collection of elements that will be added to the AVL tree during
|
|
34
34
|
* initialization.
|
|
35
35
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
@@ -43,7 +43,7 @@ class AVLTree extends bst_1.BST {
|
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* The function creates a new AVL tree node with the specified key and value.
|
|
46
|
-
* @param {
|
|
46
|
+
* @param {K} key - The key parameter is the key value that will be associated with
|
|
47
47
|
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
48
48
|
* @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
|
|
49
49
|
* type `V`, which means it can be any value that is assignable to the `value` property of the
|
|
@@ -61,11 +61,11 @@ class AVLTree extends bst_1.BST {
|
|
|
61
61
|
* @returns a new AVLTree object.
|
|
62
62
|
*/
|
|
63
63
|
createTree(options) {
|
|
64
|
-
return new AVLTree([], Object.assign({ iterationType: this.iterationType,
|
|
64
|
+
return new AVLTree([], Object.assign({ iterationType: this.iterationType, variant: this.variant }, options));
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* The function checks if an exemplar is an instance of AVLTreeNode.
|
|
68
|
-
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`.
|
|
68
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
|
|
69
69
|
* @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
|
|
70
70
|
*/
|
|
71
71
|
isNode(exemplar) {
|
|
@@ -126,9 +126,9 @@ class AVLTree extends bst_1.BST {
|
|
|
126
126
|
/**
|
|
127
127
|
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
|
|
128
128
|
* tree.
|
|
129
|
-
* @param {
|
|
130
|
-
* needs to be swapped with the destination node. It can be of type `
|
|
131
|
-
* @param {
|
|
129
|
+
* @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node that
|
|
130
|
+
* needs to be swapped with the destination node. It can be of type `K`, `N`, or `undefined`.
|
|
131
|
+
* @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
|
|
132
132
|
* node where the values from the source node will be swapped to.
|
|
133
133
|
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
134
134
|
* if either `srcNode` or `destNode` is undefined.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback,
|
|
8
|
+
import type { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNodeEntry, BTNodeExemplar, BTNodeKeyOrNode } from '../../types';
|
|
9
9
|
import { BinaryTreeNested, BinaryTreePrintOptions, BiTreeDeleteResult, DFSOrderPattern, FamilyPosition, IterationType, NodeDisplayLayout, PairCallback } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { IterablePairBase } from "../base";
|
|
@@ -14,11 +14,11 @@ import { IterablePairBase } from "../base";
|
|
|
14
14
|
* @template V - The type of data stored in the node.
|
|
15
15
|
* @template N - The type of the family relationship in the binary tree.
|
|
16
16
|
*/
|
|
17
|
-
export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>> {
|
|
18
|
-
key:
|
|
17
|
+
export declare class BinaryTreeNode<K = any, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>> {
|
|
18
|
+
key: K;
|
|
19
19
|
value?: V;
|
|
20
20
|
parent?: N;
|
|
21
|
-
constructor(key:
|
|
21
|
+
constructor(key: K, value?: V);
|
|
22
22
|
protected _left?: N | null;
|
|
23
23
|
get left(): N | null | undefined;
|
|
24
24
|
set left(v: N | null | undefined);
|
|
@@ -42,7 +42,7 @@ export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = Bi
|
|
|
42
42
|
* 8. Full Trees: Every node has either 0 or 2 children.
|
|
43
43
|
* 9. Complete Trees: All levels are fully filled except possibly the last, filled from left to right.
|
|
44
44
|
*/
|
|
45
|
-
export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>, TREE extends BinaryTree<V, N, TREE> = BinaryTree<V, N, BinaryTreeNested<V, N>>> extends IterablePairBase<
|
|
45
|
+
export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, N, TREE> = BinaryTree<K, V, N, BinaryTreeNested<K, V, N>>> extends IterablePairBase<K, V | undefined> implements IBinaryTree<K, V, N, TREE> {
|
|
46
46
|
iterationType: IterationType;
|
|
47
47
|
/**
|
|
48
48
|
* The constructor function initializes a binary tree object with optional elements and options.
|
|
@@ -53,18 +53,20 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
53
53
|
* `Partial<BinaryTreeOptions>`, which means that not all properties of `BinaryTreeOptions` are
|
|
54
54
|
* required.
|
|
55
55
|
*/
|
|
56
|
-
constructor(elements?: Iterable<BTNodeExemplar<V, N>>, options?: Partial<BinaryTreeOptions
|
|
56
|
+
constructor(elements?: Iterable<BTNodeExemplar<K, V, N>>, options?: Partial<BinaryTreeOptions<K>>);
|
|
57
|
+
protected _extractor: (key: K) => number;
|
|
58
|
+
get extractor(): (key: K) => number;
|
|
57
59
|
protected _root?: N | null;
|
|
58
60
|
get root(): N | null | undefined;
|
|
59
61
|
protected _size: number;
|
|
60
62
|
get size(): number;
|
|
61
63
|
/**
|
|
62
64
|
* Creates a new instance of BinaryTreeNode with the given key and value.
|
|
63
|
-
* @param {
|
|
65
|
+
* @param {K} key - The key for the new node.
|
|
64
66
|
* @param {V} value - The value for the new node.
|
|
65
67
|
* @returns {N} - The newly created BinaryTreeNode.
|
|
66
68
|
*/
|
|
67
|
-
createNode(key:
|
|
69
|
+
createNode(key: K, value?: V): N;
|
|
68
70
|
/**
|
|
69
71
|
* The function creates a binary tree with the given options.
|
|
70
72
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
@@ -72,28 +74,28 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
72
74
|
* you can provide only a subset of the properties defined in the `BinaryTreeOptions` interface.
|
|
73
75
|
* @returns a new instance of a binary tree.
|
|
74
76
|
*/
|
|
75
|
-
createTree(options?: Partial<BinaryTreeOptions
|
|
77
|
+
createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
|
|
76
78
|
/**
|
|
77
79
|
* The function "isNode" checks if an exemplar is an instance of the BinaryTreeNode class.
|
|
78
|
-
* @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<V,
|
|
80
|
+
* @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<K, V,N>`.
|
|
79
81
|
* @returns a boolean value indicating whether the exemplar is an instance of the class N.
|
|
80
82
|
*/
|
|
81
|
-
isNode(exemplar: BTNodeExemplar<V, N>): exemplar is N;
|
|
83
|
+
isNode(exemplar: BTNodeExemplar<K, V, N>): exemplar is N;
|
|
82
84
|
/**
|
|
83
85
|
* The function `exemplarToNode` converts an exemplar of a binary tree node into an actual node
|
|
84
86
|
* object.
|
|
85
|
-
* @param exemplar - BTNodeExemplar<V,
|
|
87
|
+
* @param exemplar - BTNodeExemplar<K, V,N> - A generic type representing the exemplar parameter of the
|
|
86
88
|
* function. It can be any type.
|
|
87
89
|
* @returns a value of type `N` (which represents a node), or `null`, or `undefined`.
|
|
88
90
|
*/
|
|
89
|
-
exemplarToNode(exemplar: BTNodeExemplar<V, N>): N | null | undefined;
|
|
91
|
+
exemplarToNode(exemplar: BTNodeExemplar<K, V, N>): N | null | undefined;
|
|
90
92
|
/**
|
|
91
93
|
* The function checks if a given value is an entry in a binary tree node.
|
|
92
|
-
* @param kne - BTNodeExemplar<V,
|
|
94
|
+
* @param kne - BTNodeExemplar<K, V,N> - A generic type representing a node in a binary tree. It has
|
|
93
95
|
* two type parameters V and N, representing the value and node type respectively.
|
|
94
96
|
* @returns a boolean value.
|
|
95
97
|
*/
|
|
96
|
-
isEntry(kne: BTNodeExemplar<V, N>): kne is BTNodeEntry<V>;
|
|
98
|
+
isEntry(kne: BTNodeExemplar<K, V, N>): kne is BTNodeEntry<K, V>;
|
|
97
99
|
/**
|
|
98
100
|
* Time Complexity O(log n) - O(n)
|
|
99
101
|
* Space Complexity O(1)
|
|
@@ -106,7 +108,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
106
108
|
* @param keyOrNodeOrEntry - The parameter `keyOrNodeOrEntry` can be one of the following:
|
|
107
109
|
* @returns The function `add` returns the inserted node (`N`), `null`, or `undefined`.
|
|
108
110
|
*/
|
|
109
|
-
add(keyOrNodeOrEntry: BTNodeExemplar<V, N>): N | null | undefined;
|
|
111
|
+
add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>): N | null | undefined;
|
|
110
112
|
/**
|
|
111
113
|
* Time Complexity: O(k log n) - O(k * n)
|
|
112
114
|
* Space Complexity: O(1)
|
|
@@ -119,11 +121,11 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
119
121
|
* The function `addMany` takes in an iterable of `BTNodeExemplar` objects, adds each object to the
|
|
120
122
|
* current instance, and returns an array of the inserted nodes.
|
|
121
123
|
* @param nodes - The `nodes` parameter is an iterable (such as an array or a set) of
|
|
122
|
-
* `BTNodeExemplar<V,
|
|
124
|
+
* `BTNodeExemplar<K, V,N>` objects.
|
|
123
125
|
* @returns The function `addMany` returns an array of values, where each value is either of type
|
|
124
126
|
* `N`, `null`, or `undefined`.
|
|
125
127
|
*/
|
|
126
|
-
addMany(nodes: Iterable<BTNodeExemplar<V, N>>): (N | null | undefined)[];
|
|
128
|
+
addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>): (N | null | undefined)[];
|
|
127
129
|
/**
|
|
128
130
|
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
129
131
|
* Space Complexity: O(1)
|
|
@@ -136,12 +138,12 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
136
138
|
* @param nodesOrKeysOrEntries - The parameter `nodesOrKeysOrEntries` is an iterable object that can
|
|
137
139
|
* contain either `BTNodeExemplar` objects, keys, or entries.
|
|
138
140
|
*/
|
|
139
|
-
refill(nodesOrKeysOrEntries: Iterable<BTNodeExemplar<V, N>>): void;
|
|
141
|
+
refill(nodesOrKeysOrEntries: Iterable<BTNodeExemplar<K, V, N>>): void;
|
|
140
142
|
/**
|
|
141
143
|
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
142
144
|
* Space Complexity: O(1)
|
|
143
145
|
*/
|
|
144
|
-
delete<C extends BTNCallback<N,
|
|
146
|
+
delete<C extends BTNCallback<N, K>>(identifier: K, callback?: C): BiTreeDeleteResult<N>[];
|
|
145
147
|
delete<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C): BiTreeDeleteResult<N>[];
|
|
146
148
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C): BiTreeDeleteResult<N>[];
|
|
147
149
|
/**
|
|
@@ -153,15 +155,15 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
153
155
|
* Space Complexity: O(1)
|
|
154
156
|
*
|
|
155
157
|
* The function calculates the depth of a given node in a binary tree.
|
|
156
|
-
* @param {
|
|
157
|
-
* the binary tree whose depth we want to find. It can be of type `
|
|
158
|
+
* @param {K | N | null | undefined} distNode - The `distNode` parameter represents the node in
|
|
159
|
+
* the binary tree whose depth we want to find. It can be of type `K`, `N`, `null`, or
|
|
158
160
|
* `undefined`.
|
|
159
|
-
* @param {
|
|
160
|
-
* from which we want to calculate the depth. It can be either a `
|
|
161
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
|
|
162
|
+
* from which we want to calculate the depth. It can be either a `K` (binary tree node key) or
|
|
161
163
|
* `N` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
|
|
162
164
|
* @returns the depth of the `distNode` relative to the `beginRoot`.
|
|
163
165
|
*/
|
|
164
|
-
getDepth(distNode: BTNodeKeyOrNode<N>, beginRoot?: BTNodeKeyOrNode<N>): number;
|
|
166
|
+
getDepth(distNode: BTNodeKeyOrNode<K, N>, beginRoot?: BTNodeKeyOrNode<K, N>): number;
|
|
165
167
|
/**
|
|
166
168
|
* Time Complexity: O(n)
|
|
167
169
|
* Space Complexity: O(1)
|
|
@@ -172,15 +174,15 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
172
174
|
*
|
|
173
175
|
* The function `getHeight` calculates the maximum height of a binary tree using either recursive or
|
|
174
176
|
* iterative traversal.
|
|
175
|
-
* @param {
|
|
177
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
176
178
|
* starting node of the binary tree from which we want to calculate the height. It can be of type
|
|
177
|
-
* `
|
|
179
|
+
* `K`, `N`, `null`, or `undefined`. If not provided, it defaults to `this.root`.
|
|
178
180
|
* @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
|
|
179
181
|
* height of the tree using a recursive approach or an iterative approach. It can have two possible
|
|
180
182
|
* values:
|
|
181
183
|
* @returns the height of the binary tree.
|
|
182
184
|
*/
|
|
183
|
-
getHeight(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): number;
|
|
185
|
+
getHeight(beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): number;
|
|
184
186
|
/**
|
|
185
187
|
* Time Complexity: O(n)
|
|
186
188
|
* Space Complexity: O(log n)
|
|
@@ -192,14 +194,14 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
192
194
|
*
|
|
193
195
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
194
196
|
* recursive or iterative approach.
|
|
195
|
-
* @param {
|
|
197
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
196
198
|
* starting node of the binary tree from which we want to calculate the minimum height. It can be of
|
|
197
|
-
* type `
|
|
199
|
+
* type `K`, `N`, `null`, or `undefined`. If no value is provided, it defaults to `this.root`.
|
|
198
200
|
* @param iterationType - The `iterationType` parameter is used to determine the method of iteration
|
|
199
201
|
* to calculate the minimum height of a binary tree. It can have two possible values:
|
|
200
202
|
* @returns The function `getMinHeight` returns the minimum height of a binary tree.
|
|
201
203
|
*/
|
|
202
|
-
getMinHeight(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): number;
|
|
204
|
+
getMinHeight(beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): number;
|
|
203
205
|
/**
|
|
204
206
|
* Time Complexity: O(n)
|
|
205
207
|
* Space Complexity: O(log n)
|
|
@@ -211,33 +213,33 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
211
213
|
*
|
|
212
214
|
* The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
|
|
213
215
|
* height of the tree.
|
|
214
|
-
* @param {
|
|
215
|
-
* for calculating the height and minimum height of a binary tree. It can be either a `
|
|
216
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
|
|
217
|
+
* for calculating the height and minimum height of a binary tree. It can be either a `K` (a key
|
|
216
218
|
* value of a binary tree node), `N` (a node of a binary tree), `null`, or `undefined`. If
|
|
217
219
|
* @returns a boolean value.
|
|
218
220
|
*/
|
|
219
|
-
isPerfectlyBalanced(beginRoot?: BTNodeKeyOrNode<N>): boolean;
|
|
221
|
+
isPerfectlyBalanced(beginRoot?: BTNodeKeyOrNode<K, N>): boolean;
|
|
220
222
|
/**
|
|
221
223
|
* Time Complexity: O(n)
|
|
222
224
|
* Space Complexity: O(log n)
|
|
223
225
|
*/
|
|
224
|
-
getNodes<C extends BTNCallback<N,
|
|
225
|
-
getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N[];
|
|
226
|
-
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N[];
|
|
226
|
+
getNodes<C extends BTNCallback<N, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N[];
|
|
227
|
+
getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N[];
|
|
228
|
+
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N[];
|
|
227
229
|
/**
|
|
228
230
|
* Time Complexity: O(n)
|
|
229
231
|
* Space Complexity: O(log n).
|
|
230
232
|
*/
|
|
231
|
-
has<C extends BTNCallback<N,
|
|
232
|
-
has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): boolean;
|
|
233
|
-
has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): boolean;
|
|
233
|
+
has<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): boolean;
|
|
234
|
+
has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): boolean;
|
|
235
|
+
has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): boolean;
|
|
234
236
|
/**
|
|
235
237
|
* Time Complexity: O(n)
|
|
236
238
|
* Space Complexity: O(log n).
|
|
237
239
|
*/
|
|
238
|
-
getNode<C extends BTNCallback<N,
|
|
239
|
-
getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
|
|
240
|
-
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
|
|
240
|
+
getNode<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
241
|
+
getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
242
|
+
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
241
243
|
/**
|
|
242
244
|
* Time Complexity: O(n)
|
|
243
245
|
* Space Complexity: O(log n)
|
|
@@ -248,7 +250,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
248
250
|
*
|
|
249
251
|
* The function `getNodeByKey` searches for a node in a binary tree by its key, using either
|
|
250
252
|
* recursive or iterative iteration.
|
|
251
|
-
* @param {
|
|
253
|
+
* @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
|
|
252
254
|
* It is used to find the node with the matching key value.
|
|
253
255
|
* @param iterationType - The `iterationType` parameter is used to determine whether the search for
|
|
254
256
|
* the node with the given key should be performed iteratively or recursively. It has two possible
|
|
@@ -256,7 +258,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
256
258
|
* @returns The function `getNodeByKey` returns a node (`N`) if a node with the specified key is
|
|
257
259
|
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
258
260
|
*/
|
|
259
|
-
getNodeByKey(key:
|
|
261
|
+
getNodeByKey(key: K, iterationType?: IterationType): N | undefined;
|
|
260
262
|
/**
|
|
261
263
|
* Time Complexity: O(n)
|
|
262
264
|
* Space Complexity: O(log n)
|
|
@@ -264,7 +266,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
264
266
|
/**
|
|
265
267
|
* The function `ensureNode` returns the node corresponding to the given key if it is a valid node
|
|
266
268
|
* key, otherwise it returns the key itself.
|
|
267
|
-
* @param {
|
|
269
|
+
* @param {K | N | null | undefined} key - The `key` parameter can be of type `K`, `N`,
|
|
268
270
|
* `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
|
|
269
271
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
270
272
|
* type of iteration to be used when searching for a node by key. It has a default value of
|
|
@@ -272,10 +274,10 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
272
274
|
* @returns either the node corresponding to the given key if it is a valid node key, or the key
|
|
273
275
|
* itself if it is not a valid node key.
|
|
274
276
|
*/
|
|
275
|
-
ensureNode(key: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
|
|
276
|
-
get<C extends BTNCallback<N,
|
|
277
|
-
get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): V | undefined;
|
|
278
|
-
get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): V | undefined;
|
|
277
|
+
ensureNode(key: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
278
|
+
get<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
|
|
279
|
+
get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
|
|
280
|
+
get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
|
|
279
281
|
/**
|
|
280
282
|
* Time Complexity: O(n)
|
|
281
283
|
* Space Complexity: O(log n)
|
|
@@ -295,15 +297,15 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
295
297
|
*
|
|
296
298
|
* The function `getPathToRoot` returns an array of nodes from a given node to the root of a tree
|
|
297
299
|
* structure, with the option to reverse the order of the nodes.
|
|
298
|
-
* @param {
|
|
299
|
-
* starting node from which you want to find the path to the root. It can be of type `
|
|
300
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
301
|
+
* starting node from which you want to find the path to the root. It can be of type `K`, `N`,
|
|
300
302
|
* `null`, or `undefined`.
|
|
301
303
|
* @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
|
|
302
304
|
* resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
|
|
303
305
|
* reversed before returning it. If `isReverse` is set to `false`, the path will be returned as is
|
|
304
306
|
* @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
|
|
305
307
|
*/
|
|
306
|
-
getPathToRoot(beginRoot: BTNodeKeyOrNode<N>, isReverse?: boolean): N[];
|
|
308
|
+
getPathToRoot(beginRoot: BTNodeKeyOrNode<K, N>, isReverse?: boolean): N[];
|
|
307
309
|
/**
|
|
308
310
|
* Time Complexity: O(log n)
|
|
309
311
|
* Space Complexity: O(log n)
|
|
@@ -314,15 +316,15 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
314
316
|
*
|
|
315
317
|
* The function `getLeftMost` returns the leftmost node in a binary tree, either recursively or
|
|
316
318
|
* iteratively.
|
|
317
|
-
* @param {
|
|
318
|
-
* for finding the leftmost node in a binary tree. It can be either a `
|
|
319
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
|
|
320
|
+
* for finding the leftmost node in a binary tree. It can be either a `K` (a key value), `N` (a
|
|
319
321
|
* node), `null`, or `undefined`. If not provided, it defaults to `this.root`,
|
|
320
322
|
* @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
|
|
321
323
|
* be performed when finding the leftmost node in a binary tree. It can have two possible values:
|
|
322
324
|
* @returns The function `getLeftMost` returns the leftmost node (`N`) in the binary tree. If there
|
|
323
325
|
* is no leftmost node, it returns `null` or `undefined` depending on the input.
|
|
324
326
|
*/
|
|
325
|
-
getLeftMost(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
|
|
327
|
+
getLeftMost(beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
326
328
|
/**
|
|
327
329
|
* Time Complexity: O(log n)
|
|
328
330
|
* Space Complexity: O(1)
|
|
@@ -333,8 +335,8 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
333
335
|
*
|
|
334
336
|
* The function `getRightMost` returns the rightmost node in a binary tree, either recursively or
|
|
335
337
|
* iteratively.
|
|
336
|
-
* @param {
|
|
337
|
-
* starting node from which we want to find the rightmost node. It can be of type `
|
|
338
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
|
|
339
|
+
* starting node from which we want to find the rightmost node. It can be of type `K`, `N`,
|
|
338
340
|
* `null`, or `undefined`. If not provided, it defaults to `this.root`, which is a property of the
|
|
339
341
|
* current object.
|
|
340
342
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
@@ -342,7 +344,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
342
344
|
* @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If there
|
|
343
345
|
* is no rightmost node, it returns `null` or `undefined`, depending on the input.
|
|
344
346
|
*/
|
|
345
|
-
getRightMost(beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType): N | null | undefined;
|
|
347
|
+
getRightMost(beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
346
348
|
/**
|
|
347
349
|
* Time Complexity: O(log n)
|
|
348
350
|
* Space Complexity: O(1)
|
|
@@ -352,14 +354,14 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
352
354
|
* Space Complexity: O(1)
|
|
353
355
|
*
|
|
354
356
|
* The function `isSubtreeBST` checks if a given binary tree is a valid binary search tree.
|
|
355
|
-
* @param {
|
|
357
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the root
|
|
356
358
|
* node of the binary search tree (BST) that you want to check if it is a subtree of another BST.
|
|
357
359
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
358
360
|
* type of iteration to use when checking if a subtree is a binary search tree (BST). It can have two
|
|
359
361
|
* possible values:
|
|
360
362
|
* @returns a boolean value.
|
|
361
363
|
*/
|
|
362
|
-
isSubtreeBST(beginRoot: BTNodeKeyOrNode<N>, iterationType?: IterationType): boolean;
|
|
364
|
+
isSubtreeBST(beginRoot: BTNodeKeyOrNode<K, N>, iterationType?: IterationType): boolean;
|
|
363
365
|
/**
|
|
364
366
|
* Time Complexity: O(n)
|
|
365
367
|
* Space Complexity: O(1)
|
|
@@ -380,9 +382,9 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
380
382
|
* Time Complexity: O(n)
|
|
381
383
|
* Space Complexity: O(1)
|
|
382
384
|
*/
|
|
383
|
-
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
384
|
-
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
385
|
-
subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
385
|
+
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
386
|
+
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
387
|
+
subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
386
388
|
/**
|
|
387
389
|
* Time complexity: O(n)
|
|
388
390
|
* Space complexity: O(log n)
|
|
@@ -407,29 +409,29 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
407
409
|
*/
|
|
408
410
|
isNodeOrNull(node: any): node is N | null;
|
|
409
411
|
/**
|
|
410
|
-
* The function "
|
|
412
|
+
* The function "isNotNodeInstance" checks if a potential key is a number.
|
|
411
413
|
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
412
414
|
* data type.
|
|
413
415
|
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
414
416
|
*/
|
|
415
|
-
|
|
416
|
-
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
417
|
-
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
418
|
-
dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
417
|
+
isNotNodeInstance(potentialKey: BTNodeKeyOrNode<K, N>): potentialKey is K;
|
|
418
|
+
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
419
|
+
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
420
|
+
dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
419
421
|
/**
|
|
420
422
|
* Time complexity: O(n)
|
|
421
423
|
* Space complexity: O(n)
|
|
422
424
|
*/
|
|
423
|
-
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
424
|
-
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
425
|
-
bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
425
|
+
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
426
|
+
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
427
|
+
bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
426
428
|
/**
|
|
427
429
|
* Time complexity: O(n)
|
|
428
430
|
* Space complexity: O(n)
|
|
429
431
|
*/
|
|
430
|
-
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
431
|
-
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
|
|
432
|
-
listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
432
|
+
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
433
|
+
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
|
|
434
|
+
listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNodeKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
433
435
|
/**
|
|
434
436
|
* Time complexity: O(n)
|
|
435
437
|
* Space complexity: O(n)
|
|
@@ -437,11 +439,11 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
437
439
|
getPredecessor(node: N): N;
|
|
438
440
|
/**
|
|
439
441
|
* The function `getSuccessor` returns the next node in a binary tree given a current node.
|
|
440
|
-
* @param {
|
|
442
|
+
* @param {K | N | null} [x] - The parameter `x` can be of type `K`, `N`, or `null`.
|
|
441
443
|
* @returns the successor of the given node or key. The successor is the node that comes immediately
|
|
442
444
|
* after the given node in the inorder traversal of the binary tree.
|
|
443
445
|
*/
|
|
444
|
-
getSuccessor(x?:
|
|
446
|
+
getSuccessor(x?: K | N | null): N | null | undefined;
|
|
445
447
|
/**
|
|
446
448
|
* Time complexity: O(n)
|
|
447
449
|
* Space complexity: O(1)
|
|
@@ -453,14 +455,14 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
453
455
|
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
|
|
454
456
|
* determines the order in which the nodes of a binary tree are traversed. It can have one of the
|
|
455
457
|
* following values:
|
|
456
|
-
* @param {
|
|
458
|
+
* @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
|
|
457
459
|
* for the traversal. It can be specified as a key, a node object, or `null`/`undefined` to indicate
|
|
458
460
|
* the root of the tree. If no value is provided, the default value is the root of the tree.
|
|
459
461
|
* @returns The function `morris` returns an array of values that are the result of invoking the
|
|
460
462
|
* `callback` function on each node in the binary tree. The type of the array elements is determined
|
|
461
463
|
* by the return type of the `callback` function.
|
|
462
464
|
*/
|
|
463
|
-
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<N>): ReturnType<C>[];
|
|
465
|
+
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNodeKeyOrNode<K, N>): ReturnType<C>[];
|
|
464
466
|
/**
|
|
465
467
|
* Time complexity: O(n)
|
|
466
468
|
* Space complexity: O(n)
|
|
@@ -493,7 +495,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
493
495
|
* @returns The `filter` method is returning a new tree object that contains the key-value pairs that
|
|
494
496
|
* pass the given predicate function.
|
|
495
497
|
*/
|
|
496
|
-
filter(predicate: PairCallback<
|
|
498
|
+
filter(predicate: PairCallback<K, V | undefined, boolean>, thisArg?: any): TREE;
|
|
497
499
|
/**
|
|
498
500
|
* Time Complexity: O(n)
|
|
499
501
|
* Space Complexity: O(n)
|
|
@@ -513,25 +515,25 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
513
515
|
* will be used as the `this` value when the callback function is called. If you don't pass a value
|
|
514
516
|
* @returns The `map` method is returning a new tree object.
|
|
515
517
|
*/
|
|
516
|
-
map(callback: PairCallback<
|
|
518
|
+
map(callback: PairCallback<K, V | undefined, V>, thisArg?: any): TREE;
|
|
517
519
|
/**
|
|
518
520
|
* The `print` function is used to display a binary tree structure in a visually appealing way.
|
|
519
|
-
* @param {
|
|
521
|
+
* @param {K | N | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `K | N | null |
|
|
520
522
|
* undefined`. It represents the root node of a binary tree. The root node can have one of the
|
|
521
523
|
* following types:
|
|
522
524
|
* @param {BinaryTreePrintOptions} [options={ isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false}] - Options object that controls printing behavior. You can specify whether to display undefined, null, or sentinel nodes.
|
|
523
525
|
*/
|
|
524
|
-
print(beginRoot?: BTNodeKeyOrNode<N>, options?: BinaryTreePrintOptions): void;
|
|
525
|
-
protected _getIterator(node?: N | null | undefined): IterableIterator<[
|
|
526
|
+
print(beginRoot?: BTNodeKeyOrNode<K, N>, options?: BinaryTreePrintOptions): void;
|
|
527
|
+
protected _getIterator(node?: N | null | undefined): IterableIterator<[K, V | undefined]>;
|
|
526
528
|
protected _displayAux(node: N | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
527
|
-
protected _defaultOneParamCallback: (node: N) =>
|
|
529
|
+
protected _defaultOneParamCallback: (node: N) => K;
|
|
528
530
|
/**
|
|
529
531
|
* Swap the data of two nodes in the binary tree.
|
|
530
532
|
* @param {N} srcNode - The source node to swap.
|
|
531
533
|
* @param {N} destNode - The destination node to swap.
|
|
532
534
|
* @returns {N} - The destination node after the swap.
|
|
533
535
|
*/
|
|
534
|
-
protected _swapProperties(srcNode: BTNodeKeyOrNode<N>, destNode: BTNodeKeyOrNode<N>): N | undefined;
|
|
536
|
+
protected _swapProperties(srcNode: BTNodeKeyOrNode<K, N>, destNode: BTNodeKeyOrNode<K, N>): N | undefined;
|
|
535
537
|
/**
|
|
536
538
|
* The function replaces an old node with a new node in a binary tree.
|
|
537
539
|
* @param {N} oldNode - The oldNode parameter represents the node that needs to be replaced in the
|
|
@@ -552,7 +554,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
552
554
|
* the binary tree. If neither the left nor right child is available, the function returns undefined.
|
|
553
555
|
* If the parent node is null, the function also returns undefined.
|
|
554
556
|
*/
|
|
555
|
-
protected _addTo(newNode: N | null | undefined, parent: BTNodeKeyOrNode<N>): N | null | undefined;
|
|
557
|
+
protected _addTo(newNode: N | null | undefined, parent: BTNodeKeyOrNode<K, N>): N | null | undefined;
|
|
556
558
|
/**
|
|
557
559
|
* The function sets the root property of an object to a given value, and if the value is not null,
|
|
558
560
|
* it also sets the parent property of the value to undefined.
|