heap-typed 1.51.8 → 1.52.0
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/base/index.d.ts +2 -1
- package/dist/data-structures/base/index.js +2 -1
- package/dist/data-structures/base/iterable-element-base.d.ts +171 -0
- package/dist/data-structures/base/iterable-element-base.js +225 -0
- package/dist/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
- package/dist/data-structures/base/{iterable-base.js → iterable-entry-base.js} +12 -189
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
- package/dist/data-structures/binary-tree/avl-tree.d.ts +82 -62
- package/dist/data-structures/binary-tree/avl-tree.js +78 -59
- package/dist/data-structures/binary-tree/binary-tree.d.ts +318 -226
- package/dist/data-structures/binary-tree/binary-tree.js +475 -363
- package/dist/data-structures/binary-tree/bst.d.ts +192 -202
- package/dist/data-structures/binary-tree/bst.js +207 -249
- package/dist/data-structures/binary-tree/rb-tree.d.ts +73 -74
- package/dist/data-structures/binary-tree/rb-tree.js +107 -98
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +92 -75
- package/dist/data-structures/binary-tree/tree-multi-map.js +105 -93
- package/dist/data-structures/graph/abstract-graph.d.ts +10 -15
- package/dist/data-structures/graph/abstract-graph.js +10 -15
- package/dist/data-structures/hash/hash-map.d.ts +33 -40
- package/dist/data-structures/hash/hash-map.js +40 -55
- package/dist/data-structures/heap/heap.d.ts +43 -114
- package/dist/data-structures/heap/heap.js +59 -127
- package/dist/data-structures/heap/max-heap.d.ts +50 -4
- package/dist/data-structures/heap/max-heap.js +76 -10
- package/dist/data-structures/heap/min-heap.d.ts +51 -5
- package/dist/data-structures/heap/min-heap.js +68 -11
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
- package/dist/data-structures/linked-list/doubly-linked-list.js +26 -28
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +22 -25
- package/dist/data-structures/linked-list/singly-linked-list.js +29 -26
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
- package/dist/data-structures/priority-queue/max-priority-queue.js +79 -10
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
- package/dist/data-structures/priority-queue/min-priority-queue.js +71 -11
- package/dist/data-structures/priority-queue/priority-queue.d.ts +50 -4
- package/dist/data-structures/priority-queue/priority-queue.js +70 -1
- package/dist/data-structures/queue/deque.d.ts +21 -20
- package/dist/data-structures/queue/deque.js +29 -23
- package/dist/data-structures/queue/queue.d.ts +8 -28
- package/dist/data-structures/queue/queue.js +15 -31
- package/dist/data-structures/stack/stack.d.ts +17 -22
- package/dist/data-structures/stack/stack.js +25 -24
- package/dist/data-structures/trie/trie.d.ts +19 -14
- package/dist/data-structures/trie/trie.js +27 -16
- package/dist/interfaces/binary-tree.d.ts +7 -7
- package/dist/types/common.d.ts +1 -2
- package/dist/types/data-structures/base/base.d.ts +5 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
- package/dist/types/data-structures/binary-tree/bst.d.ts +4 -5
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
- package/dist/types/data-structures/heap/heap.d.ts +3 -2
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +3 -2
- package/dist/types/data-structures/queue/queue.d.ts +2 -1
- package/dist/types/data-structures/stack/stack.d.ts +2 -1
- package/dist/types/data-structures/trie/trie.d.ts +3 -2
- package/dist/utils/utils.js +3 -5
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +2 -1
- package/src/data-structures/base/iterable-element-base.ts +250 -0
- package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +144 -95
- package/src/data-structures/binary-tree/avl-tree.ts +96 -69
- package/src/data-structures/binary-tree/binary-tree.ts +535 -403
- package/src/data-structures/binary-tree/bst.ts +247 -277
- package/src/data-structures/binary-tree/rb-tree.ts +123 -103
- package/src/data-structures/binary-tree/tree-multi-map.ts +127 -102
- package/src/data-structures/graph/abstract-graph.ts +10 -10
- package/src/data-structures/hash/hash-map.ts +46 -53
- package/src/data-structures/heap/heap.ts +71 -152
- package/src/data-structures/heap/max-heap.ts +88 -13
- package/src/data-structures/heap/min-heap.ts +78 -15
- package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
- package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
- package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
- package/src/data-structures/priority-queue/priority-queue.ts +81 -4
- package/src/data-structures/queue/deque.ts +37 -26
- package/src/data-structures/queue/queue.ts +23 -36
- package/src/data-structures/stack/stack.ts +31 -26
- package/src/data-structures/trie/trie.ts +35 -20
- package/src/interfaces/binary-tree.ts +9 -9
- package/src/types/common.ts +1 -2
- package/src/types/data-structures/base/base.ts +14 -6
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -4
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -4
- package/src/types/data-structures/binary-tree/binary-tree.ts +6 -6
- package/src/types/data-structures/binary-tree/bst.ts +4 -5
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -4
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -4
- package/src/types/data-structures/heap/heap.ts +4 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
- package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/types/data-structures/queue/deque.ts +3 -1
- package/src/types/data-structures/queue/queue.ts +3 -1
- package/src/types/data-structures/stack/stack.ts +3 -1
- package/src/types/data-structures/trie/trie.ts +3 -1
- package/src/utils/utils.ts +3 -3
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BSTNested, BSTNKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback,
|
|
8
|
+
import type { BSTNested, BSTNKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback, Comparator, CP, DFSOrderPattern, IterationType, KeyOrNodeOrEntry } from '../../types';
|
|
9
|
+
import { BTNEntry } from '../../types';
|
|
9
10
|
import { BinaryTree, BinaryTreeNode } from './binary-tree';
|
|
10
11
|
import { IBinaryTree } from '../../interfaces';
|
|
11
|
-
export declare class BSTNode<K
|
|
12
|
+
export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, NODE> {
|
|
12
13
|
parent?: NODE;
|
|
13
14
|
constructor(key: K, value?: V);
|
|
14
15
|
protected _left?: NODE;
|
|
@@ -46,29 +47,22 @@ export declare class BSTNode<K extends Comparable, V = any, NODE extends BSTNode
|
|
|
46
47
|
* 6. Balance Variability: Can become unbalanced; special types maintain balance.
|
|
47
48
|
* 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
|
|
48
49
|
*/
|
|
49
|
-
export declare class BST<K
|
|
50
|
+
export declare class BST<K = any, V = any, R = BTNEntry<K, V>, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, R, NODE, TREE> = BST<K, V, R, NODE, BSTNested<K, V, R, NODE>>> extends BinaryTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
50
51
|
/**
|
|
51
|
-
* This is the constructor function for a Binary Search Tree class in TypeScript
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* configuration options for the binary search tree. It can have the following properties:
|
|
52
|
+
* This is the constructor function for a Binary Search Tree class in TypeScript.
|
|
53
|
+
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
|
|
54
|
+
* iterable that can contain either keys, nodes, entries, or raw elements. These elements will be
|
|
55
|
+
* added to the binary search tree during the construction of the object.
|
|
56
|
+
* @param [options] - An optional object that contains additional options for the Binary Search Tree.
|
|
57
|
+
* It can include a comparator function that defines the order of the elements in the tree.
|
|
58
58
|
*/
|
|
59
|
-
constructor(
|
|
59
|
+
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>, options?: BSTOptions<K, V, R>);
|
|
60
60
|
protected _root?: NODE;
|
|
61
61
|
/**
|
|
62
62
|
* The function returns the root node of a tree structure.
|
|
63
63
|
* @returns The `_root` property of the object, which is of type `NODE` or `undefined`.
|
|
64
64
|
*/
|
|
65
65
|
get root(): NODE | undefined;
|
|
66
|
-
protected _comparator: Comparator<K>;
|
|
67
|
-
/**
|
|
68
|
-
* The function returns the value of the _comparator property.
|
|
69
|
-
* @returns The `_comparator` property is being returned.
|
|
70
|
-
*/
|
|
71
|
-
get comparator(): Comparator<K>;
|
|
72
66
|
/**
|
|
73
67
|
* The function creates a new BSTNode with the given key and value and returns it.
|
|
74
68
|
* @param {K} key - The key parameter is of type K, which represents the type of the key for the node
|
|
@@ -81,72 +75,69 @@ export declare class BST<K extends Comparable, V = any, NODE extends BSTNode<K,
|
|
|
81
75
|
/**
|
|
82
76
|
* The function creates a new binary search tree with the specified options.
|
|
83
77
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
84
|
-
* behavior of the `createTree` method. It
|
|
85
|
-
*
|
|
86
|
-
* @returns a new instance of the BST class
|
|
87
|
-
* options. The returned value is casted as TREE.
|
|
88
|
-
*/
|
|
89
|
-
createTree(options?: Partial<BSTOptions<K>>): TREE;
|
|
90
|
-
/**
|
|
91
|
-
* The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
|
|
92
|
-
* otherwise it returns undefined.
|
|
93
|
-
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
|
|
94
|
-
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
95
|
-
* `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
|
|
96
|
-
* @returns a node of type NODE or undefined.
|
|
78
|
+
* behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
|
|
79
|
+
* following properties:
|
|
80
|
+
* @returns a new instance of the BST class with the provided options.
|
|
97
81
|
*/
|
|
98
|
-
|
|
82
|
+
createTree(options?: Partial<BSTOptions<K, V, R>>): TREE;
|
|
99
83
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
84
|
+
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
85
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - A variable that can be of
|
|
86
|
+
* type R or KeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
|
|
87
|
+
* element.
|
|
88
|
+
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
89
|
+
* value associated with a key in a key-value pair.
|
|
90
|
+
* @returns either a NODE object or undefined.
|
|
102
91
|
*/
|
|
92
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined;
|
|
103
93
|
/**
|
|
104
94
|
* Time Complexity: O(log n)
|
|
105
95
|
* Space Complexity: O(log n)
|
|
106
96
|
*
|
|
107
|
-
* The function
|
|
108
|
-
*
|
|
109
|
-
* @param {
|
|
110
|
-
* `
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*/
|
|
97
|
+
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
98
|
+
* it doesn't exist.
|
|
99
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
100
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, which represents the key, node,
|
|
101
|
+
* entry, or raw element that needs to be ensured in the tree.
|
|
102
|
+
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
103
|
+
* parameter that specifies the type of iteration to be used when ensuring a node. It has a default
|
|
104
|
+
* value of `'ITERATIVE'`.
|
|
105
|
+
* @returns The method is returning either the node that was ensured or `undefined` if the node could
|
|
106
|
+
* not be ensured.
|
|
107
|
+
*/
|
|
108
|
+
ensureNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* The function checks if the input is an instance of the BSTNode class.
|
|
111
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
112
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
113
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
114
|
+
* an instance of the `BSTNode` class.
|
|
115
|
+
*/
|
|
116
|
+
isNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
|
|
126
117
|
/**
|
|
127
118
|
* Time Complexity: O(log n)
|
|
128
119
|
* Space Complexity: O(1)
|
|
129
120
|
*
|
|
130
|
-
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* @param {V} [value] - The value
|
|
134
|
-
*
|
|
121
|
+
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
122
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
123
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
124
|
+
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
125
|
+
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
126
|
+
* @returns a boolean value.
|
|
135
127
|
*/
|
|
136
|
-
add(
|
|
128
|
+
add(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
|
|
137
129
|
/**
|
|
138
|
-
* Time Complexity: O(
|
|
139
|
-
* Space Complexity: O(
|
|
130
|
+
* Time Complexity: O(log n)
|
|
131
|
+
* Space Complexity: O(log n)
|
|
140
132
|
*/
|
|
141
133
|
/**
|
|
142
134
|
* Time Complexity: O(k log n)
|
|
143
135
|
* Space Complexity: O(k + log n)
|
|
144
136
|
*
|
|
145
|
-
* The `addMany` function in TypeScript adds multiple keys or nodes to a data structure
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* data structure.
|
|
137
|
+
* The `addMany` function in TypeScript adds multiple keys or nodes to a data structure and returns
|
|
138
|
+
* an array indicating whether each key or node was successfully inserted.
|
|
139
|
+
* @param keysOrNodesOrEntriesOrRawElements - An iterable containing keys, nodes, entries, or raw
|
|
140
|
+
* elements to be added to the data structure.
|
|
150
141
|
* @param [values] - An optional iterable of values to be associated with the keys or nodes being
|
|
151
142
|
* added. If provided, the values will be assigned to the corresponding keys or nodes in the same
|
|
152
143
|
* order. If not provided, undefined will be assigned as the value for each key or node.
|
|
@@ -155,42 +146,35 @@ export declare class BST<K extends Comparable, V = any, NODE extends BSTNode<K,
|
|
|
155
146
|
* algorithm. If set to false, the elements will be added without balancing the tree. The default
|
|
156
147
|
* value is true.
|
|
157
148
|
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
158
|
-
* specifies the type of iteration to use when adding multiple keys or nodes to the binary
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* or entry was successfully inserted into the data structure.
|
|
149
|
+
* specifies the type of iteration to use when adding multiple keys or nodes to the binary search
|
|
150
|
+
* tree. It can have two possible values:
|
|
151
|
+
* @returns The function `addMany` returns an array of booleans indicating whether each element was
|
|
152
|
+
* successfully inserted into the data structure.
|
|
163
153
|
*/
|
|
164
|
-
addMany(
|
|
154
|
+
addMany(keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
|
|
165
155
|
/**
|
|
166
|
-
* Time Complexity: O(log n)
|
|
167
|
-
* Space Complexity: O(k + log n)
|
|
168
|
-
* /
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
156
|
* Time Complexity: O(log n)
|
|
172
157
|
* Space Complexity: O(k + log n)
|
|
173
158
|
*
|
|
174
|
-
* The
|
|
175
|
-
*
|
|
159
|
+
* The `getNodes` function in TypeScript retrieves nodes from a binary tree based on a given
|
|
160
|
+
* identifier and callback function.
|
|
176
161
|
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
|
|
177
|
-
* want to search for in the
|
|
178
|
-
*
|
|
179
|
-
* @param {C} callback - The `callback` parameter is a function that takes a node
|
|
180
|
-
*
|
|
181
|
-
* function
|
|
182
|
-
* @param [onlyOne=false] - A boolean
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
162
|
+
* want to search for in the binary tree. It can be of any type that is returned by the callback
|
|
163
|
+
* function.
|
|
164
|
+
* @param {C} callback - The `callback` parameter is a function that takes a node as input and
|
|
165
|
+
* returns a value. This value is used to identify the nodes that match the given identifier. The
|
|
166
|
+
* `callback` function is optional and defaults to `this._DEFAULT_CALLBACK`.
|
|
167
|
+
* @param [onlyOne=false] - A boolean value indicating whether to return only the first matching node
|
|
168
|
+
* or all matching nodes. If set to true, only the first matching node will be returned. If set to
|
|
169
|
+
* false, all matching nodes will be returned. The default value is false.
|
|
170
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
171
|
+
* point for the search in the binary tree. It can be either a node object, a key-value pair, or an
|
|
172
|
+
* entry object. If it is not provided, the `root` of the binary tree is used as the starting point.
|
|
173
|
+
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
174
|
+
* iteration to be performed. It can have two possible values:
|
|
175
|
+
* @returns The method `getNodes` returns an array of `NODE` objects.
|
|
176
|
+
*/
|
|
177
|
+
getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, onlyOne?: boolean, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
194
178
|
/**
|
|
195
179
|
* Time Complexity: O(log n)
|
|
196
180
|
* Space Complexity: O(1)
|
|
@@ -199,46 +183,45 @@ export declare class BST<K extends Comparable, V = any, NODE extends BSTNode<K,
|
|
|
199
183
|
* Time Complexity: O(log n)
|
|
200
184
|
* Space Complexity: O(1)
|
|
201
185
|
*
|
|
202
|
-
* The `getNode`
|
|
203
|
-
*
|
|
204
|
-
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* @param {C} callback - The `callback` parameter is a function that will be
|
|
208
|
-
* the
|
|
209
|
-
*
|
|
210
|
-
*
|
|
186
|
+
* The function `getNode` returns the first node that matches the given identifier and callback
|
|
187
|
+
* function in a binary search tree.
|
|
188
|
+
* @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
|
|
189
|
+
* want to search for in the binary search tree. It can be of any type that is compatible with the
|
|
190
|
+
* type returned by the callback function.
|
|
191
|
+
* @param {C} callback - The `callback` parameter is a function that will be used to determine if a
|
|
192
|
+
* node matches the desired criteria. It should be a function that takes a node as an argument and
|
|
193
|
+
* returns a boolean value indicating whether the node matches the criteria or not. If no callback is
|
|
194
|
+
* provided, the default callback will be
|
|
211
195
|
* @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
|
|
212
|
-
* search tree. It can be either a key or a node. If it is a key,
|
|
213
|
-
*
|
|
214
|
-
* @param iterationType - The `iterationType` parameter is used to specify the type
|
|
215
|
-
* be performed when searching for nodes in the binary search tree. It
|
|
216
|
-
*
|
|
217
|
-
* @returns The method is returning a
|
|
196
|
+
* search tree. It can be either a key or a node. If it is a key, the search will start from the node
|
|
197
|
+
* with that key. If it is a node, the search will start from that node.
|
|
198
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
199
|
+
* of iteration to be performed when searching for nodes in the binary search tree. It can have one
|
|
200
|
+
* of the following values:
|
|
201
|
+
* @returns The method is returning a NODE object or undefined.
|
|
218
202
|
*/
|
|
219
|
-
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: BSTNKeyOrNode<K, NODE>, iterationType?: IterationType): NODE | undefined;
|
|
203
|
+
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: R | BSTNKeyOrNode<K, NODE>, iterationType?: IterationType): NODE | undefined;
|
|
220
204
|
/**
|
|
221
|
-
* Time Complexity: O(log n)
|
|
222
|
-
* Space Complexity: O(
|
|
205
|
+
* Time Complexity: O(k log n)
|
|
206
|
+
* Space Complexity: O(k + log n)
|
|
223
207
|
*/
|
|
224
208
|
/**
|
|
225
209
|
* Time Complexity: O(log n)
|
|
226
210
|
* Space Complexity: O(1)
|
|
227
211
|
*
|
|
228
|
-
* The function `getNodeByKey`
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
* @param iterationType - The `iterationType` parameter is an optional
|
|
233
|
-
* type of iteration to
|
|
234
|
-
*
|
|
235
|
-
* @returns The
|
|
236
|
-
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
212
|
+
* The function `getNodeByKey` returns a node with a specific key from a tree data structure.
|
|
213
|
+
* @param {K} key - The key parameter is the value used to search for a specific node in the tree. It
|
|
214
|
+
* is typically a unique identifier or a value that can be used to determine the position of the node
|
|
215
|
+
* in the tree structure.
|
|
216
|
+
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
217
|
+
* parameter that specifies the type of iteration to be used when searching for a node in the tree.
|
|
218
|
+
* It has a default value of `'ITERATIVE'`.
|
|
219
|
+
* @returns The method is returning a NODE object or undefined.
|
|
237
220
|
*/
|
|
238
221
|
getNodeByKey(key: K, iterationType?: IterationType): NODE | undefined;
|
|
239
222
|
/**
|
|
240
|
-
* Time
|
|
241
|
-
* Space
|
|
223
|
+
* Time Complexity: O(log n)
|
|
224
|
+
* Space Complexity: O(k + log n)
|
|
242
225
|
*/
|
|
243
226
|
/**
|
|
244
227
|
* Time complexity: O(n)
|
|
@@ -247,22 +230,23 @@ export declare class BST<K extends Comparable, V = any, NODE extends BSTNode<K,
|
|
|
247
230
|
* The function overrides the depth-first search method and returns an array of the return types of
|
|
248
231
|
* the callback function.
|
|
249
232
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
250
|
-
* during the depth-first search traversal. It is an optional parameter and
|
|
251
|
-
*
|
|
252
|
-
* @param {DFSOrderPattern} [pattern=
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
233
|
+
* during the depth-first search traversal. It is an optional parameter and defaults to
|
|
234
|
+
* `this._DEFAULT_CALLBACK`. The type `C` represents the type of the callback function.
|
|
235
|
+
* @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
|
|
236
|
+
* order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
|
|
237
|
+
* take one of the following values:
|
|
238
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
239
|
+
* point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
|
|
240
|
+
* node entry. If not specified, the default value is the root of the tree.
|
|
241
|
+
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
|
|
242
|
+
* type of iteration to be used during the Depth-First Search (DFS) traversal. It can have one of the
|
|
259
243
|
* following values:
|
|
260
244
|
* @returns The method is returning an array of the return type of the callback function.
|
|
261
245
|
*/
|
|
262
|
-
dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
246
|
+
dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
263
247
|
/**
|
|
264
|
-
* Time
|
|
265
|
-
* Space
|
|
248
|
+
* Time Complexity: O(log n)
|
|
249
|
+
* Space Complexity: O(1)
|
|
266
250
|
*/
|
|
267
251
|
/**
|
|
268
252
|
* Time complexity: O(n)
|
|
@@ -271,109 +255,115 @@ export declare class BST<K extends Comparable, V = any, NODE extends BSTNode<K,
|
|
|
271
255
|
* The function overrides the breadth-first search method and returns an array of the return types of
|
|
272
256
|
* the callback function.
|
|
273
257
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
274
|
-
* visited during the breadth-first search
|
|
275
|
-
*
|
|
276
|
-
* @param beginRoot - The `beginRoot` parameter is the starting
|
|
277
|
-
*
|
|
278
|
-
* the
|
|
279
|
-
* @param iterationType - The `iterationType` parameter is used to specify the type
|
|
280
|
-
* be performed during the breadth-first search (BFS) traversal. It
|
|
281
|
-
*
|
|
282
|
-
* @returns
|
|
283
|
-
*/
|
|
284
|
-
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
258
|
+
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
259
|
+
* node being visited, and it can return a value of any type.
|
|
260
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
261
|
+
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
262
|
+
* object. If no value is provided, the default value is the root of the tree.
|
|
263
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
264
|
+
* of iteration to be performed during the breadth-first search (BFS) traversal. It can have one of
|
|
265
|
+
* the following values:
|
|
266
|
+
* @returns an array of the return type of the callback function.
|
|
267
|
+
*/
|
|
268
|
+
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
285
269
|
/**
|
|
286
|
-
* Time
|
|
287
|
-
* Space
|
|
270
|
+
* Time Complexity: O(log n)
|
|
271
|
+
* Space Complexity: O(1)
|
|
288
272
|
*/
|
|
289
273
|
/**
|
|
290
274
|
* Time complexity: O(n)
|
|
291
275
|
* Space complexity: O(n)
|
|
292
276
|
*
|
|
293
|
-
* The function overrides the listLevels method and returns an array of arrays
|
|
294
|
-
*
|
|
277
|
+
* The function overrides the listLevels method from the superclass and returns an array of arrays
|
|
278
|
+
* containing the results of the callback function applied to each level of the tree.
|
|
295
279
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
296
|
-
* `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
|
|
297
|
-
* during the
|
|
298
|
-
* @param beginRoot - The `beginRoot` parameter is
|
|
299
|
-
* levels of
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
* iteration.
|
|
280
|
+
* `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
|
|
281
|
+
* tree during the iteration process.
|
|
282
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
283
|
+
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
284
|
+
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
285
|
+
* value is provided, the root of
|
|
286
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
287
|
+
* of iteration to be performed on the tree. It can have one of the following values:
|
|
304
288
|
* @returns The method is returning a two-dimensional array of the return type of the callback
|
|
305
289
|
* function.
|
|
306
290
|
*/
|
|
307
|
-
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[][];
|
|
291
|
+
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[][];
|
|
308
292
|
/**
|
|
309
|
-
* Time
|
|
310
|
-
* Space
|
|
293
|
+
* Time complexity: O(n)
|
|
294
|
+
* Space complexity: O(n)
|
|
311
295
|
*/
|
|
312
296
|
/**
|
|
313
|
-
* Time
|
|
314
|
-
* Space
|
|
297
|
+
* Time complexity: O(n)
|
|
298
|
+
* Space complexity: O(n)
|
|
315
299
|
*
|
|
316
|
-
* The `lesserOrGreaterTraverse` function traverses a binary tree and
|
|
317
|
-
*
|
|
300
|
+
* The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
|
|
301
|
+
* each node that meets a certain condition based on a target node and a comparison value.
|
|
318
302
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
319
|
-
* that
|
|
320
|
-
*
|
|
303
|
+
* that meets the condition specified by the `lesserOrGreater` parameter. It takes a single argument,
|
|
304
|
+
* which is the current node being traversed, and returns a value of any type.
|
|
321
305
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
322
|
-
* traverse nodes that are lesser
|
|
323
|
-
*
|
|
324
|
-
* `
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
* @param iterationType - The `iterationType` parameter determines the type of
|
|
329
|
-
* performed on the binary tree. It can have two possible values:
|
|
306
|
+
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
307
|
+
* 0, or 1, where:
|
|
308
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} targetNode - The `targetNode` parameter is the node in
|
|
309
|
+
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
310
|
+
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
311
|
+
* `targetNode` is provided,
|
|
312
|
+
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
313
|
+
* traversal to be performed on the binary tree. It can have two possible values:
|
|
330
314
|
* @returns The function `lesserOrGreaterTraverse` returns an array of values of type
|
|
331
315
|
* `ReturnType<C>`, which is the return type of the callback function passed as an argument.
|
|
332
316
|
*/
|
|
333
|
-
lesserOrGreaterTraverse<C extends BTNCallback<NODE>>(callback?: C, lesserOrGreater?: CP, targetNode?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
317
|
+
lesserOrGreaterTraverse<C extends BTNCallback<NODE>>(callback?: C, lesserOrGreater?: CP, targetNode?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
334
318
|
/**
|
|
335
|
-
* Time
|
|
336
|
-
* Space
|
|
319
|
+
* Time complexity: O(n)
|
|
320
|
+
* Space complexity: O(n)
|
|
337
321
|
*/
|
|
338
322
|
/**
|
|
339
|
-
* Time
|
|
340
|
-
* Space
|
|
323
|
+
* Time complexity: O(n)
|
|
324
|
+
* Space complexity: O(n)
|
|
341
325
|
*
|
|
342
|
-
* The `perfectlyBalance` function
|
|
343
|
-
*
|
|
344
|
-
* @param iterationType - The `iterationType` parameter is an optional parameter that
|
|
345
|
-
* type of iteration to use when building a balanced binary search tree. It
|
|
346
|
-
*
|
|
326
|
+
* The `perfectlyBalance` function takes an optional `iterationType` parameter and returns `true` if
|
|
327
|
+
* the binary search tree is perfectly balanced, otherwise it returns `false`.
|
|
328
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
329
|
+
* specifies the type of iteration to use when building a balanced binary search tree. It has a
|
|
330
|
+
* default value of `this.iterationType`, which means it will use the iteration type specified in the
|
|
331
|
+
* current instance of the class.
|
|
347
332
|
* @returns The function `perfectlyBalance` returns a boolean value.
|
|
348
333
|
*/
|
|
349
334
|
perfectlyBalance(iterationType?: IterationType): boolean;
|
|
350
335
|
/**
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
* AVL Tree: After insertion or deletion operations, an AVL tree performs rotation adjustments based on the balance factor of nodes to restore the tree's balance. These rotations can be left rotations, right rotations, left-right rotations, or right-left rotations, performed as needed.
|
|
354
|
-
*
|
|
355
|
-
* Use Cases and Efficiency:
|
|
356
|
-
* Perfectly Balanced Binary Tree: Perfectly balanced binary trees are typically used in specific scenarios such as complete binary heaps in heap sort or certain types of Huffman trees. However, they are not suitable for dynamic operations requiring frequent insertions and deletions, as these operations often necessitate full tree reconstruction.
|
|
357
|
-
* AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
|
|
336
|
+
* Time complexity: O(n)
|
|
337
|
+
* Space complexity: O(n)
|
|
358
338
|
*/
|
|
359
339
|
/**
|
|
360
340
|
* Time Complexity: O(n)
|
|
361
341
|
* Space Complexity: O(log n)
|
|
342
|
+
*
|
|
343
|
+
* The function `isAVLBalanced` checks if a binary tree is AVL balanced using either a recursive or
|
|
344
|
+
* iterative approach.
|
|
345
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
346
|
+
* specifies the type of iteration to use when checking if the AVL tree is balanced. It has a default
|
|
347
|
+
* value of `this.iterationType`, which means it will use the iteration type specified in the current
|
|
348
|
+
* instance of the AVL tree.
|
|
349
|
+
* @returns a boolean value.
|
|
362
350
|
*/
|
|
351
|
+
isAVLBalanced(iterationType?: IterationType): boolean;
|
|
352
|
+
protected _DEFAULT_COMPARATOR: (a: K, b: K) => number;
|
|
353
|
+
protected _comparator: Comparator<K>;
|
|
363
354
|
/**
|
|
364
355
|
* Time Complexity: O(n)
|
|
365
356
|
* Space Complexity: O(log n)
|
|
366
|
-
*
|
|
367
|
-
* The function checks if a binary tree is AVL balanced using either recursive or iterative approach.
|
|
368
|
-
* @param iterationType - The `iterationType` parameter is used to determine the method of iteration
|
|
369
|
-
* to check if the AVL tree is balanced. It can have two possible values:
|
|
370
|
-
* @returns a boolean value.
|
|
371
357
|
*/
|
|
372
|
-
isAVLBalanced(iterationType?: IterationType): boolean;
|
|
373
358
|
/**
|
|
374
|
-
* The function
|
|
375
|
-
* @
|
|
376
|
-
|
|
359
|
+
* The function returns the value of the _comparator property.
|
|
360
|
+
* @returns The `_comparator` property is being returned.
|
|
361
|
+
*/
|
|
362
|
+
get comparator(): Comparator<K>;
|
|
363
|
+
/**
|
|
364
|
+
* The function sets the root of a tree-like structure and updates the parent property of the new
|
|
365
|
+
* root.
|
|
366
|
+
* @param {NODE | undefined} v - v is a parameter of type NODE or undefined.
|
|
377
367
|
*/
|
|
378
368
|
protected _setRoot(v: NODE | undefined): void;
|
|
379
369
|
}
|