queue-typed 1.51.8 → 1.51.9
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 +104 -66
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
- package/dist/data-structures/binary-tree/avl-tree.d.ts +80 -60
- package/dist/data-structures/binary-tree/avl-tree.js +78 -59
- package/dist/data-structures/binary-tree/binary-tree.d.ts +316 -224
- package/dist/data-structures/binary-tree/binary-tree.js +471 -361
- package/dist/data-structures/binary-tree/bst.d.ts +198 -200
- package/dist/data-structures/binary-tree/bst.js +215 -249
- package/dist/data-structures/binary-tree/rb-tree.d.ts +71 -72
- package/dist/data-structures/binary-tree/rb-tree.js +107 -98
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +90 -73
- 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 +31 -38
- package/dist/data-structures/hash/hash-map.js +40 -55
- package/dist/data-structures/queue/deque.d.ts +2 -3
- package/dist/data-structures/queue/deque.js +2 -3
- package/dist/data-structures/trie/trie.d.ts +1 -1
- package/dist/data-structures/trie/trie.js +1 -1
- package/dist/interfaces/binary-tree.d.ts +6 -6
- package/dist/types/common.d.ts +1 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +5 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +4 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -3
- package/dist/utils/utils.js +3 -5
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +142 -92
- package/src/data-structures/binary-tree/avl-tree.ts +94 -66
- package/src/data-structures/binary-tree/binary-tree.ts +530 -398
- package/src/data-structures/binary-tree/bst.ts +251 -270
- package/src/data-structures/binary-tree/rb-tree.ts +121 -100
- package/src/data-structures/binary-tree/tree-multi-map.ts +125 -99
- package/src/data-structures/graph/abstract-graph.ts +10 -10
- package/src/data-structures/hash/hash-map.ts +42 -49
- package/src/data-structures/queue/deque.ts +2 -2
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/data-structures/trie/trie.ts +2 -2
- package/src/interfaces/binary-tree.ts +8 -7
- package/src/types/common.ts +1 -2
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -2
- package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/binary-tree.ts +5 -4
- package/src/types/data-structures/binary-tree/bst.ts +4 -4
- package/src/types/data-structures/binary-tree/rb-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -3
- package/src/utils/utils.ts +3 -3
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, Comparable, IterationType, KeyOrNodeOrEntry } from '../../types';
|
|
9
|
+
import { BTNEntry } from '../../types';
|
|
9
10
|
import { IBinaryTree } from '../../interfaces';
|
|
10
11
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
11
12
|
export declare class AVLTreeMultiMapNode<K extends Comparable, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
|
|
@@ -36,8 +37,16 @@ export declare class AVLTreeMultiMapNode<K extends Comparable, V = any, NODE ext
|
|
|
36
37
|
/**
|
|
37
38
|
* The only distinction between a AVLTreeMultiMap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
38
39
|
*/
|
|
39
|
-
export declare class AVLTreeMultiMap<K extends Comparable, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>, TREE extends AVLTreeMultiMap<K, V, NODE, TREE> = AVLTreeMultiMap<K, V, NODE, AVLTreeMultiMapNested<K, V, NODE>>> extends AVLTree<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
|
|
40
|
-
|
|
40
|
+
export declare class AVLTreeMultiMap<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>, TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMapNested<K, V, R, NODE>>> extends AVLTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
41
|
+
/**
|
|
42
|
+
* The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
|
|
43
|
+
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
|
|
44
|
+
* iterable object that can contain either keys, nodes, entries, or raw elements.
|
|
45
|
+
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
46
|
+
* behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
|
|
47
|
+
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
48
|
+
*/
|
|
49
|
+
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeMultiMapOptions<K, V, R>);
|
|
41
50
|
protected _count: number;
|
|
42
51
|
/**
|
|
43
52
|
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
@@ -59,35 +68,46 @@ export declare class AVLTreeMultiMap<K extends Comparable, V = any, NODE extends
|
|
|
59
68
|
*/
|
|
60
69
|
getComputedCount(): number;
|
|
61
70
|
/**
|
|
62
|
-
* The function creates a new
|
|
63
|
-
* @param {K} key - The key parameter
|
|
64
|
-
*
|
|
65
|
-
* @param {
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
71
|
+
* The function creates a new AVLTreeMultiMapNode with the specified key, value, and count.
|
|
72
|
+
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
73
|
+
* which is a generic type that can be replaced with any specific type when using the function.
|
|
74
|
+
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
75
|
+
* associated with the key in the node. It is of type `V`, which can be any data type.
|
|
76
|
+
* @param {number} [count] - The `count` parameter represents the number of occurrences of a
|
|
77
|
+
* key-value pair in the AVLTreeMultiMapNode. It is an optional parameter, so it can be omitted when
|
|
78
|
+
* calling the `createNode` method. If provided, it specifies the initial count for the node.
|
|
79
|
+
* @returns a new instance of the AVLTreeMultiMapNode class, casted as NODE.
|
|
69
80
|
*/
|
|
70
81
|
createNode(key: K, value?: V, count?: number): NODE;
|
|
71
|
-
createTree(options?: AVLTreeMultiMapOptions<K>): TREE;
|
|
72
|
-
/**
|
|
73
|
-
* The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
|
|
74
|
-
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, which means it
|
|
75
|
-
* can be one of the following:
|
|
76
|
-
* @param {V} [value] - The `value` parameter is an optional argument that represents the value
|
|
77
|
-
* associated with the node. It is of type `V`, which can be any data type. If no value is provided,
|
|
78
|
-
* it defaults to `undefined`.
|
|
79
|
-
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
80
|
-
* times the value should be added to the node. If not provided, it defaults to 1.
|
|
81
|
-
* @returns a node of type `NODE` or `undefined`.
|
|
82
|
-
*/
|
|
83
|
-
keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
|
|
84
82
|
/**
|
|
85
|
-
* The function
|
|
86
|
-
* @param
|
|
87
|
-
*
|
|
88
|
-
* class
|
|
83
|
+
* The function creates a new AVLTreeMultiMap object with the specified options and returns it.
|
|
84
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
85
|
+
* configuration options for creating the AVLTreeMultiMap. It can have the following properties:
|
|
86
|
+
* @returns a new instance of the AVLTreeMultiMap class, with the specified options, as a TREE
|
|
87
|
+
* object.
|
|
88
|
+
*/
|
|
89
|
+
createTree(options?: AVLTreeMultiMapOptions<K, V, R>): TREE;
|
|
90
|
+
/**
|
|
91
|
+
* The function checks if the input is an instance of AVLTreeMultiMapNode.
|
|
92
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
93
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
94
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
95
|
+
* an instance of the `AVLTreeMultiMapNode` class.
|
|
96
|
+
*/
|
|
97
|
+
isNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
|
|
98
|
+
/**
|
|
99
|
+
* The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
|
|
100
|
+
* a node object.
|
|
101
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
102
|
+
* `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
103
|
+
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
104
|
+
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
105
|
+
* value is provided, it will default to `undefined`.
|
|
106
|
+
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
107
|
+
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
108
|
+
* @returns either a NODE object or undefined.
|
|
89
109
|
*/
|
|
90
|
-
|
|
110
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
|
|
91
111
|
/**
|
|
92
112
|
* Time Complexity: O(log n)
|
|
93
113
|
* Space Complexity: O(1)
|
|
@@ -96,19 +116,20 @@ export declare class AVLTreeMultiMap<K extends Comparable, V = any, NODE extends
|
|
|
96
116
|
* Time Complexity: O(log n)
|
|
97
117
|
* Space Complexity: O(1)
|
|
98
118
|
*
|
|
99
|
-
* The function overrides the add method of a
|
|
100
|
-
*
|
|
101
|
-
*
|
|
119
|
+
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
120
|
+
* and update the count.
|
|
121
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
122
|
+
* `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which can be any type. It
|
|
123
|
+
* can also accept a value of type `KeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
|
|
124
|
+
* entry, or raw element
|
|
102
125
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
103
|
-
*
|
|
104
|
-
* method.
|
|
126
|
+
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
105
127
|
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
106
|
-
* be added to the
|
|
107
|
-
* added once. However, you can specify a different value for `count` if you want to add
|
|
108
|
-
* @returns
|
|
109
|
-
* was not successful.
|
|
128
|
+
* be added to the data structure. By default, it is set to 1, meaning that the key-value pair will
|
|
129
|
+
* be added once. However, you can specify a different value for `count` if you want to add
|
|
130
|
+
* @returns a boolean value.
|
|
110
131
|
*/
|
|
111
|
-
add(
|
|
132
|
+
add(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
|
|
112
133
|
/**
|
|
113
134
|
* Time Complexity: O(log n)
|
|
114
135
|
* Space Complexity: O(1)
|
|
@@ -117,19 +138,19 @@ export declare class AVLTreeMultiMap<K extends Comparable, V = any, NODE extends
|
|
|
117
138
|
* Time Complexity: O(log n)
|
|
118
139
|
* Space Complexity: O(1)
|
|
119
140
|
*
|
|
120
|
-
* The `delete` function in
|
|
121
|
-
*
|
|
122
|
-
* @param identifier - The identifier is the value
|
|
123
|
-
*
|
|
141
|
+
* The `delete` function in a binary tree data structure deletes a node based on its identifier and
|
|
142
|
+
* returns the deleted node along with the parent node that needs to be balanced.
|
|
143
|
+
* @param identifier - The identifier parameter is the value used to identify the node that needs to
|
|
144
|
+
* be deleted from the binary tree. It can be of any type and is the return type of the callback
|
|
124
145
|
* function.
|
|
125
|
-
* @param {C} callback - The `callback` parameter is a function that is used to determine
|
|
126
|
-
*
|
|
127
|
-
* function takes
|
|
128
|
-
*
|
|
146
|
+
* @param {C} callback - The `callback` parameter is a function that is used to determine the
|
|
147
|
+
* equality of nodes in the binary tree. It is optional and has a default value of
|
|
148
|
+
* `this._DEFAULT_CALLBACK`. The `callback` function takes a single argument, which is the identifier
|
|
149
|
+
* of a node, and returns a value that
|
|
129
150
|
* @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
|
|
130
151
|
* being deleted. If set to true, the count of the node will not be considered and the node will be
|
|
131
|
-
* deleted regardless of its count. If set to false (default), the count of the node will be
|
|
132
|
-
*
|
|
152
|
+
* deleted regardless of its count. If set to false (default), the count of the node will be taken
|
|
153
|
+
* into account and the node
|
|
133
154
|
* @returns an array of `BinaryTreeDeleteResult<NODE>`.
|
|
134
155
|
*/
|
|
135
156
|
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
|
|
@@ -141,7 +162,8 @@ export declare class AVLTreeMultiMap<K extends Comparable, V = any, NODE extends
|
|
|
141
162
|
* Time Complexity: O(1)
|
|
142
163
|
* Space Complexity: O(1)
|
|
143
164
|
*
|
|
144
|
-
* The clear
|
|
165
|
+
* The "clear" function overrides the parent class's "clear" function and also resets the count to
|
|
166
|
+
* zero.
|
|
145
167
|
*/
|
|
146
168
|
clear(): void;
|
|
147
169
|
/**
|
|
@@ -151,13 +173,14 @@ export declare class AVLTreeMultiMap<K extends Comparable, V = any, NODE extends
|
|
|
151
173
|
/**
|
|
152
174
|
* Time Complexity: O(n log n)
|
|
153
175
|
* Space Complexity: O(log n)
|
|
154
|
-
*
|
|
155
176
|
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
|
|
156
177
|
* tree using either a recursive or iterative approach.
|
|
157
|
-
* @param iterationType - The `iterationType` parameter is an optional parameter that
|
|
158
|
-
* type of iteration to use when building the balanced binary search tree. It
|
|
159
|
-
*
|
|
160
|
-
*
|
|
178
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
179
|
+
* specifies the type of iteration to use when building the balanced binary search tree. It has a
|
|
180
|
+
* default value of `this.iterationType`, which means it will use the iteration type currently set in
|
|
181
|
+
* the object.
|
|
182
|
+
* @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
|
|
183
|
+
* balancing operation is successful, and `false` if there are no nodes to balance.
|
|
161
184
|
*/
|
|
162
185
|
perfectlyBalance(iterationType?: IterationType): boolean;
|
|
163
186
|
/**
|
|
@@ -168,27 +191,42 @@ export declare class AVLTreeMultiMap<K extends Comparable, V = any, NODE extends
|
|
|
168
191
|
* Time complexity: O(n)
|
|
169
192
|
* Space complexity: O(n)
|
|
170
193
|
*
|
|
171
|
-
* The
|
|
194
|
+
* The function overrides the clone method to create a deep copy of a tree object.
|
|
172
195
|
* @returns The `clone()` method is returning a cloned instance of the `TREE` object.
|
|
173
196
|
*/
|
|
174
197
|
clone(): TREE;
|
|
175
198
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
199
|
+
* Time Complexity: O(1)
|
|
200
|
+
* Space Complexity: O(1)
|
|
201
|
+
*/
|
|
202
|
+
/**
|
|
203
|
+
* Time Complexity: O(1)
|
|
204
|
+
* Space Complexity: O(1)
|
|
205
|
+
*
|
|
206
|
+
* The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
|
|
207
|
+
* in a binary search tree.
|
|
208
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
|
|
209
|
+
* that will be swapped with the `destNode`.
|
|
210
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
|
|
211
|
+
* node where the properties will be swapped with the source node.
|
|
212
|
+
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
213
|
+
* If either `srcNode` or `destNode` is undefined, it returns `undefined`.
|
|
183
214
|
*/
|
|
184
|
-
protected _swapProperties(srcNode: BSTNKeyOrNode<K, NODE>, destNode: BSTNKeyOrNode<K, NODE>): NODE | undefined;
|
|
215
|
+
protected _swapProperties(srcNode: R | BSTNKeyOrNode<K, NODE>, destNode: R | BSTNKeyOrNode<K, NODE>): NODE | undefined;
|
|
185
216
|
/**
|
|
217
|
+
* Time Complexity: O(1)
|
|
218
|
+
* Space Complexity: O(1)
|
|
219
|
+
*/
|
|
220
|
+
/**
|
|
221
|
+
* Time Complexity: O(1)
|
|
222
|
+
* Space Complexity: O(1)
|
|
223
|
+
*
|
|
186
224
|
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
187
|
-
* @param {NODE} oldNode - The
|
|
188
|
-
*
|
|
189
|
-
* @param {NODE} newNode - The `newNode` parameter is an
|
|
225
|
+
* @param {NODE} oldNode - The oldNode parameter represents the node that needs to be replaced in the
|
|
226
|
+
* data structure. It is of type NODE.
|
|
227
|
+
* @param {NODE} newNode - The `newNode` parameter is an instance of the `NODE` class.
|
|
190
228
|
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
191
|
-
* superclass,
|
|
229
|
+
* superclass, which is of type `NODE`.
|
|
192
230
|
*/
|
|
193
231
|
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
|
|
194
232
|
}
|
|
@@ -39,13 +39,20 @@ exports.AVLTreeMultiMapNode = AVLTreeMultiMapNode;
|
|
|
39
39
|
* The only distinction between a AVLTreeMultiMap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
40
40
|
*/
|
|
41
41
|
class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
|
|
44
|
+
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
|
|
45
|
+
* iterable object that can contain either keys, nodes, entries, or raw elements.
|
|
46
|
+
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
47
|
+
* behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
|
|
48
|
+
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
49
|
+
*/
|
|
50
|
+
constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
|
|
43
51
|
super([], options);
|
|
44
52
|
this._count = 0;
|
|
45
|
-
if (
|
|
46
|
-
this.addMany(
|
|
53
|
+
if (keysOrNodesOrEntriesOrRawElements)
|
|
54
|
+
this.addMany(keysOrNodesOrEntriesOrRawElements);
|
|
47
55
|
}
|
|
48
|
-
// TODO the _count is not accurate after nodes count modified
|
|
49
56
|
/**
|
|
50
57
|
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
51
58
|
* search.
|
|
@@ -72,64 +79,71 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
72
79
|
return sum;
|
|
73
80
|
}
|
|
74
81
|
/**
|
|
75
|
-
* The function creates a new
|
|
76
|
-
* @param {K} key - The key parameter
|
|
77
|
-
*
|
|
78
|
-
* @param {
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
+
* The function creates a new AVLTreeMultiMapNode with the specified key, value, and count.
|
|
83
|
+
* @param {K} key - The key parameter represents the key of the node being created. It is of type K,
|
|
84
|
+
* which is a generic type that can be replaced with any specific type when using the function.
|
|
85
|
+
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
86
|
+
* associated with the key in the node. It is of type `V`, which can be any data type.
|
|
87
|
+
* @param {number} [count] - The `count` parameter represents the number of occurrences of a
|
|
88
|
+
* key-value pair in the AVLTreeMultiMapNode. It is an optional parameter, so it can be omitted when
|
|
89
|
+
* calling the `createNode` method. If provided, it specifies the initial count for the node.
|
|
90
|
+
* @returns a new instance of the AVLTreeMultiMapNode class, casted as NODE.
|
|
82
91
|
*/
|
|
83
92
|
createNode(key, value, count) {
|
|
84
93
|
return new AVLTreeMultiMapNode(key, value, count);
|
|
85
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* The function creates a new AVLTreeMultiMap object with the specified options and returns it.
|
|
97
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
98
|
+
* configuration options for creating the AVLTreeMultiMap. It can have the following properties:
|
|
99
|
+
* @returns a new instance of the AVLTreeMultiMap class, with the specified options, as a TREE
|
|
100
|
+
* object.
|
|
101
|
+
*/
|
|
86
102
|
createTree(options) {
|
|
87
103
|
return new AVLTreeMultiMap([], Object.assign({ iterationType: this.iterationType, comparator: this.comparator }, options));
|
|
88
104
|
}
|
|
89
105
|
/**
|
|
90
|
-
* The function
|
|
91
|
-
* @param
|
|
92
|
-
* can be
|
|
93
|
-
* @
|
|
94
|
-
*
|
|
95
|
-
|
|
106
|
+
* The function checks if the input is an instance of AVLTreeMultiMapNode.
|
|
107
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
108
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
109
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
110
|
+
* an instance of the `AVLTreeMultiMapNode` class.
|
|
111
|
+
*/
|
|
112
|
+
isNode(keyOrNodeOrEntryOrRawElement) {
|
|
113
|
+
return keyOrNodeOrEntryOrRawElement instanceof AVLTreeMultiMapNode;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
|
|
117
|
+
* a node object.
|
|
118
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
119
|
+
* `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
120
|
+
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
121
|
+
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
122
|
+
* value is provided, it will default to `undefined`.
|
|
96
123
|
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
97
|
-
* times the value should be added to the
|
|
98
|
-
* @returns a
|
|
124
|
+
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
125
|
+
* @returns either a NODE object or undefined.
|
|
99
126
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (keyOrNodeOrEntry === undefined || keyOrNodeOrEntry === null) {
|
|
127
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count = 1) {
|
|
128
|
+
if (keyOrNodeOrEntryOrRawElement === undefined || keyOrNodeOrEntryOrRawElement === null)
|
|
103
129
|
return;
|
|
130
|
+
if (this.isNode(keyOrNodeOrEntryOrRawElement))
|
|
131
|
+
return keyOrNodeOrEntryOrRawElement;
|
|
132
|
+
if (this.toEntryFn) {
|
|
133
|
+
const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement);
|
|
134
|
+
if (key)
|
|
135
|
+
return this.createNode(key, entryValue !== null && entryValue !== void 0 ? entryValue : value, count);
|
|
104
136
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
else if (this.isEntry(keyOrNodeOrEntry)) {
|
|
109
|
-
const [key, value] = keyOrNodeOrEntry;
|
|
110
|
-
if (key === undefined || key === null) {
|
|
137
|
+
if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
|
|
138
|
+
const [key, value] = keyOrNodeOrEntryOrRawElement;
|
|
139
|
+
if (key === undefined || key === null)
|
|
111
140
|
return;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
node = this.createNode(key, value, count);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
else if (!this.isNode(keyOrNodeOrEntry)) {
|
|
118
|
-
node = this.createNode(keyOrNodeOrEntry, value, count);
|
|
141
|
+
else
|
|
142
|
+
return this.createNode(key, value, count);
|
|
119
143
|
}
|
|
120
|
-
|
|
121
|
-
return;
|
|
122
|
-
|
|
123
|
-
return node;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* The function checks if an keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode class.
|
|
127
|
-
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
128
|
-
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode
|
|
129
|
-
* class.
|
|
130
|
-
*/
|
|
131
|
-
isNode(keyOrNodeOrEntry) {
|
|
132
|
-
return keyOrNodeOrEntry instanceof AVLTreeMultiMapNode;
|
|
144
|
+
if (this.isKey(keyOrNodeOrEntryOrRawElement))
|
|
145
|
+
return this.createNode(keyOrNodeOrEntryOrRawElement, value, count);
|
|
146
|
+
return;
|
|
133
147
|
}
|
|
134
148
|
/**
|
|
135
149
|
* Time Complexity: O(log n)
|
|
@@ -139,20 +153,21 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
139
153
|
* Time Complexity: O(log n)
|
|
140
154
|
* Space Complexity: O(1)
|
|
141
155
|
*
|
|
142
|
-
* The function overrides the add method of a
|
|
143
|
-
*
|
|
144
|
-
*
|
|
156
|
+
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
157
|
+
* and update the count.
|
|
158
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
159
|
+
* `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which can be any type. It
|
|
160
|
+
* can also accept a value of type `KeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
|
|
161
|
+
* entry, or raw element
|
|
145
162
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
146
|
-
*
|
|
147
|
-
* method.
|
|
163
|
+
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
148
164
|
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
149
|
-
* be added to the
|
|
150
|
-
* added once. However, you can specify a different value for `count` if you want to add
|
|
151
|
-
* @returns
|
|
152
|
-
* was not successful.
|
|
165
|
+
* be added to the data structure. By default, it is set to 1, meaning that the key-value pair will
|
|
166
|
+
* be added once. However, you can specify a different value for `count` if you want to add
|
|
167
|
+
* @returns a boolean value.
|
|
153
168
|
*/
|
|
154
|
-
add(
|
|
155
|
-
const newNode = this.
|
|
169
|
+
add(keyOrNodeOrEntryOrRawElement, value, count = 1) {
|
|
170
|
+
const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count);
|
|
156
171
|
if (newNode === undefined)
|
|
157
172
|
return false;
|
|
158
173
|
const orgNodeCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
|
|
@@ -170,19 +185,19 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
170
185
|
* Time Complexity: O(log n)
|
|
171
186
|
* Space Complexity: O(1)
|
|
172
187
|
*
|
|
173
|
-
* The `delete` function in
|
|
174
|
-
*
|
|
175
|
-
* @param identifier - The identifier is the value
|
|
176
|
-
*
|
|
188
|
+
* The `delete` function in a binary tree data structure deletes a node based on its identifier and
|
|
189
|
+
* returns the deleted node along with the parent node that needs to be balanced.
|
|
190
|
+
* @param identifier - The identifier parameter is the value used to identify the node that needs to
|
|
191
|
+
* be deleted from the binary tree. It can be of any type and is the return type of the callback
|
|
177
192
|
* function.
|
|
178
|
-
* @param {C} callback - The `callback` parameter is a function that is used to determine
|
|
179
|
-
*
|
|
180
|
-
* function takes
|
|
181
|
-
*
|
|
193
|
+
* @param {C} callback - The `callback` parameter is a function that is used to determine the
|
|
194
|
+
* equality of nodes in the binary tree. It is optional and has a default value of
|
|
195
|
+
* `this._DEFAULT_CALLBACK`. The `callback` function takes a single argument, which is the identifier
|
|
196
|
+
* of a node, and returns a value that
|
|
182
197
|
* @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
|
|
183
198
|
* being deleted. If set to true, the count of the node will not be considered and the node will be
|
|
184
|
-
* deleted regardless of its count. If set to false (default), the count of the node will be
|
|
185
|
-
*
|
|
199
|
+
* deleted regardless of its count. If set to false (default), the count of the node will be taken
|
|
200
|
+
* into account and the node
|
|
186
201
|
* @returns an array of `BinaryTreeDeleteResult<NODE>`.
|
|
187
202
|
*/
|
|
188
203
|
delete(identifier, callback = this._DEFAULT_CALLBACK, ignoreCount = false) {
|
|
@@ -252,7 +267,8 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
252
267
|
* Time Complexity: O(1)
|
|
253
268
|
* Space Complexity: O(1)
|
|
254
269
|
*
|
|
255
|
-
* The clear
|
|
270
|
+
* The "clear" function overrides the parent class's "clear" function and also resets the count to
|
|
271
|
+
* zero.
|
|
256
272
|
*/
|
|
257
273
|
clear() {
|
|
258
274
|
super.clear();
|
|
@@ -265,13 +281,14 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
265
281
|
/**
|
|
266
282
|
* Time Complexity: O(n log n)
|
|
267
283
|
* Space Complexity: O(log n)
|
|
268
|
-
*
|
|
269
284
|
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
|
|
270
285
|
* tree using either a recursive or iterative approach.
|
|
271
|
-
* @param iterationType - The `iterationType` parameter is an optional parameter that
|
|
272
|
-
* type of iteration to use when building the balanced binary search tree. It
|
|
273
|
-
*
|
|
274
|
-
*
|
|
286
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
287
|
+
* specifies the type of iteration to use when building the balanced binary search tree. It has a
|
|
288
|
+
* default value of `this.iterationType`, which means it will use the iteration type currently set in
|
|
289
|
+
* the object.
|
|
290
|
+
* @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
|
|
291
|
+
* balancing operation is successful, and `false` if there are no nodes to balance.
|
|
275
292
|
*/
|
|
276
293
|
perfectlyBalance(iterationType = this.iterationType) {
|
|
277
294
|
const sorted = this.dfs(node => node, 'IN'), n = sorted.length;
|
|
@@ -317,7 +334,7 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
317
334
|
* Time complexity: O(n)
|
|
318
335
|
* Space complexity: O(n)
|
|
319
336
|
*
|
|
320
|
-
* The
|
|
337
|
+
* The function overrides the clone method to create a deep copy of a tree object.
|
|
321
338
|
* @returns The `clone()` method is returning a cloned instance of the `TREE` object.
|
|
322
339
|
*/
|
|
323
340
|
clone() {
|
|
@@ -326,13 +343,21 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
326
343
|
return cloned;
|
|
327
344
|
}
|
|
328
345
|
/**
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
346
|
+
* Time Complexity: O(1)
|
|
347
|
+
* Space Complexity: O(1)
|
|
348
|
+
*/
|
|
349
|
+
/**
|
|
350
|
+
* Time Complexity: O(1)
|
|
351
|
+
* Space Complexity: O(1)
|
|
352
|
+
*
|
|
353
|
+
* The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
|
|
354
|
+
* in a binary search tree.
|
|
355
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
|
|
356
|
+
* that will be swapped with the `destNode`.
|
|
357
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
|
|
358
|
+
* node where the properties will be swapped with the source node.
|
|
359
|
+
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
360
|
+
* If either `srcNode` or `destNode` is undefined, it returns `undefined`.
|
|
336
361
|
*/
|
|
337
362
|
_swapProperties(srcNode, destNode) {
|
|
338
363
|
srcNode = this.ensureNode(srcNode);
|
|
@@ -356,12 +381,19 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
356
381
|
return undefined;
|
|
357
382
|
}
|
|
358
383
|
/**
|
|
384
|
+
* Time Complexity: O(1)
|
|
385
|
+
* Space Complexity: O(1)
|
|
386
|
+
*/
|
|
387
|
+
/**
|
|
388
|
+
* Time Complexity: O(1)
|
|
389
|
+
* Space Complexity: O(1)
|
|
390
|
+
*
|
|
359
391
|
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
360
|
-
* @param {NODE} oldNode - The
|
|
361
|
-
*
|
|
362
|
-
* @param {NODE} newNode - The `newNode` parameter is an
|
|
392
|
+
* @param {NODE} oldNode - The oldNode parameter represents the node that needs to be replaced in the
|
|
393
|
+
* data structure. It is of type NODE.
|
|
394
|
+
* @param {NODE} newNode - The `newNode` parameter is an instance of the `NODE` class.
|
|
363
395
|
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
364
|
-
* superclass,
|
|
396
|
+
* superclass, which is of type `NODE`.
|
|
365
397
|
*/
|
|
366
398
|
_replaceNode(oldNode, newNode) {
|
|
367
399
|
newNode.count = oldNode.count + newNode.count;
|