min-heap-typed 1.48.9 → 1.49.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/data-structures/binary-tree/avl-tree.d.ts +16 -11
- package/dist/data-structures/binary-tree/avl-tree.js +12 -4
- package/dist/data-structures/binary-tree/binary-tree.d.ts +70 -61
- package/dist/data-structures/binary-tree/binary-tree.js +25 -21
- package/dist/data-structures/binary-tree/bst.d.ts +20 -13
- package/dist/data-structures/binary-tree/bst.js +12 -3
- package/dist/data-structures/binary-tree/rb-tree.d.ts +19 -25
- package/dist/data-structures/binary-tree/rb-tree.js +21 -35
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +20 -13
- package/dist/data-structures/binary-tree/tree-multimap.js +12 -3
- package/dist/data-structures/graph/abstract-graph.d.ts +9 -3
- package/dist/data-structures/graph/abstract-graph.js +27 -31
- package/dist/data-structures/graph/directed-graph.d.ts +8 -1
- package/dist/data-structures/graph/directed-graph.js +1 -8
- package/dist/data-structures/graph/map-graph.d.ts +1 -1
- package/dist/data-structures/graph/undirected-graph.d.ts +8 -1
- package/dist/data-structures/graph/undirected-graph.js +1 -8
- package/dist/data-structures/hash/hash-map.d.ts +14 -2
- package/dist/data-structures/hash/hash-map.js +19 -8
- package/dist/data-structures/hash/hash-table.d.ts +2 -2
- package/dist/data-structures/heap/heap.d.ts +14 -3
- package/dist/data-structures/heap/heap.js +12 -0
- package/dist/data-structures/heap/max-heap.d.ts +11 -1
- package/dist/data-structures/heap/max-heap.js +10 -7
- package/dist/data-structures/heap/min-heap.d.ts +11 -1
- package/dist/data-structures/heap/min-heap.js +10 -7
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +8 -2
- package/dist/data-structures/linked-list/doubly-linked-list.js +6 -7
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/data-structures/linked-list/singly-linked-list.js +0 -7
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.js +0 -7
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js +0 -7
- package/dist/data-structures/priority-queue/priority-queue.d.ts +9 -1
- package/dist/data-structures/priority-queue/priority-queue.js +8 -7
- package/dist/data-structures/queue/deque.d.ts +6 -5
- package/dist/data-structures/queue/deque.js +6 -12
- package/dist/data-structures/queue/queue.d.ts +18 -3
- package/dist/data-structures/queue/queue.js +16 -6
- package/dist/data-structures/stack/stack.d.ts +15 -5
- package/dist/data-structures/stack/stack.js +7 -4
- package/dist/data-structures/trie/trie.d.ts +13 -3
- package/dist/data-structures/trie/trie.js +11 -8
- package/dist/interfaces/binary-tree.d.ts +4 -4
- package/dist/types/common.d.ts +32 -8
- package/dist/types/common.js +22 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
- package/dist/types/data-structures/binary-tree/binary-tree.js +0 -22
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +23 -13
- package/src/data-structures/binary-tree/binary-tree.ts +93 -97
- package/src/data-structures/binary-tree/bst.ts +26 -15
- package/src/data-structures/binary-tree/rb-tree.ts +33 -48
- package/src/data-structures/binary-tree/tree-multimap.ts +32 -14
- package/src/data-structures/graph/abstract-graph.ts +35 -25
- package/src/data-structures/graph/directed-graph.ts +2 -2
- package/src/data-structures/graph/map-graph.ts +1 -1
- package/src/data-structures/graph/undirected-graph.ts +2 -2
- package/src/data-structures/hash/hash-map.ts +20 -3
- package/src/data-structures/hash/hash-table.ts +3 -3
- package/src/data-structures/heap/heap.ts +14 -3
- package/src/data-structures/heap/max-heap.ts +11 -2
- package/src/data-structures/heap/min-heap.ts +11 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +9 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +3 -3
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/priority-queue.ts +9 -2
- package/src/data-structures/queue/deque.ts +7 -9
- package/src/data-structures/queue/queue.ts +18 -3
- package/src/data-structures/stack/stack.ts +16 -6
- package/src/data-structures/trie/trie.ts +13 -4
- package/src/interfaces/binary-tree.ts +5 -5
- package/src/types/common.ts +37 -12
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -26
- package/src/types/data-structures/binary-tree/bst.ts +0 -1
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
|
-
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions,
|
|
10
|
-
import { BTNCallback } from '../../types';
|
|
9
|
+
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, BTNExemplar, BTNKeyOrNode } from '../../types';
|
|
11
10
|
import { IBinaryTree } from '../../interfaces';
|
|
12
11
|
export declare class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, N> {
|
|
13
12
|
height: number;
|
|
@@ -21,19 +20,18 @@ export declare class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N
|
|
|
21
20
|
* 5. Efficient Lookups: Offers O(log n) search time, where 'n' is the number of nodes, due to its balanced nature.
|
|
22
21
|
* 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
|
|
23
22
|
* 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
|
-
* 8. Memory Overhead: Stores balance factors (or heights) at each node, leading to slightly higher memory usage compared to a regular BST.
|
|
25
23
|
*/
|
|
26
24
|
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
25
|
/**
|
|
28
26
|
* The constructor function initializes an AVLTree object with optional elements and options.
|
|
29
|
-
* @param [elements] - The `elements` parameter is an optional iterable of `
|
|
27
|
+
* @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
|
|
30
28
|
* objects. It represents a collection of elements that will be added to the AVL tree during
|
|
31
29
|
* initialization.
|
|
32
30
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
33
31
|
* behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
|
|
34
32
|
* provide only a subset of the properties defined in the `AVLTreeOptions` interface.
|
|
35
33
|
*/
|
|
36
|
-
constructor(elements?: Iterable<
|
|
34
|
+
constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<AVLTreeOptions<K>>);
|
|
37
35
|
/**
|
|
38
36
|
* The function creates a new AVL tree node with the specified key and value.
|
|
39
37
|
* @param {K} key - The key parameter is the key value that will be associated with
|
|
@@ -54,10 +52,17 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
|
|
|
54
52
|
createTree(options?: AVLTreeOptions<K>): TREE;
|
|
55
53
|
/**
|
|
56
54
|
* The function checks if an exemplar is an instance of AVLTreeNode.
|
|
57
|
-
* @param exemplar - The `exemplar` parameter is of type `
|
|
55
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
|
|
58
56
|
* @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
|
|
59
57
|
*/
|
|
60
|
-
isNode(exemplar:
|
|
58
|
+
isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
|
|
59
|
+
/**
|
|
60
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
61
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
62
|
+
* data type.
|
|
63
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
64
|
+
*/
|
|
65
|
+
isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
|
|
61
66
|
/**
|
|
62
67
|
* 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
68
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -74,7 +79,7 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
|
|
|
74
79
|
* being added to the binary tree.
|
|
75
80
|
* @returns The method is returning either the inserted node or undefined.
|
|
76
81
|
*/
|
|
77
|
-
add(keyOrNodeOrEntry:
|
|
82
|
+
add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | undefined;
|
|
78
83
|
/**
|
|
79
84
|
* 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.
|
|
80
85
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -92,9 +97,9 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
|
|
|
92
97
|
* that is deleted from the binary tree. It is an optional parameter and if not provided, it will
|
|
93
98
|
* default to the `_defaultOneParamCallback` function. The `callback` function should have a single
|
|
94
99
|
* parameter of type `N
|
|
95
|
-
* @returns The method is returning an array of `
|
|
100
|
+
* @returns The method is returning an array of `BinaryTreeDeleteResult<N>`.
|
|
96
101
|
*/
|
|
97
|
-
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C):
|
|
102
|
+
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeleteResult<N>[];
|
|
98
103
|
/**
|
|
99
104
|
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
|
|
100
105
|
* tree.
|
|
@@ -105,7 +110,7 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
|
|
|
105
110
|
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
106
111
|
* if either `srcNode` or `destNode` is undefined.
|
|
107
112
|
*/
|
|
108
|
-
protected _swapProperties(srcNode:
|
|
113
|
+
protected _swapProperties(srcNode: BSTNKeyOrNode<K, N>, destNode: BSTNKeyOrNode<K, N>): N | undefined;
|
|
109
114
|
/**
|
|
110
115
|
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
111
116
|
* Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
|
|
@@ -24,12 +24,11 @@ exports.AVLTreeNode = AVLTreeNode;
|
|
|
24
24
|
* 5. Efficient Lookups: Offers O(log n) search time, where 'n' is the number of nodes, due to its balanced nature.
|
|
25
25
|
* 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
|
|
26
26
|
* 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.
|
|
27
|
-
* 8. Memory Overhead: Stores balance factors (or heights) at each node, leading to slightly higher memory usage compared to a regular BST.
|
|
28
27
|
*/
|
|
29
28
|
class AVLTree extends bst_1.BST {
|
|
30
29
|
/**
|
|
31
30
|
* The constructor function initializes an AVLTree object with optional elements and options.
|
|
32
|
-
* @param [elements] - The `elements` parameter is an optional iterable of `
|
|
31
|
+
* @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
|
|
33
32
|
* objects. It represents a collection of elements that will be added to the AVL tree during
|
|
34
33
|
* initialization.
|
|
35
34
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
@@ -65,12 +64,21 @@ class AVLTree extends bst_1.BST {
|
|
|
65
64
|
}
|
|
66
65
|
/**
|
|
67
66
|
* The function checks if an exemplar is an instance of AVLTreeNode.
|
|
68
|
-
* @param exemplar - The `exemplar` parameter is of type `
|
|
67
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
|
|
69
68
|
* @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
|
|
70
69
|
*/
|
|
71
70
|
isNode(exemplar) {
|
|
72
71
|
return exemplar instanceof AVLTreeNode;
|
|
73
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
75
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
76
|
+
* data type.
|
|
77
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
78
|
+
*/
|
|
79
|
+
isNotNodeInstance(potentialKey) {
|
|
80
|
+
return !(potentialKey instanceof AVLTreeNode);
|
|
81
|
+
}
|
|
74
82
|
/**
|
|
75
83
|
* 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.
|
|
76
84
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -112,7 +120,7 @@ class AVLTree extends bst_1.BST {
|
|
|
112
120
|
* that is deleted from the binary tree. It is an optional parameter and if not provided, it will
|
|
113
121
|
* default to the `_defaultOneParamCallback` function. The `callback` function should have a single
|
|
114
122
|
* parameter of type `N
|
|
115
|
-
* @returns The method is returning an array of `
|
|
123
|
+
* @returns The method is returning an array of `BinaryTreeDeleteResult<N>`.
|
|
116
124
|
*/
|
|
117
125
|
delete(identifier, callback = this._defaultOneParamCallback) {
|
|
118
126
|
if (identifier instanceof AVLTreeNode)
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback,
|
|
9
|
-
import {
|
|
8
|
+
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNCallback, BTNEntry, BTNExemplar, BTNKeyOrNode, DFSOrderPattern, EntryCallback, NodeDisplayLayout } from '../../types';
|
|
9
|
+
import { FamilyPosition, IterationType } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { IterableEntryBase } from "../base";
|
|
12
12
|
/**
|
|
@@ -42,14 +42,14 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
42
42
|
iterationType: IterationType;
|
|
43
43
|
/**
|
|
44
44
|
* The constructor function initializes a binary tree object with optional elements and options.
|
|
45
|
-
* @param [elements] - An optional iterable of
|
|
45
|
+
* @param [elements] - An optional iterable of BTNExemplar objects. These objects represent the
|
|
46
46
|
* elements to be added to the binary tree.
|
|
47
47
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
48
48
|
* configuration options for the binary tree. In this case, it is of type
|
|
49
49
|
* `Partial<BinaryTreeOptions>`, which means that not all properties of `BinaryTreeOptions` are
|
|
50
50
|
* required.
|
|
51
51
|
*/
|
|
52
|
-
constructor(elements?: Iterable<
|
|
52
|
+
constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<BinaryTreeOptions<K>>);
|
|
53
53
|
protected _extractor: (key: K) => number;
|
|
54
54
|
get extractor(): (key: K) => number;
|
|
55
55
|
protected _root?: N | null;
|
|
@@ -73,26 +73,26 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
73
73
|
createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
|
|
74
74
|
/**
|
|
75
75
|
* The function "isNode" checks if an exemplar is an instance of the BinaryTreeNode class.
|
|
76
|
-
* @param exemplar - The `exemplar` parameter is a variable of type `
|
|
76
|
+
* @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V,N>`.
|
|
77
77
|
* @returns a boolean value indicating whether the exemplar is an instance of the class N.
|
|
78
78
|
*/
|
|
79
|
-
isNode(exemplar:
|
|
79
|
+
isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
|
|
80
80
|
/**
|
|
81
81
|
* The function `exemplarToNode` converts an exemplar object into a node object.
|
|
82
|
-
* @param exemplar - The `exemplar` parameter is of type `
|
|
82
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
|
|
83
83
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
84
84
|
* `exemplarToNode` function. It represents the value associated with the exemplar node. If no value
|
|
85
85
|
* is provided, it will be `undefined`.
|
|
86
86
|
* @returns a value of type N (node), or null, or undefined.
|
|
87
87
|
*/
|
|
88
|
-
exemplarToNode(exemplar:
|
|
88
|
+
exemplarToNode(exemplar: BTNExemplar<K, V, N>, value?: V): N | null | undefined;
|
|
89
89
|
/**
|
|
90
90
|
* The function checks if a given value is an entry in a binary tree node.
|
|
91
|
-
* @param kne -
|
|
91
|
+
* @param kne - BTNExemplar<K, V,N> - A generic type representing a node in a binary tree. It has
|
|
92
92
|
* two type parameters V and N, representing the value and node type respectively.
|
|
93
93
|
* @returns a boolean value.
|
|
94
94
|
*/
|
|
95
|
-
isEntry(kne:
|
|
95
|
+
isEntry(kne: BTNExemplar<K, V, N>): kne is BTNEntry<K, V>;
|
|
96
96
|
/**
|
|
97
97
|
* Time Complexity O(log n) - O(n)
|
|
98
98
|
* Space Complexity O(1)
|
|
@@ -107,7 +107,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
107
107
|
* @param {V} [value] - The value to be inserted into the binary tree.
|
|
108
108
|
* @returns The function `add` returns either a node (`N`), `null`, or `undefined`.
|
|
109
109
|
*/
|
|
110
|
-
add(keyOrNodeOrEntry:
|
|
110
|
+
add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | null | undefined;
|
|
111
111
|
/**
|
|
112
112
|
* Time Complexity: O(k log n) - O(k * n)
|
|
113
113
|
* Space Complexity: O(1)
|
|
@@ -119,23 +119,23 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
119
119
|
*
|
|
120
120
|
* The `addMany` function takes in a collection of nodes and an optional collection of values, and
|
|
121
121
|
* adds each node with its corresponding value to the data structure.
|
|
122
|
-
* @param nodes - An iterable collection of
|
|
122
|
+
* @param nodes - An iterable collection of BTNExemplar objects.
|
|
123
123
|
* @param [values] - An optional iterable of values that will be assigned to each node being added.
|
|
124
124
|
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
125
125
|
*/
|
|
126
|
-
addMany(nodes: Iterable<
|
|
126
|
+
addMany(nodes: Iterable<BTNExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
|
|
127
127
|
/**
|
|
128
128
|
* 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
129
|
* Space Complexity: O(1)
|
|
130
130
|
*/
|
|
131
|
-
refill(nodesOrKeysOrEntries: Iterable<
|
|
131
|
+
refill(nodesOrKeysOrEntries: Iterable<BTNExemplar<K, V, N>>, values?: Iterable<V | undefined>): void;
|
|
132
132
|
/**
|
|
133
133
|
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
134
134
|
* Space Complexity: O(1)
|
|
135
135
|
*/
|
|
136
|
-
delete<C extends BTNCallback<N, K>>(identifier: K, callback?: C):
|
|
137
|
-
delete<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C):
|
|
138
|
-
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C):
|
|
136
|
+
delete<C extends BTNCallback<N, K>>(identifier: K, callback?: C): BinaryTreeDeleteResult<N>[];
|
|
137
|
+
delete<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C): BinaryTreeDeleteResult<N>[];
|
|
138
|
+
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C): BinaryTreeDeleteResult<N>[];
|
|
139
139
|
/**
|
|
140
140
|
* Time Complexity: O(n)
|
|
141
141
|
* Space Complexity: O(1)
|
|
@@ -153,7 +153,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
153
153
|
* `N` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
|
|
154
154
|
* @returns the depth of the `distNode` relative to the `beginRoot`.
|
|
155
155
|
*/
|
|
156
|
-
getDepth(distNode:
|
|
156
|
+
getDepth(distNode: BTNKeyOrNode<K, N>, beginRoot?: BTNKeyOrNode<K, N>): number;
|
|
157
157
|
/**
|
|
158
158
|
* Time Complexity: O(n)
|
|
159
159
|
* Space Complexity: O(1)
|
|
@@ -172,7 +172,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
172
172
|
* values:
|
|
173
173
|
* @returns the height of the binary tree.
|
|
174
174
|
*/
|
|
175
|
-
getHeight(beginRoot?:
|
|
175
|
+
getHeight(beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): number;
|
|
176
176
|
/**
|
|
177
177
|
* Time Complexity: O(n)
|
|
178
178
|
* Space Complexity: O(log n)
|
|
@@ -191,7 +191,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
191
191
|
* to calculate the minimum height of a binary tree. It can have two possible values:
|
|
192
192
|
* @returns The function `getMinHeight` returns the minimum height of a binary tree.
|
|
193
193
|
*/
|
|
194
|
-
getMinHeight(beginRoot?:
|
|
194
|
+
getMinHeight(beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): number;
|
|
195
195
|
/**
|
|
196
196
|
* Time Complexity: O(n)
|
|
197
197
|
* Space Complexity: O(log n)
|
|
@@ -208,28 +208,28 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
208
208
|
* value of a binary tree node), `N` (a node of a binary tree), `null`, or `undefined`. If
|
|
209
209
|
* @returns a boolean value.
|
|
210
210
|
*/
|
|
211
|
-
isPerfectlyBalanced(beginRoot?:
|
|
211
|
+
isPerfectlyBalanced(beginRoot?: BTNKeyOrNode<K, N>): boolean;
|
|
212
212
|
/**
|
|
213
213
|
* Time Complexity: O(n)
|
|
214
214
|
* Space Complexity: O(log n)
|
|
215
215
|
*/
|
|
216
|
-
getNodes<C extends BTNCallback<N, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?:
|
|
217
|
-
getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?:
|
|
218
|
-
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?:
|
|
216
|
+
getNodes<C extends BTNCallback<N, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N[];
|
|
217
|
+
getNodes<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N[];
|
|
218
|
+
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N[];
|
|
219
219
|
/**
|
|
220
220
|
* Time Complexity: O(n)
|
|
221
221
|
* Space Complexity: O(log n).
|
|
222
222
|
*/
|
|
223
|
-
has<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?:
|
|
224
|
-
has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?:
|
|
225
|
-
has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?:
|
|
223
|
+
has<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): boolean;
|
|
224
|
+
has<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): boolean;
|
|
225
|
+
has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): boolean;
|
|
226
226
|
/**
|
|
227
227
|
* Time Complexity: O(n)
|
|
228
228
|
* Space Complexity: O(log n).
|
|
229
229
|
*/
|
|
230
|
-
getNode<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?:
|
|
231
|
-
getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?:
|
|
232
|
-
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?:
|
|
230
|
+
getNode<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
231
|
+
getNode<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
232
|
+
getNode<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
233
233
|
/**
|
|
234
234
|
* Time Complexity: O(n)
|
|
235
235
|
* Space Complexity: O(log n)
|
|
@@ -264,10 +264,10 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
264
264
|
* @returns either the node corresponding to the given key if it is a valid node key, or the key
|
|
265
265
|
* itself if it is not a valid node key.
|
|
266
266
|
*/
|
|
267
|
-
ensureNode(key:
|
|
268
|
-
get<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?:
|
|
269
|
-
get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?:
|
|
270
|
-
get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?:
|
|
267
|
+
ensureNode(key: BTNKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
268
|
+
get<C extends BTNCallback<N, K>>(identifier: K, callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
|
|
269
|
+
get<C extends BTNCallback<N, N>>(identifier: N | null | undefined, callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
|
|
270
|
+
get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): V | undefined;
|
|
271
271
|
/**
|
|
272
272
|
* Time Complexity: O(n)
|
|
273
273
|
* Space Complexity: O(log n)
|
|
@@ -295,7 +295,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
295
295
|
* reversed before returning it. If `isReverse` is set to `false`, the path will be returned as is
|
|
296
296
|
* @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
|
|
297
297
|
*/
|
|
298
|
-
getPathToRoot(beginRoot:
|
|
298
|
+
getPathToRoot(beginRoot: BTNKeyOrNode<K, N>, isReverse?: boolean): N[];
|
|
299
299
|
/**
|
|
300
300
|
* Time Complexity: O(log n)
|
|
301
301
|
* Space Complexity: O(log n)
|
|
@@ -314,7 +314,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
314
314
|
* @returns The function `getLeftMost` returns the leftmost node (`N`) in the binary tree. If there
|
|
315
315
|
* is no leftmost node, it returns `null` or `undefined` depending on the input.
|
|
316
316
|
*/
|
|
317
|
-
getLeftMost(beginRoot?:
|
|
317
|
+
getLeftMost(beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
318
318
|
/**
|
|
319
319
|
* Time Complexity: O(log n)
|
|
320
320
|
* Space Complexity: O(1)
|
|
@@ -334,7 +334,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
334
334
|
* @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If there
|
|
335
335
|
* is no rightmost node, it returns `null` or `undefined`, depending on the input.
|
|
336
336
|
*/
|
|
337
|
-
getRightMost(beginRoot?:
|
|
337
|
+
getRightMost(beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType): N | null | undefined;
|
|
338
338
|
/**
|
|
339
339
|
* Time Complexity: O(log n)
|
|
340
340
|
* Space Complexity: O(1)
|
|
@@ -351,7 +351,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
351
351
|
* possible values:
|
|
352
352
|
* @returns a boolean value.
|
|
353
353
|
*/
|
|
354
|
-
isSubtreeBST(beginRoot:
|
|
354
|
+
isSubtreeBST(beginRoot: BTNKeyOrNode<K, N>, iterationType?: IterationType): boolean;
|
|
355
355
|
/**
|
|
356
356
|
* Time Complexity: O(n)
|
|
357
357
|
* Space Complexity: O(1)
|
|
@@ -372,9 +372,9 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
372
372
|
* Time Complexity: O(n)
|
|
373
373
|
* Space Complexity: O(1)
|
|
374
374
|
*/
|
|
375
|
-
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?:
|
|
376
|
-
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?:
|
|
377
|
-
subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?:
|
|
375
|
+
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
376
|
+
subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
377
|
+
subTreeTraverse<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
378
378
|
/**
|
|
379
379
|
* Time complexity: O(n)
|
|
380
380
|
* Space complexity: O(log n)
|
|
@@ -385,46 +385,55 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
385
385
|
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
386
386
|
* @returns a boolean value.
|
|
387
387
|
*/
|
|
388
|
-
isRealNode(node:
|
|
388
|
+
isRealNode(node: BTNExemplar<K, V, N>): node is N;
|
|
389
389
|
/**
|
|
390
390
|
* The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.
|
|
391
391
|
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
392
392
|
* @returns a boolean value.
|
|
393
393
|
*/
|
|
394
|
-
isNIL(node:
|
|
394
|
+
isNIL(node: BTNExemplar<K, V, N>): boolean;
|
|
395
395
|
/**
|
|
396
396
|
* The function checks if a given node is a real node or null.
|
|
397
397
|
* @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
|
|
398
398
|
* @returns a boolean value.
|
|
399
399
|
*/
|
|
400
|
-
isNodeOrNull(node:
|
|
400
|
+
isNodeOrNull(node: BTNExemplar<K, V, N>): node is N | null;
|
|
401
401
|
/**
|
|
402
|
-
* The function "isNotNodeInstance" checks if a potential key is a
|
|
402
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
403
403
|
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
404
404
|
* data type.
|
|
405
405
|
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
406
406
|
*/
|
|
407
|
-
isNotNodeInstance(potentialKey:
|
|
408
|
-
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?:
|
|
409
|
-
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?:
|
|
410
|
-
dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?:
|
|
407
|
+
isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
|
|
408
|
+
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
409
|
+
dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
410
|
+
dfs<C extends BTNCallback<N | null | undefined>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
411
411
|
/**
|
|
412
412
|
* Time complexity: O(n)
|
|
413
413
|
* Space complexity: O(n)
|
|
414
414
|
*/
|
|
415
|
-
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?:
|
|
416
|
-
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?:
|
|
417
|
-
bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?:
|
|
415
|
+
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
416
|
+
bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[];
|
|
417
|
+
bfs<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
418
418
|
/**
|
|
419
419
|
* Time complexity: O(n)
|
|
420
420
|
* Space complexity: O(n)
|
|
421
421
|
*/
|
|
422
|
-
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?:
|
|
423
|
-
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?:
|
|
424
|
-
listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?:
|
|
422
|
+
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
423
|
+
listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: undefined): ReturnType<C>[][];
|
|
424
|
+
listLevels<C extends BTNCallback<N | null | undefined>>(callback?: C, beginRoot?: BTNKeyOrNode<K, N>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
425
425
|
/**
|
|
426
|
-
* Time
|
|
427
|
-
* Space
|
|
426
|
+
* Time Complexity: O(log n)
|
|
427
|
+
* Space Complexity: O(1)
|
|
428
|
+
*/
|
|
429
|
+
/**
|
|
430
|
+
* Time Complexity: O(log n)
|
|
431
|
+
* Space Complexity: O(1)
|
|
432
|
+
*
|
|
433
|
+
* The function returns the predecessor of a given node in a tree.
|
|
434
|
+
* @param {N} node - The parameter `node` is of type `RedBlackTreeNode`, which represents a node in a
|
|
435
|
+
* tree.
|
|
436
|
+
* @returns the predecessor of the given 'node'.
|
|
428
437
|
*/
|
|
429
438
|
getPredecessor(node: N): N;
|
|
430
439
|
/**
|
|
@@ -452,7 +461,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
452
461
|
* `callback` function on each node in the binary tree. The type of the array elements is determined
|
|
453
462
|
* by the return type of the `callback` function.
|
|
454
463
|
*/
|
|
455
|
-
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?:
|
|
464
|
+
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKeyOrNode<K, N>): ReturnType<C>[];
|
|
456
465
|
/**
|
|
457
466
|
* Time complexity: O(n)
|
|
458
467
|
* Space complexity: O(n)
|
|
@@ -513,7 +522,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
513
522
|
* following types:
|
|
514
523
|
* @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.
|
|
515
524
|
*/
|
|
516
|
-
print(beginRoot?:
|
|
525
|
+
print(beginRoot?: BTNKeyOrNode<K, N>, options?: BinaryTreePrintOptions): void;
|
|
517
526
|
protected _getIterator(node?: N | null | undefined): IterableIterator<[K, V | undefined]>;
|
|
518
527
|
protected _displayAux(node: N | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
519
528
|
protected _defaultOneParamCallback: (node: N) => K;
|
|
@@ -523,7 +532,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
523
532
|
* @param {N} destNode - The destination node to swap.
|
|
524
533
|
* @returns {N} - The destination node after the swap.
|
|
525
534
|
*/
|
|
526
|
-
protected _swapProperties(srcNode:
|
|
535
|
+
protected _swapProperties(srcNode: BTNKeyOrNode<K, N>, destNode: BTNKeyOrNode<K, N>): N | undefined;
|
|
527
536
|
/**
|
|
528
537
|
* The function replaces an old node with a new node in a binary tree.
|
|
529
538
|
* @param {N} oldNode - The oldNode parameter represents the node that needs to be replaced in the
|
|
@@ -544,7 +553,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
544
553
|
* the binary tree. If neither the left nor right child is available, the function returns undefined.
|
|
545
554
|
* If the parent node is null, the function also returns undefined.
|
|
546
555
|
*/
|
|
547
|
-
protected _addTo(newNode: N | null | undefined, parent:
|
|
556
|
+
protected _addTo(newNode: N | null | undefined, parent: BTNKeyOrNode<K, N>): N | null | undefined;
|
|
548
557
|
/**
|
|
549
558
|
* The function sets the root property of an object to a given value, and if the value is not null,
|
|
550
559
|
* it also sets the parent property of the value to undefined.
|
|
@@ -69,7 +69,7 @@ exports.BinaryTreeNode = BinaryTreeNode;
|
|
|
69
69
|
class BinaryTree extends base_1.IterableEntryBase {
|
|
70
70
|
/**
|
|
71
71
|
* The constructor function initializes a binary tree object with optional elements and options.
|
|
72
|
-
* @param [elements] - An optional iterable of
|
|
72
|
+
* @param [elements] - An optional iterable of BTNExemplar objects. These objects represent the
|
|
73
73
|
* elements to be added to the binary tree.
|
|
74
74
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
75
75
|
* configuration options for the binary tree. In this case, it is of type
|
|
@@ -124,7 +124,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
126
|
* The function "isNode" checks if an exemplar is an instance of the BinaryTreeNode class.
|
|
127
|
-
* @param exemplar - The `exemplar` parameter is a variable of type `
|
|
127
|
+
* @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V,N>`.
|
|
128
128
|
* @returns a boolean value indicating whether the exemplar is an instance of the class N.
|
|
129
129
|
*/
|
|
130
130
|
isNode(exemplar) {
|
|
@@ -132,7 +132,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
134
|
* The function `exemplarToNode` converts an exemplar object into a node object.
|
|
135
|
-
* @param exemplar - The `exemplar` parameter is of type `
|
|
135
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
|
|
136
136
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
137
137
|
* `exemplarToNode` function. It represents the value associated with the exemplar node. If no value
|
|
138
138
|
* is provided, it will be `undefined`.
|
|
@@ -170,7 +170,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
172
172
|
* The function checks if a given value is an entry in a binary tree node.
|
|
173
|
-
* @param kne -
|
|
173
|
+
* @param kne - BTNExemplar<K, V,N> - A generic type representing a node in a binary tree. It has
|
|
174
174
|
* two type parameters V and N, representing the value and node type respectively.
|
|
175
175
|
* @returns a boolean value.
|
|
176
176
|
*/
|
|
@@ -248,7 +248,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
248
248
|
*
|
|
249
249
|
* The `addMany` function takes in a collection of nodes and an optional collection of values, and
|
|
250
250
|
* adds each node with its corresponding value to the data structure.
|
|
251
|
-
* @param nodes - An iterable collection of
|
|
251
|
+
* @param nodes - An iterable collection of BTNExemplar objects.
|
|
252
252
|
* @param [values] - An optional iterable of values that will be assigned to each node being added.
|
|
253
253
|
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
254
254
|
*/
|
|
@@ -292,7 +292,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
292
292
|
* @param {C} callback - The `callback` parameter is a function that is used to determine the
|
|
293
293
|
* identifier of the node to be deleted. It is optional and has a default value of
|
|
294
294
|
* `this._defaultOneParamCallback`. The `callback` function should return the identifier of the node.
|
|
295
|
-
* @returns an array of `
|
|
295
|
+
* @returns an array of `BinaryTreeDeleteResult<N>`.
|
|
296
296
|
*/
|
|
297
297
|
delete(identifier, callback = this._defaultOneParamCallback) {
|
|
298
298
|
const deletedResult = [];
|
|
@@ -980,7 +980,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
980
980
|
* @returns a boolean value.
|
|
981
981
|
*/
|
|
982
982
|
isRealNode(node) {
|
|
983
|
-
return node instanceof BinaryTreeNode && node.key
|
|
983
|
+
return node instanceof BinaryTreeNode && String(node.key) !== 'NaN';
|
|
984
984
|
}
|
|
985
985
|
/**
|
|
986
986
|
* The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.
|
|
@@ -988,7 +988,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
988
988
|
* @returns a boolean value.
|
|
989
989
|
*/
|
|
990
990
|
isNIL(node) {
|
|
991
|
-
return node instanceof BinaryTreeNode && node.key
|
|
991
|
+
return node instanceof BinaryTreeNode && String(node.key) === 'NaN';
|
|
992
992
|
}
|
|
993
993
|
/**
|
|
994
994
|
* The function checks if a given node is a real node or null.
|
|
@@ -999,7 +999,7 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
999
999
|
return this.isRealNode(node) || node === null;
|
|
1000
1000
|
}
|
|
1001
1001
|
/**
|
|
1002
|
-
* The function "isNotNodeInstance" checks if a potential key is a
|
|
1002
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
1003
1003
|
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
1004
1004
|
* data type.
|
|
1005
1005
|
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
@@ -1280,19 +1280,23 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1280
1280
|
return levelsNodes;
|
|
1281
1281
|
}
|
|
1282
1282
|
/**
|
|
1283
|
-
*
|
|
1284
|
-
*
|
|
1285
|
-
|
|
1286
|
-
|
|
1283
|
+
* Time Complexity: O(log n)
|
|
1284
|
+
* Space Complexity: O(1)
|
|
1285
|
+
*/
|
|
1286
|
+
/**
|
|
1287
|
+
* Time Complexity: O(log n)
|
|
1288
|
+
* Space Complexity: O(1)
|
|
1289
|
+
*
|
|
1290
|
+
* The function returns the predecessor of a given node in a tree.
|
|
1291
|
+
* @param {N} node - The parameter `node` is of type `RedBlackTreeNode`, which represents a node in a
|
|
1292
|
+
* tree.
|
|
1293
|
+
* @returns the predecessor of the given 'node'.
|
|
1287
1294
|
*/
|
|
1288
1295
|
getPredecessor(node) {
|
|
1289
|
-
|
|
1290
|
-
if (!this.isRealNode(node))
|
|
1291
|
-
return undefined;
|
|
1292
|
-
if (node.left) {
|
|
1296
|
+
if (this.isRealNode(node.left)) {
|
|
1293
1297
|
let predecessor = node.left;
|
|
1294
1298
|
while (!this.isRealNode(predecessor) || (this.isRealNode(predecessor.right) && predecessor.right !== node)) {
|
|
1295
|
-
if (predecessor) {
|
|
1299
|
+
if (this.isRealNode(predecessor)) {
|
|
1296
1300
|
predecessor = predecessor.right;
|
|
1297
1301
|
}
|
|
1298
1302
|
}
|
|
@@ -1310,13 +1314,13 @@ class BinaryTree extends base_1.IterableEntryBase {
|
|
|
1310
1314
|
*/
|
|
1311
1315
|
getSuccessor(x) {
|
|
1312
1316
|
x = this.ensureNode(x);
|
|
1313
|
-
if (!x)
|
|
1317
|
+
if (!this.isRealNode(x))
|
|
1314
1318
|
return undefined;
|
|
1315
|
-
if (x.right) {
|
|
1319
|
+
if (this.isRealNode(x.right)) {
|
|
1316
1320
|
return this.getLeftMost(x.right);
|
|
1317
1321
|
}
|
|
1318
1322
|
let y = x.parent;
|
|
1319
|
-
while (y &&
|
|
1323
|
+
while (this.isRealNode(y) && x === y.right) {
|
|
1320
1324
|
x = y;
|
|
1321
1325
|
y = y.parent;
|
|
1322
1326
|
}
|