min-heap-typed 1.49.0 → 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 +10 -12
- package/dist/data-structures/binary-tree/avl-tree.js +3 -4
- package/dist/data-structures/binary-tree/binary-tree.d.ts +58 -58
- package/dist/data-structures/binary-tree/binary-tree.js +6 -6
- package/dist/data-structures/binary-tree/bst.d.ts +15 -15
- package/dist/data-structures/binary-tree/bst.js +3 -3
- package/dist/data-structures/binary-tree/rb-tree.d.ts +11 -11
- package/dist/data-structures/binary-tree/rb-tree.js +5 -6
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +14 -14
- package/dist/data-structures/binary-tree/tree-multimap.js +3 -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 +14 -14
- package/src/data-structures/binary-tree/binary-tree.ts +74 -77
- package/src/data-structures/binary-tree/bst.ts +18 -17
- package/src/data-structures/binary-tree/rb-tree.ts +17 -18
- package/src/data-structures/binary-tree/tree-multimap.ts +22 -20
- 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, BTNodeKeyOrNode } 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,17 +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;
|
|
61
59
|
/**
|
|
62
60
|
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
63
61
|
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
64
62
|
* data type.
|
|
65
63
|
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
66
64
|
*/
|
|
67
|
-
isNotNodeInstance(potentialKey:
|
|
65
|
+
isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
|
|
68
66
|
/**
|
|
69
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.
|
|
70
68
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -81,7 +79,7 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
|
|
|
81
79
|
* being added to the binary tree.
|
|
82
80
|
* @returns The method is returning either the inserted node or undefined.
|
|
83
81
|
*/
|
|
84
|
-
add(keyOrNodeOrEntry:
|
|
82
|
+
add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | undefined;
|
|
85
83
|
/**
|
|
86
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.
|
|
87
85
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -99,9 +97,9 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
|
|
|
99
97
|
* that is deleted from the binary tree. It is an optional parameter and if not provided, it will
|
|
100
98
|
* default to the `_defaultOneParamCallback` function. The `callback` function should have a single
|
|
101
99
|
* parameter of type `N
|
|
102
|
-
* @returns The method is returning an array of `
|
|
100
|
+
* @returns The method is returning an array of `BinaryTreeDeleteResult<N>`.
|
|
103
101
|
*/
|
|
104
|
-
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C):
|
|
102
|
+
delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeleteResult<N>[];
|
|
105
103
|
/**
|
|
106
104
|
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
|
|
107
105
|
* tree.
|
|
@@ -112,7 +110,7 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
|
|
|
112
110
|
* @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
|
|
113
111
|
* if either `srcNode` or `destNode` is undefined.
|
|
114
112
|
*/
|
|
115
|
-
protected _swapProperties(srcNode:
|
|
113
|
+
protected _swapProperties(srcNode: BSTNKeyOrNode<K, N>, destNode: BSTNKeyOrNode<K, N>): N | undefined;
|
|
116
114
|
/**
|
|
117
115
|
* Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
|
|
118
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,7 +64,7 @@ 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) {
|
|
@@ -121,7 +120,7 @@ class AVLTree extends bst_1.BST {
|
|
|
121
120
|
* that is deleted from the binary tree. It is an optional parameter and if not provided, it will
|
|
122
121
|
* default to the `_defaultOneParamCallback` function. The `callback` function should have a single
|
|
123
122
|
* parameter of type `N
|
|
124
|
-
* @returns The method is returning an array of `
|
|
123
|
+
* @returns The method is returning an array of `BinaryTreeDeleteResult<N>`.
|
|
125
124
|
*/
|
|
126
125
|
delete(identifier, callback = this._defaultOneParamCallback) {
|
|
127
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,43 +385,43 @@ 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
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
426
|
* Time Complexity: O(log n)
|
|
427
427
|
* Space Complexity: O(1)
|
|
@@ -461,7 +461,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
461
461
|
* `callback` function on each node in the binary tree. The type of the array elements is determined
|
|
462
462
|
* by the return type of the `callback` function.
|
|
463
463
|
*/
|
|
464
|
-
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>[];
|
|
465
465
|
/**
|
|
466
466
|
* Time complexity: O(n)
|
|
467
467
|
* Space complexity: O(n)
|
|
@@ -522,7 +522,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
522
522
|
* following types:
|
|
523
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.
|
|
524
524
|
*/
|
|
525
|
-
print(beginRoot?:
|
|
525
|
+
print(beginRoot?: BTNKeyOrNode<K, N>, options?: BinaryTreePrintOptions): void;
|
|
526
526
|
protected _getIterator(node?: N | null | undefined): IterableIterator<[K, V | undefined]>;
|
|
527
527
|
protected _displayAux(node: N | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
528
528
|
protected _defaultOneParamCallback: (node: N) => K;
|
|
@@ -532,7 +532,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
532
532
|
* @param {N} destNode - The destination node to swap.
|
|
533
533
|
* @returns {N} - The destination node after the swap.
|
|
534
534
|
*/
|
|
535
|
-
protected _swapProperties(srcNode:
|
|
535
|
+
protected _swapProperties(srcNode: BTNKeyOrNode<K, N>, destNode: BTNKeyOrNode<K, N>): N | undefined;
|
|
536
536
|
/**
|
|
537
537
|
* The function replaces an old node with a new node in a binary tree.
|
|
538
538
|
* @param {N} oldNode - The oldNode parameter represents the node that needs to be replaced in the
|
|
@@ -553,7 +553,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
|
|
|
553
553
|
* the binary tree. If neither the left nor right child is available, the function returns undefined.
|
|
554
554
|
* If the parent node is null, the function also returns undefined.
|
|
555
555
|
*/
|
|
556
|
-
protected _addTo(newNode: N | null | undefined, parent:
|
|
556
|
+
protected _addTo(newNode: N | null | undefined, parent: BTNKeyOrNode<K, N>): N | null | undefined;
|
|
557
557
|
/**
|
|
558
558
|
* The function sets the root property of an object to a given value, and if the value is not null,
|
|
559
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 = [];
|
|
@@ -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 { BSTNested,
|
|
9
|
-
import { BSTVariant,
|
|
8
|
+
import type { BSTNested, BSTNKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback, BTNExemplar, BTNKeyOrNode } from '../../types';
|
|
9
|
+
import { BSTVariant, CP, IterationType } from '../../types';
|
|
10
10
|
import { BinaryTree, BinaryTreeNode } from './binary-tree';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
12
|
export declare class BSTNode<K = any, V = any, N extends BSTNode<K, V, N> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, N> {
|
|
@@ -46,12 +46,12 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
46
46
|
/**
|
|
47
47
|
* This is the constructor function for a binary search tree class in TypeScript, which initializes
|
|
48
48
|
* the tree with optional elements and options.
|
|
49
|
-
* @param [elements] - An optional iterable of
|
|
49
|
+
* @param [elements] - An optional iterable of BTNExemplar objects that will be added to the
|
|
50
50
|
* binary search tree.
|
|
51
51
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
52
52
|
* configuration options for the binary search tree. It can have the following properties:
|
|
53
53
|
*/
|
|
54
|
-
constructor(elements?: Iterable<
|
|
54
|
+
constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<BSTOptions<K>>);
|
|
55
55
|
protected _root?: N;
|
|
56
56
|
get root(): N | undefined;
|
|
57
57
|
protected _variant: BSTVariant;
|
|
@@ -75,19 +75,19 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
75
75
|
createTree(options?: Partial<BSTOptions<K>>): TREE;
|
|
76
76
|
/**
|
|
77
77
|
* The function checks if an exemplar is an instance of BSTNode.
|
|
78
|
-
* @param exemplar - The `exemplar` parameter is a variable of type `
|
|
78
|
+
* @param exemplar - The `exemplar` parameter is a variable of type `BTNExemplar<K, V, N>`.
|
|
79
79
|
* @returns a boolean value indicating whether the exemplar is an instance of the BSTNode class.
|
|
80
80
|
*/
|
|
81
|
-
isNode(exemplar:
|
|
81
|
+
isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
|
|
82
82
|
/**
|
|
83
83
|
* The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
|
|
84
84
|
* otherwise it returns undefined.
|
|
85
|
-
* @param exemplar - The `exemplar` parameter is of type `
|
|
85
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, where:
|
|
86
86
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
87
87
|
* `exemplarToNode` function. It represents the value associated with the exemplar node.
|
|
88
88
|
* @returns a node of type N or undefined.
|
|
89
89
|
*/
|
|
90
|
-
exemplarToNode(exemplar:
|
|
90
|
+
exemplarToNode(exemplar: BTNExemplar<K, V, N>, value?: V): N | undefined;
|
|
91
91
|
/**
|
|
92
92
|
* Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
|
|
93
93
|
* Space Complexity: O(1) - Constant space is used.
|
|
@@ -104,7 +104,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
104
104
|
* @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
|
|
105
105
|
* node was not added.
|
|
106
106
|
*/
|
|
107
|
-
add(keyOrNodeOrEntry:
|
|
107
|
+
add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | undefined;
|
|
108
108
|
/**
|
|
109
109
|
* Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
|
|
110
110
|
* Space Complexity: O(k) - Additional space is required for the sorted array.
|
|
@@ -129,7 +129,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
129
129
|
* `this.iterationType`, which suggests that it is a property of the current object.
|
|
130
130
|
* @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
|
|
131
131
|
*/
|
|
132
|
-
addMany(keysOrNodesOrEntries: Iterable<
|
|
132
|
+
addMany(keysOrNodesOrEntries: Iterable<BTNExemplar<K, V, N>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): (N | undefined)[];
|
|
133
133
|
/**
|
|
134
134
|
* Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
|
|
135
135
|
* Space Complexity: O(n) - Additional space is required for the sorted array.
|
|
@@ -149,7 +149,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
149
149
|
* the key of the leftmost node if the comparison result is greater than, and the key of the
|
|
150
150
|
* rightmost node otherwise. If no node is found, it returns 0.
|
|
151
151
|
*/
|
|
152
|
-
lastKey(beginRoot?:
|
|
152
|
+
lastKey(beginRoot?: BSTNKeyOrNode<K, N>): K | undefined;
|
|
153
153
|
/**
|
|
154
154
|
* Time Complexity: O(log n) - Average case for a balanced tree.
|
|
155
155
|
* Space Complexity: O(1) - Constant space is used.
|
|
@@ -175,7 +175,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
175
175
|
* data type.
|
|
176
176
|
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
177
177
|
*/
|
|
178
|
-
isNotNodeInstance(potentialKey:
|
|
178
|
+
isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
|
|
179
179
|
/**
|
|
180
180
|
* Time Complexity: O(log n) - Average case for a balanced tree.
|
|
181
181
|
* Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
|
|
@@ -189,7 +189,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
189
189
|
* type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
|
|
190
190
|
* @returns either a node object (N) or undefined.
|
|
191
191
|
*/
|
|
192
|
-
ensureNode(key:
|
|
192
|
+
ensureNode(key: BSTNKeyOrNode<K, N>, iterationType?: IterationType): N | undefined;
|
|
193
193
|
/**
|
|
194
194
|
* Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
|
|
195
195
|
* Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
|
|
@@ -213,7 +213,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
213
213
|
* performed on the binary tree. It can have two possible values:
|
|
214
214
|
* @returns The method returns an array of nodes (`N[]`).
|
|
215
215
|
*/
|
|
216
|
-
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?:
|
|
216
|
+
getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: BSTNKeyOrNode<K, N>, iterationType?: IterationType): N[];
|
|
217
217
|
/**
|
|
218
218
|
* Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
|
|
219
219
|
* Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
|
|
@@ -239,7 +239,7 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
239
239
|
* @returns The function `lesserOrGreaterTraverse` returns an array of values of type
|
|
240
240
|
* `ReturnType<C>`, which is the return type of the callback function passed as an argument.
|
|
241
241
|
*/
|
|
242
|
-
lesserOrGreaterTraverse<C extends BTNCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?:
|
|
242
|
+
lesserOrGreaterTraverse<C extends BTNCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?: BSTNKeyOrNode<K, N>, iterationType?: IterationType): ReturnType<C>[];
|
|
243
243
|
/**
|
|
244
244
|
* Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
|
|
245
245
|
* Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
|