queue-typed 1.51.5 → 1.51.8
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-multi-map.d.ts +3 -12
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +2 -10
- package/dist/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/data-structures/binary-tree/avl-tree.js +12 -14
- package/dist/data-structures/binary-tree/binary-tree.d.ts +7 -13
- package/dist/data-structures/binary-tree/binary-tree.js +46 -78
- package/dist/data-structures/binary-tree/bst.d.ts +51 -96
- package/dist/data-structures/binary-tree/bst.js +120 -218
- package/dist/data-structures/binary-tree/rb-tree.d.ts +3 -4
- package/dist/data-structures/binary-tree/rb-tree.js +4 -2
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
- package/dist/data-structures/binary-tree/tree-multi-map.js +1 -0
- package/dist/data-structures/heap/heap.d.ts +1 -3
- package/dist/interfaces/binary-tree.d.ts +3 -3
- package/dist/types/common.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +6 -5
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -3
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -2
- package/dist/types/utils/utils.d.ts +10 -1
- package/dist/utils/utils.d.ts +2 -1
- package/dist/utils/utils.js +29 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +5 -12
- package/src/data-structures/binary-tree/avl-tree.ts +15 -15
- package/src/data-structures/binary-tree/binary-tree.ts +56 -76
- package/src/data-structures/binary-tree/bst.ts +132 -224
- package/src/data-structures/binary-tree/rb-tree.ts +9 -6
- package/src/data-structures/binary-tree/tree-multi-map.ts +5 -3
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/interfaces/binary-tree.ts +4 -3
- package/src/types/common.ts +1 -1
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -2
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -2
- package/src/types/data-structures/binary-tree/binary-tree.ts +5 -5
- package/src/types/data-structures/binary-tree/bst.ts +6 -5
- package/src/types/data-structures/binary-tree/rb-tree.ts +4 -3
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -2
- package/src/types/utils/utils.ts +14 -1
- package/src/utils/utils.ts +20 -1
|
@@ -5,11 +5,10 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BSTNested, BSTNodeNested, BSTOptions, BTNCallback, KeyOrNodeOrEntry } from '../../types';
|
|
9
|
-
import { BSTNKeyOrNode, BSTVariant, CP, DFSOrderPattern, IterationType } from '../../types';
|
|
8
|
+
import type { BSTNested, BSTNKeyOrNode, BSTNodeNested, BSTOptions, BTNCallback, Comparable, Comparator, CP, DFSOrderPattern, IterationType, KeyOrNodeOrEntry } from '../../types';
|
|
10
9
|
import { BinaryTree, BinaryTreeNode } from './binary-tree';
|
|
11
10
|
import { IBinaryTree } from '../../interfaces';
|
|
12
|
-
export declare class BSTNode<K
|
|
11
|
+
export declare class BSTNode<K extends Comparable, V = any, NODE extends BSTNode<K, V, NODE> = BSTNodeNested<K, V>> extends BinaryTreeNode<K, V, NODE> {
|
|
13
12
|
parent?: NODE;
|
|
14
13
|
constructor(key: K, value?: V);
|
|
15
14
|
protected _left?: NODE;
|
|
@@ -47,12 +46,13 @@ export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE>
|
|
|
47
46
|
* 6. Balance Variability: Can become unbalanced; special types maintain balance.
|
|
48
47
|
* 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
|
|
49
48
|
*/
|
|
50
|
-
export declare class BST<K
|
|
49
|
+
export declare class BST<K extends Comparable, V = any, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, NODE, TREE> = BST<K, V, NODE, BSTNested<K, V, NODE>>> extends BinaryTree<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
|
|
51
50
|
/**
|
|
52
|
-
* This is the constructor function for a
|
|
53
|
-
*
|
|
54
|
-
* @param keysOrNodesOrEntries -
|
|
55
|
-
* to initialize the binary search tree with the provided
|
|
51
|
+
* This is the constructor function for a Binary Search Tree class in TypeScript, which initializes
|
|
52
|
+
* the tree with keys, nodes, or entries and optional options.
|
|
53
|
+
* @param keysOrNodesOrEntries - The `keysOrNodesOrEntries` parameter is an iterable object that can
|
|
54
|
+
* contain keys, nodes, or entries. It is used to initialize the binary search tree with the provided
|
|
55
|
+
* keys, nodes, or entries.
|
|
56
56
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
57
57
|
* configuration options for the binary search tree. It can have the following properties:
|
|
58
58
|
*/
|
|
@@ -63,12 +63,12 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
|
|
|
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
|
|
66
|
+
protected _comparator: Comparator<K>;
|
|
67
67
|
/**
|
|
68
|
-
* The function returns the value of the
|
|
69
|
-
* @returns The
|
|
68
|
+
* The function returns the value of the _comparator property.
|
|
69
|
+
* @returns The `_comparator` property is being returned.
|
|
70
70
|
*/
|
|
71
|
-
get
|
|
71
|
+
get comparator(): Comparator<K>;
|
|
72
72
|
/**
|
|
73
73
|
* The function creates a new BSTNode with the given key and value and returns it.
|
|
74
74
|
* @param {K} key - The key parameter is of type K, which represents the type of the key for the node
|
|
@@ -127,13 +127,11 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
|
|
|
127
127
|
* Time Complexity: O(log n)
|
|
128
128
|
* Space Complexity: O(1)
|
|
129
129
|
*
|
|
130
|
-
* The `add` function adds a new node to a binary tree
|
|
131
|
-
*
|
|
132
|
-
* @param keyOrNodeOrEntry -
|
|
133
|
-
* @param {V} [value] - The
|
|
134
|
-
*
|
|
135
|
-
* @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
|
|
136
|
-
* node was not added.
|
|
130
|
+
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value,
|
|
131
|
+
* updating the value if the key already exists.
|
|
132
|
+
* @param keyOrNodeOrEntry - It is a parameter that can accept three types of values:
|
|
133
|
+
* @param {V} [value] - The value to be added to the binary search tree.
|
|
134
|
+
* @returns The method returns a boolean value.
|
|
137
135
|
*/
|
|
138
136
|
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
|
|
139
137
|
/**
|
|
@@ -144,42 +142,26 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
|
|
|
144
142
|
* Time Complexity: O(k log n)
|
|
145
143
|
* Space Complexity: O(k + log n)
|
|
146
144
|
*
|
|
147
|
-
* The `addMany` function in TypeScript adds multiple keys or nodes to a
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
145
|
+
* The `addMany` function in TypeScript adds multiple keys or nodes to a data structure, balancing
|
|
146
|
+
* the structure if specified, and returns an array indicating whether each key or node was
|
|
147
|
+
* successfully inserted.
|
|
148
|
+
* @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries to be added to the
|
|
149
|
+
* data structure.
|
|
151
150
|
* @param [values] - An optional iterable of values to be associated with the keys or nodes being
|
|
152
151
|
* added. If provided, the values will be assigned to the corresponding keys or nodes in the same
|
|
153
152
|
* order. If not provided, undefined will be assigned as the value for each key or node.
|
|
154
|
-
* @param [isBalanceAdd=true] - A boolean flag indicating whether the
|
|
155
|
-
*
|
|
156
|
-
* algorithm. If set to false, the
|
|
157
|
-
*
|
|
158
|
-
* @param iterationType - The `iterationType` parameter is an optional parameter that
|
|
159
|
-
* type of iteration to use when adding multiple keys or nodes
|
|
160
|
-
* `this.iterationType`, which
|
|
161
|
-
*
|
|
153
|
+
* @param [isBalanceAdd=true] - A boolean flag indicating whether the tree should be balanced after
|
|
154
|
+
* adding the elements. If set to true, the tree will be balanced using a binary search tree
|
|
155
|
+
* algorithm. If set to false, the elements will be added without balancing the tree. The default
|
|
156
|
+
* value is true.
|
|
157
|
+
* @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 tree. It
|
|
159
|
+
* has a default value of `this.iterationType`, which means it will use the iteration type specified
|
|
160
|
+
* in the binary tree instance.
|
|
161
|
+
* @returns The function `addMany` returns an array of booleans indicating whether each key or node
|
|
162
|
+
* or entry was successfully inserted into the data structure.
|
|
162
163
|
*/
|
|
163
164
|
addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
|
|
164
|
-
/**
|
|
165
|
-
* Time Complexity: O(log n)
|
|
166
|
-
* Space Complexity: O(1)
|
|
167
|
-
*/
|
|
168
|
-
/**
|
|
169
|
-
* Time Complexity: O(log n)
|
|
170
|
-
* Space Complexity: O(1)
|
|
171
|
-
*
|
|
172
|
-
* The function `getNodeByKey` searches for a node in a binary tree based on a given key, using
|
|
173
|
-
* either recursive or iterative methods.
|
|
174
|
-
* @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
|
|
175
|
-
* It is used to identify the node that we want to retrieve.
|
|
176
|
-
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
177
|
-
* type of iteration to use when searching for a node in the binary tree. It can have two possible
|
|
178
|
-
* values:
|
|
179
|
-
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
|
|
180
|
-
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
181
|
-
*/
|
|
182
|
-
getNodeByKey(key: K, iterationType?: IterationType): NODE | undefined;
|
|
183
165
|
/**
|
|
184
166
|
* Time Complexity: O(log n)
|
|
185
167
|
* Space Complexity: O(k + log n)
|
|
@@ -235,6 +217,25 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
|
|
|
235
217
|
* @returns The method is returning a value of type `NODE | null | undefined`.
|
|
236
218
|
*/
|
|
237
219
|
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | undefined, callback?: C, beginRoot?: BSTNKeyOrNode<K, NODE>, iterationType?: IterationType): NODE | undefined;
|
|
220
|
+
/**
|
|
221
|
+
* Time Complexity: O(log n)
|
|
222
|
+
* Space Complexity: O(1)
|
|
223
|
+
*/
|
|
224
|
+
/**
|
|
225
|
+
* Time Complexity: O(log n)
|
|
226
|
+
* Space Complexity: O(1)
|
|
227
|
+
*
|
|
228
|
+
* The function `getNodeByKey` searches for a node in a binary tree based on a given key, using
|
|
229
|
+
* either recursive or iterative methods.
|
|
230
|
+
* @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
|
|
231
|
+
* It is used to identify the node that we want to retrieve.
|
|
232
|
+
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
233
|
+
* type of iteration to use when searching for a node in the binary tree. It can have two possible
|
|
234
|
+
* values:
|
|
235
|
+
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
|
|
236
|
+
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
237
|
+
*/
|
|
238
|
+
getNodeByKey(key: K, iterationType?: IterationType): NODE | undefined;
|
|
238
239
|
/**
|
|
239
240
|
* Time complexity: O(n)
|
|
240
241
|
* Space complexity: O(n)
|
|
@@ -304,24 +305,6 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
|
|
|
304
305
|
* function.
|
|
305
306
|
*/
|
|
306
307
|
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[][];
|
|
307
|
-
/**
|
|
308
|
-
* Time Complexity: O(log n)
|
|
309
|
-
* Space Complexity: O(1)
|
|
310
|
-
*/
|
|
311
|
-
/**
|
|
312
|
-
* Time Complexity: O(log n)
|
|
313
|
-
* Space Complexity: O(1)
|
|
314
|
-
*
|
|
315
|
-
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
|
|
316
|
-
* leftmost node if the comparison result is greater than.
|
|
317
|
-
* @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
|
|
318
|
-
* type `K`, `NODE`, or `undefined`. It represents the starting point for finding the last key in
|
|
319
|
-
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
|
|
320
|
-
* @returns the key of the rightmost node in the binary tree if the comparison result is less than,
|
|
321
|
-
* the key of the leftmost node if the comparison result is greater than, and the key of the
|
|
322
|
-
* rightmost node otherwise. If no node is found, it returns 0.
|
|
323
|
-
*/
|
|
324
|
-
lastKey(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): K | undefined;
|
|
325
308
|
/**
|
|
326
309
|
* Time Complexity: O(log n)
|
|
327
310
|
* Space Complexity: O(log n)
|
|
@@ -393,32 +376,4 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
|
|
|
393
376
|
* can either be an object of type `NODE` or it can be `undefined`.
|
|
394
377
|
*/
|
|
395
378
|
protected _setRoot(v: NODE | undefined): void;
|
|
396
|
-
/**
|
|
397
|
-
* The function compares two values using a comparator function and returns whether the first value
|
|
398
|
-
* is greater than, less than, or equal to the second value.
|
|
399
|
-
* @param {K} a - The parameter "a" is of type K.
|
|
400
|
-
* @param {K} b - The parameter "b" in the above code represents a K.
|
|
401
|
-
* @returns a value of type CP (ComparisonResult). The possible return values are 'GT' (greater
|
|
402
|
-
* than), 'LT' (less than), or 'EQ' (equal).
|
|
403
|
-
*/
|
|
404
|
-
protected _compare(a: K, b: K): CP;
|
|
405
|
-
/**
|
|
406
|
-
* The function `_lt` compares two values `a` and `b` using an extractor function and returns true if
|
|
407
|
-
* `a` is less than `b` based on the specified variant.
|
|
408
|
-
* @param {K} a - The parameter "a" is of type "K", which means it can be any type. It represents the
|
|
409
|
-
* first value to be compared in the function.
|
|
410
|
-
* @param {K} b - The parameter `b` is of type `K`, which means it can be any type. It is used as one
|
|
411
|
-
* of the arguments for the comparison in the `_lt` function.
|
|
412
|
-
* @returns a boolean value.
|
|
413
|
-
*/
|
|
414
|
-
protected _lt(a: K, b: K): boolean;
|
|
415
|
-
/**
|
|
416
|
-
* The function compares two values using a custom extractor function and returns true if the first
|
|
417
|
-
* value is greater than the second value.
|
|
418
|
-
* @param {K} a - The parameter "a" is of type K, which means it can be any type.
|
|
419
|
-
* @param {K} b - The parameter "b" is of type K, which means it can be any type. It is used as one
|
|
420
|
-
* of the arguments for the comparison in the function.
|
|
421
|
-
* @returns a boolean value.
|
|
422
|
-
*/
|
|
423
|
-
protected _gt(a: K, b: K): boolean;
|
|
424
379
|
}
|