min-heap-typed 1.38.9 → 1.39.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 +2 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +8 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +17 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +86 -32
- package/dist/data-structures/binary-tree/binary-tree.js +8 -8
- package/dist/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/data-structures/binary-tree/bst.js +2 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +2 -2
- package/dist/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/data-structures/graph/abstract-graph.js +5 -5
- package/dist/data-structures/graph/directed-graph.d.ts +4 -4
- package/dist/data-structures/graph/directed-graph.js +6 -6
- package/dist/data-structures/graph/map-graph.d.ts +1 -1
- package/dist/data-structures/graph/map-graph.js +1 -1
- package/dist/data-structures/graph/undirected-graph.d.ts +3 -3
- package/dist/data-structures/graph/undirected-graph.js +4 -4
- package/dist/data-structures/heap/heap.d.ts +10 -5
- package/dist/data-structures/heap/heap.js +10 -10
- package/dist/data-structures/heap/max-heap.d.ts +4 -1
- package/dist/data-structures/heap/max-heap.js +9 -7
- package/dist/data-structures/heap/min-heap.d.ts +4 -1
- package/dist/data-structures/heap/min-heap.js +9 -7
- package/dist/data-structures/matrix/matrix2d.d.ts +1 -2
- package/dist/data-structures/matrix/matrix2d.js +3 -7
- package/dist/data-structures/matrix/vector2d.d.ts +0 -1
- package/dist/data-structures/matrix/vector2d.js +0 -1
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +4 -1
- package/dist/data-structures/priority-queue/max-priority-queue.js +9 -7
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +4 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js +9 -7
- package/dist/data-structures/priority-queue/priority-queue.d.ts +5 -2
- package/dist/data-structures/priority-queue/priority-queue.js +2 -2
- package/dist/interfaces/binary-tree.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
- package/dist/types/helpers.d.ts +1 -4
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +5 -4
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +21 -1
- package/src/data-structures/binary-tree/binary-tree.ts +37 -93
- package/src/data-structures/binary-tree/bst.ts +11 -17
- package/src/data-structures/binary-tree/rb-tree.ts +2 -1
- package/src/data-structures/binary-tree/tree-multiset.ts +4 -3
- package/src/data-structures/graph/abstract-graph.ts +16 -15
- package/src/data-structures/graph/directed-graph.ts +8 -7
- package/src/data-structures/graph/map-graph.ts +2 -2
- package/src/data-structures/graph/undirected-graph.ts +9 -8
- package/src/data-structures/hash/hash-map.ts +1 -1
- package/src/data-structures/hash/tree-map.ts +1 -2
- package/src/data-structures/hash/tree-set.ts +1 -2
- package/src/data-structures/heap/heap.ts +12 -12
- package/src/data-structures/heap/max-heap.ts +8 -6
- package/src/data-structures/heap/min-heap.ts +8 -6
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/matrix/matrix2d.ts +1 -3
- package/src/data-structures/matrix/vector2d.ts +1 -4
- package/src/data-structures/priority-queue/max-priority-queue.ts +8 -6
- package/src/data-structures/priority-queue/min-priority-queue.ts +8 -6
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/data-structures/queue/deque.ts +4 -5
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/interfaces/binary-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/binary-tree.ts +0 -4
- package/src/types/data-structures/matrix/navigator.ts +1 -1
- package/src/types/helpers.ts +1 -7
- package/src/types/utils/utils.ts +1 -1
- package/src/types/utils/validate-type.ts +2 -2
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
9
|
import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey } from '../../types';
|
|
10
|
-
import {
|
|
10
|
+
import { OneParamCallback } from '../../types';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
12
12
|
export declare class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
|
|
13
13
|
height: number;
|
|
@@ -53,7 +53,7 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
|
|
|
53
53
|
* `this._defaultCallbackByKey`
|
|
54
54
|
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
|
|
55
55
|
*/
|
|
56
|
-
delete<C extends
|
|
56
|
+
delete<C extends OneParamCallback<N>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeletedResult<N>[];
|
|
57
57
|
/**
|
|
58
58
|
* The function swaps the key, value, and height properties between two nodes in a binary tree.
|
|
59
59
|
* @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
|
|
@@ -69,6 +69,14 @@ export declare class BinaryIndexedTree {
|
|
|
69
69
|
* @returns The upperBound function is returning a number.
|
|
70
70
|
*/
|
|
71
71
|
upperBound(sum: number): number;
|
|
72
|
+
/**
|
|
73
|
+
* The function calculates the prefix sum of an array using a binary indexed tree.
|
|
74
|
+
* @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the
|
|
75
|
+
* array for which we want to calculate the prefix sum.
|
|
76
|
+
* @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index
|
|
77
|
+
* `i`.
|
|
78
|
+
*/
|
|
79
|
+
getPrefixSum(i: number): number;
|
|
72
80
|
/**
|
|
73
81
|
* The function returns the value of a specific index in a freqMap data structure, or a default value if
|
|
74
82
|
* the index is not found.
|
|
@@ -120,6 +120,23 @@ class BinaryIndexedTree {
|
|
|
120
120
|
}
|
|
121
121
|
return this._binarySearch(sum, (x, y) => x <= y);
|
|
122
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* The function calculates the prefix sum of an array using a binary indexed tree.
|
|
125
|
+
* @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the
|
|
126
|
+
* array for which we want to calculate the prefix sum.
|
|
127
|
+
* @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index
|
|
128
|
+
* `i`.
|
|
129
|
+
*/
|
|
130
|
+
getPrefixSum(i) {
|
|
131
|
+
this._checkIndex(i);
|
|
132
|
+
i++; // Convert to 1-based index
|
|
133
|
+
let sum = 0;
|
|
134
|
+
while (i > 0) {
|
|
135
|
+
sum += this._getFrequency(i);
|
|
136
|
+
i -= i & -i;
|
|
137
|
+
}
|
|
138
|
+
return sum;
|
|
139
|
+
}
|
|
123
140
|
/**
|
|
124
141
|
* The function returns the value of a specific index in a freqMap data structure, or a default value if
|
|
125
142
|
* the index is not found.
|
|
@@ -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 {
|
|
9
|
-
import { BinaryTreeDeletedResult,
|
|
8
|
+
import type { OneParamCallback, BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeOptions } from '../../types';
|
|
9
|
+
import { BinaryTreeDeletedResult, DFSOrderPattern, FamilyPosition, IterationType } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
/**
|
|
12
12
|
* Represents a node in a binary tree.
|
|
@@ -132,8 +132,21 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
132
132
|
* @returns The method is returning a boolean value.
|
|
133
133
|
*/
|
|
134
134
|
refill(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: Array<V>): boolean;
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
/**
|
|
136
|
+
* The `delete` function removes a node from a binary search tree and returns the deleted node along
|
|
137
|
+
* with the parent node that needs to be balanced.
|
|
138
|
+
* a key (`BinaryTreeNodeKey`). If it is a key, the function will find the corresponding node in the
|
|
139
|
+
* binary tree.
|
|
140
|
+
* @returns an array of `BinaryTreeDeletedResult<N>` objects.
|
|
141
|
+
* @param {ReturnType<C>} identifier - The `identifier` parameter is either a
|
|
142
|
+
* `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
|
|
143
|
+
* searching for. It can be a specific key value or any other property of the node.
|
|
144
|
+
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
145
|
+
* value. This value is compared with the `identifier` parameter to determine if the node should be
|
|
146
|
+
* included in the result. The `callback` parameter has a default value of
|
|
147
|
+
* `this._defaultCallbackByKey`, which
|
|
148
|
+
*/
|
|
149
|
+
delete<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C): BinaryTreeDeletedResult<N>[];
|
|
137
150
|
/**
|
|
138
151
|
* The function `getDepth` calculates the depth of a given node in a binary tree relative to a
|
|
139
152
|
* specified root node.
|
|
@@ -179,21 +192,62 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
179
192
|
* @returns The method is returning a boolean value.
|
|
180
193
|
*/
|
|
181
194
|
isPerfectlyBalanced(beginRoot?: N | null): boolean;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
/**
|
|
196
|
+
* The function `getNodes` returns an array of nodes that match a given node property, using either
|
|
197
|
+
* recursive or iterative traversal.
|
|
198
|
+
* @param {ReturnType<C>} identifier - The `identifier` parameter is either a
|
|
199
|
+
* `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
|
|
200
|
+
* searching for. It can be a specific key value or any other property of the node.
|
|
201
|
+
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
202
|
+
* value. This value is compared with the `identifier` parameter to determine if the node should be
|
|
203
|
+
* included in the result. The `callback` parameter has a default value of
|
|
204
|
+
* `this._defaultCallbackByKey`, which
|
|
205
|
+
* @param [onlyOne=false] - A boolean value indicating whether to stop searching after finding the
|
|
206
|
+
* first node that matches the identifier. If set to true, the function will return an array with
|
|
207
|
+
* only one element (or an empty array if no matching node is found). If set to false (default), the
|
|
208
|
+
* function will continue searching for all
|
|
209
|
+
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node from which the
|
|
210
|
+
* traversal of the binary tree will begin. It is optional and defaults to the root of the binary
|
|
211
|
+
* tree.
|
|
212
|
+
* @param iterationType - The `iterationType` parameter determines the type of iteration used to
|
|
213
|
+
* traverse the binary tree. It can have two possible values:
|
|
214
|
+
* @returns The function `getNodes` returns an array of nodes (`N[]`).
|
|
215
|
+
*/
|
|
216
|
+
getNodes<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
|
|
217
|
+
/**
|
|
218
|
+
* The function checks if a binary tree has a node with a given property or key.
|
|
219
|
+
* @param {BinaryTreeNodeKey | N} identifier - The `identifier` parameter is the key or value of
|
|
220
|
+
* the node that you want to find in the binary tree. It can be either a `BinaryTreeNodeKey` or a
|
|
221
|
+
* generic type `N`.
|
|
222
|
+
* @param callback - The `callback` parameter is a function that is used to determine whether a node
|
|
223
|
+
* matches the desired criteria. It takes a node as input and returns a boolean value indicating
|
|
224
|
+
* whether the node matches the criteria or not. The default callback function
|
|
225
|
+
* `this._defaultCallbackByKey` is used if no callback function is
|
|
226
|
+
* @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
|
|
227
|
+
* the node from which the search should begin. By default, it is set to `this.root`, which means the
|
|
228
|
+
* search will start from the root node of the binary tree. However, you can provide a different node
|
|
229
|
+
* as
|
|
230
|
+
* @param iterationType - The `iterationType` parameter specifies the type of iteration to be
|
|
231
|
+
* performed when searching for nodes in the binary tree. It can have one of the following values:
|
|
232
|
+
* @returns a boolean value.
|
|
233
|
+
*/
|
|
234
|
+
has<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, beginRoot?: N | null, iterationType?: IterationType): boolean;
|
|
235
|
+
/**
|
|
236
|
+
* The function `get` returns the first node in a binary tree that matches the given property or key.
|
|
237
|
+
* @param {BinaryTreeNodeKey | N} identifier - The `identifier` parameter is the key or value of
|
|
238
|
+
* the node that you want to find in the binary tree. It can be either a `BinaryTreeNodeKey` or `N`
|
|
239
|
+
* type.
|
|
240
|
+
* @param callback - The `callback` parameter is a function that is used to determine whether a node
|
|
241
|
+
* matches the desired criteria. It takes a node as input and returns a boolean value indicating
|
|
242
|
+
* whether the node matches the criteria or not. The default callback function
|
|
243
|
+
* (`this._defaultCallbackByKey`) is used if no callback function is
|
|
244
|
+
* @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
|
|
245
|
+
* the root node from which the search should begin.
|
|
246
|
+
* @param iterationType - The `iterationType` parameter specifies the type of iteration to be
|
|
247
|
+
* performed when searching for a node in the binary tree. It can have one of the following values:
|
|
248
|
+
* @returns either the found node (of type N) or null if no node is found.
|
|
249
|
+
*/
|
|
250
|
+
get<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, beginRoot?: N | null, iterationType?: IterationType): N | null;
|
|
197
251
|
/**
|
|
198
252
|
* The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
|
|
199
253
|
* up to the root node, with the option to reverse the order of the nodes.
|
|
@@ -238,7 +292,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
238
292
|
* possible values:
|
|
239
293
|
* @returns The function `isSubtreeBST` returns a boolean value.
|
|
240
294
|
*/
|
|
241
|
-
isSubtreeBST(beginRoot: N, iterationType?: IterationType): boolean;
|
|
295
|
+
isSubtreeBST(beginRoot: N | null, iterationType?: IterationType): boolean;
|
|
242
296
|
/**
|
|
243
297
|
* The function checks if a binary tree is a binary search tree.
|
|
244
298
|
* @param iterationType - The parameter "iterationType" is used to specify the type of iteration to
|
|
@@ -260,9 +314,9 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
260
314
|
* start from the root of the tree.
|
|
261
315
|
* @param iterationType - The `iterationType` parameter determines the type of traversal to be
|
|
262
316
|
* performed on the binary tree. It can have two possible values:
|
|
263
|
-
* @returns The function `subTreeTraverse` returns an array of `
|
|
317
|
+
* @returns The function `subTreeTraverse` returns an array of `ReturnType<OneParamCallback<N>>`.
|
|
264
318
|
*/
|
|
265
|
-
subTreeTraverse<C extends
|
|
319
|
+
subTreeTraverse<C extends OneParamCallback<N>>(callback?: C, beginRoot?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): ReturnType<C>[];
|
|
266
320
|
/**
|
|
267
321
|
* The `dfs` function performs a depth-first search traversal on a binary tree, executing a callback
|
|
268
322
|
* function on each node according to a specified order pattern.
|
|
@@ -276,23 +330,23 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
276
330
|
* is `null`, an empty array will be returned.
|
|
277
331
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
278
332
|
* iteration used in the depth-first search algorithm. It can have two possible values:
|
|
279
|
-
* @returns The function `dfs` returns an array of `
|
|
333
|
+
* @returns The function `dfs` returns an array of `ReturnType<OneParamCallback<N>>` values.
|
|
280
334
|
*/
|
|
281
|
-
dfs<C extends
|
|
335
|
+
dfs<C extends OneParamCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
|
|
282
336
|
/**
|
|
283
337
|
* The bfs function performs a breadth-first search traversal on a binary tree, executing a callback
|
|
284
338
|
* function on each node.
|
|
285
339
|
* @param callback - The `callback` parameter is a function that will be called for each node in the
|
|
286
340
|
* breadth-first search. It takes a node of type `N` as its argument and returns a value of type
|
|
287
|
-
* `
|
|
341
|
+
* `ReturnType<OneParamCallback<N>>`. The default value for this parameter is `this._defaultCallbackByKey
|
|
288
342
|
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
|
|
289
343
|
* search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
|
|
290
344
|
* will not be performed and an empty array will be returned.
|
|
291
345
|
* @param iterationType - The `iterationType` parameter determines the type of iteration to be used
|
|
292
346
|
* in the breadth-first search (BFS) algorithm. It can have two possible values:
|
|
293
|
-
* @returns The function `bfs` returns an array of `
|
|
347
|
+
* @returns The function `bfs` returns an array of `ReturnType<OneParamCallback<N>>[]`.
|
|
294
348
|
*/
|
|
295
|
-
bfs<C extends
|
|
349
|
+
bfs<C extends OneParamCallback<N>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
|
|
296
350
|
/**
|
|
297
351
|
* The `listLevels` function takes a binary tree node and a callback function, and returns an array
|
|
298
352
|
* of arrays representing the levels of the tree.
|
|
@@ -308,7 +362,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
308
362
|
* level in a binary tree. Each inner array contains the return type of the provided callback
|
|
309
363
|
* function `C` applied to the nodes at that level.
|
|
310
364
|
*/
|
|
311
|
-
listLevels<C extends
|
|
365
|
+
listLevels<C extends OneParamCallback<N>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[][];
|
|
312
366
|
/**
|
|
313
367
|
* The function returns the predecessor node of a given node in a binary tree.
|
|
314
368
|
* @param {N} node - The parameter "node" represents a node in a binary tree.
|
|
@@ -319,7 +373,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
319
373
|
* The `morris` function performs a depth-first traversal of a binary tree using the Morris traversal
|
|
320
374
|
* algorithm and returns an array of values obtained by applying a callback function to each node.
|
|
321
375
|
* @param callback - The `callback` parameter is a function that will be called on each node in the
|
|
322
|
-
* tree. It takes a node of type `N` as input and returns a value of type `
|
|
376
|
+
* tree. It takes a node of type `N` as input and returns a value of type `ReturnType<OneParamCallback<N>>`. The
|
|
323
377
|
* default value for this parameter is `this._defaultCallbackByKey`.
|
|
324
378
|
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
|
|
325
379
|
* determines the order in which the nodes of a binary tree are traversed. It can have one of the
|
|
@@ -327,9 +381,9 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
327
381
|
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the Morris
|
|
328
382
|
* traversal. It specifies the root node of the tree from which the traversal should begin. If
|
|
329
383
|
* `beginRoot` is `null`, an empty array will be returned.
|
|
330
|
-
* @returns The `morris` function returns an array of `
|
|
384
|
+
* @returns The `morris` function returns an array of `ReturnType<OneParamCallback<N>>` values.
|
|
331
385
|
*/
|
|
332
|
-
morris<C extends
|
|
386
|
+
morris<C extends OneParamCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null): ReturnType<C>[];
|
|
333
387
|
/**
|
|
334
388
|
* Swap the data of two nodes in the binary tree.
|
|
335
389
|
* @param {N} srcNode - The source node to swap.
|
|
@@ -344,7 +398,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
344
398
|
* the tree's structure should be restored to its original state to maintain the tree's integrity.
|
|
345
399
|
* This is because the purpose of the Morris algorithm is to save space rather than permanently alter the tree's shape.
|
|
346
400
|
*/
|
|
347
|
-
protected _defaultCallbackByKey:
|
|
401
|
+
protected _defaultCallbackByKey: OneParamCallback<N, BinaryTreeNodeKey>;
|
|
348
402
|
/**
|
|
349
403
|
* The function `_addTo` adds a new node to a binary tree if there is an available position.
|
|
350
404
|
* @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to
|
|
@@ -277,8 +277,8 @@ class BinaryTree {
|
|
|
277
277
|
let needBalanced = null, orgCurrent = curr;
|
|
278
278
|
if (!curr.left) {
|
|
279
279
|
if (!parent) {
|
|
280
|
-
|
|
281
|
-
|
|
280
|
+
// Handle the case when there's only one root node
|
|
281
|
+
this._setRoot(null);
|
|
282
282
|
}
|
|
283
283
|
else {
|
|
284
284
|
const { familyPosition: fp } = curr;
|
|
@@ -703,7 +703,7 @@ class BinaryTree {
|
|
|
703
703
|
* start from the root of the tree.
|
|
704
704
|
* @param iterationType - The `iterationType` parameter determines the type of traversal to be
|
|
705
705
|
* performed on the binary tree. It can have two possible values:
|
|
706
|
-
* @returns The function `subTreeTraverse` returns an array of `
|
|
706
|
+
* @returns The function `subTreeTraverse` returns an array of `ReturnType<OneParamCallback<N>>`.
|
|
707
707
|
*/
|
|
708
708
|
subTreeTraverse(callback = this._defaultCallbackByKey, beginRoot = this.root, iterationType = this.iterationType) {
|
|
709
709
|
if (typeof beginRoot === 'number')
|
|
@@ -743,7 +743,7 @@ class BinaryTree {
|
|
|
743
743
|
* is `null`, an empty array will be returned.
|
|
744
744
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
745
745
|
* iteration used in the depth-first search algorithm. It can have two possible values:
|
|
746
|
-
* @returns The function `dfs` returns an array of `
|
|
746
|
+
* @returns The function `dfs` returns an array of `ReturnType<OneParamCallback<N>>` values.
|
|
747
747
|
*/
|
|
748
748
|
dfs(callback = this._defaultCallbackByKey, pattern = 'in', beginRoot = this.root, iterationType = types_1.IterationType.ITERATIVE) {
|
|
749
749
|
if (!beginRoot)
|
|
@@ -820,13 +820,13 @@ class BinaryTree {
|
|
|
820
820
|
* function on each node.
|
|
821
821
|
* @param callback - The `callback` parameter is a function that will be called for each node in the
|
|
822
822
|
* breadth-first search. It takes a node of type `N` as its argument and returns a value of type
|
|
823
|
-
* `
|
|
823
|
+
* `ReturnType<OneParamCallback<N>>`. The default value for this parameter is `this._defaultCallbackByKey
|
|
824
824
|
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
|
|
825
825
|
* search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
|
|
826
826
|
* will not be performed and an empty array will be returned.
|
|
827
827
|
* @param iterationType - The `iterationType` parameter determines the type of iteration to be used
|
|
828
828
|
* in the breadth-first search (BFS) algorithm. It can have two possible values:
|
|
829
|
-
* @returns The function `bfs` returns an array of `
|
|
829
|
+
* @returns The function `bfs` returns an array of `ReturnType<OneParamCallback<N>>[]`.
|
|
830
830
|
*/
|
|
831
831
|
bfs(callback = this._defaultCallbackByKey, beginRoot = this.root, iterationType = this.iterationType) {
|
|
832
832
|
if (!beginRoot)
|
|
@@ -934,7 +934,7 @@ class BinaryTree {
|
|
|
934
934
|
* The `morris` function performs a depth-first traversal of a binary tree using the Morris traversal
|
|
935
935
|
* algorithm and returns an array of values obtained by applying a callback function to each node.
|
|
936
936
|
* @param callback - The `callback` parameter is a function that will be called on each node in the
|
|
937
|
-
* tree. It takes a node of type `N` as input and returns a value of type `
|
|
937
|
+
* tree. It takes a node of type `N` as input and returns a value of type `ReturnType<OneParamCallback<N>>`. The
|
|
938
938
|
* default value for this parameter is `this._defaultCallbackByKey`.
|
|
939
939
|
* @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
|
|
940
940
|
* determines the order in which the nodes of a binary tree are traversed. It can have one of the
|
|
@@ -942,7 +942,7 @@ class BinaryTree {
|
|
|
942
942
|
* @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the Morris
|
|
943
943
|
* traversal. It specifies the root node of the tree from which the traversal should begin. If
|
|
944
944
|
* `beginRoot` is `null`, an empty array will be returned.
|
|
945
|
-
* @returns The `morris` function returns an array of `
|
|
945
|
+
* @returns The `morris` function returns an array of `ReturnType<OneParamCallback<N>>` values.
|
|
946
946
|
*/
|
|
947
947
|
morris(callback = this._defaultCallbackByKey, pattern = 'in', beginRoot = this.root) {
|
|
948
948
|
if (beginRoot === null)
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeNodeKey, BSTComparator, BSTNodeNested, BSTOptions,
|
|
8
|
+
import type { BinaryTreeNodeKey, BSTComparator, BSTNodeNested, BSTOptions, OneParamCallback } from '../../types';
|
|
9
9
|
import { CP, IterationType } from '../../types';
|
|
10
10
|
import { BinaryTree, BinaryTreeNode } from './binary-tree';
|
|
11
11
|
import { IBinaryTree } from '../../interfaces';
|
|
@@ -59,7 +59,7 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
|
|
|
59
59
|
* callback.
|
|
60
60
|
* @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter is used to specify the
|
|
61
61
|
* property of the binary tree node that you want to search for. It can be either a specific key
|
|
62
|
-
* value (`BinaryTreeNodeKey`) or a custom callback function (`
|
|
62
|
+
* value (`BinaryTreeNodeKey`) or a custom callback function (`OneParamCallback<N>`) that determines
|
|
63
63
|
* whether a node matches the desired property.
|
|
64
64
|
* @param callback - The `callback` parameter is a function that is used to determine whether a node
|
|
65
65
|
* matches the desired property. It takes a node as input and returns a boolean value indicating
|
|
@@ -72,7 +72,7 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
|
|
|
72
72
|
* @returns either the first node that matches the given nodeProperty and callback, or null if no
|
|
73
73
|
* matching node is found.
|
|
74
74
|
*/
|
|
75
|
-
get<C extends
|
|
75
|
+
get<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, beginRoot?: N | null, iterationType?: IterationType): N | null;
|
|
76
76
|
/**
|
|
77
77
|
* The function `lastKey` returns the key of the rightmost node if the comparison result is less
|
|
78
78
|
* than, the key of the leftmost node if the comparison result is greater than, and the key of the
|
|
@@ -110,7 +110,7 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
|
|
|
110
110
|
* traverse the binary tree. It can have one of the following values:
|
|
111
111
|
* @returns an array of nodes (N[]).
|
|
112
112
|
*/
|
|
113
|
-
getNodes<C extends
|
|
113
|
+
getNodes<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
|
|
114
114
|
/**
|
|
115
115
|
* The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
|
|
116
116
|
* nodes that have a key value lesser or greater than a target key value.
|
|
@@ -126,9 +126,9 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
|
|
|
126
126
|
* (`BinaryTreeNodeKey`), or `null` to
|
|
127
127
|
* @param iterationType - The `iterationType` parameter determines whether the traversal should be
|
|
128
128
|
* done recursively or iteratively. It can have two possible values:
|
|
129
|
-
* @returns The function `lesserOrGreaterTraverse` returns an array of `
|
|
129
|
+
* @returns The function `lesserOrGreaterTraverse` returns an array of `ReturnType<OneParamCallback<N>>`.
|
|
130
130
|
*/
|
|
131
|
-
lesserOrGreaterTraverse<C extends
|
|
131
|
+
lesserOrGreaterTraverse<C extends OneParamCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): ReturnType<C>[];
|
|
132
132
|
/**
|
|
133
133
|
* Balancing Adjustment:
|
|
134
134
|
* Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
|
|
@@ -210,7 +210,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
210
210
|
* callback.
|
|
211
211
|
* @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter is used to specify the
|
|
212
212
|
* property of the binary tree node that you want to search for. It can be either a specific key
|
|
213
|
-
* value (`BinaryTreeNodeKey`) or a custom callback function (`
|
|
213
|
+
* value (`BinaryTreeNodeKey`) or a custom callback function (`OneParamCallback<N>`) that determines
|
|
214
214
|
* whether a node matches the desired property.
|
|
215
215
|
* @param callback - The `callback` parameter is a function that is used to determine whether a node
|
|
216
216
|
* matches the desired property. It takes a node as input and returns a boolean value indicating
|
|
@@ -343,7 +343,7 @@ class BST extends binary_tree_1.BinaryTree {
|
|
|
343
343
|
* (`BinaryTreeNodeKey`), or `null` to
|
|
344
344
|
* @param iterationType - The `iterationType` parameter determines whether the traversal should be
|
|
345
345
|
* done recursively or iteratively. It can have two possible values:
|
|
346
|
-
* @returns The function `lesserOrGreaterTraverse` returns an array of `
|
|
346
|
+
* @returns The function `lesserOrGreaterTraverse` returns an array of `ReturnType<OneParamCallback<N>>`.
|
|
347
347
|
*/
|
|
348
348
|
lesserOrGreaterTraverse(callback = this._defaultCallbackByKey, lesserOrGreater = types_1.CP.lt, targetNode = this.root, iterationType = this.iterationType) {
|
|
349
349
|
if (typeof targetNode === 'number')
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { BinaryTreeNodeKey, TreeMultisetNodeNested, TreeMultisetOptions } from '../../types';
|
|
9
|
-
import { BinaryTreeDeletedResult, IterationType,
|
|
9
|
+
import { BinaryTreeDeletedResult, IterationType, OneParamCallback } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
12
12
|
export declare class TreeMultisetNode<V = any, N extends TreeMultisetNode<V, N> = TreeMultisetNodeNested<V>> extends AVLTreeNode<V, N> {
|
|
@@ -105,7 +105,7 @@ export declare class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = Tr
|
|
|
105
105
|
* decremented by 1 and
|
|
106
106
|
* @returns The method `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
|
|
107
107
|
*/
|
|
108
|
-
delete<C extends
|
|
108
|
+
delete<C extends OneParamCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
109
109
|
/**
|
|
110
110
|
* The clear() function clears the contents of a data structure and sets the count to zero.
|
|
111
111
|
*/
|
|
@@ -65,7 +65,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
65
65
|
* @param val
|
|
66
66
|
*/
|
|
67
67
|
abstract createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): E;
|
|
68
|
-
abstract
|
|
68
|
+
abstract deleteEdge(edge: E): E | null;
|
|
69
69
|
abstract getEdge(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
|
|
70
70
|
abstract degreeOf(vertexOrKey: V | VertexKey): number;
|
|
71
71
|
abstract edgeSet(): E[];
|
|
@@ -90,12 +90,12 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
90
90
|
addVertex(vertex: V): boolean;
|
|
91
91
|
addVertex(key: VertexKey, val?: V['val']): boolean;
|
|
92
92
|
/**
|
|
93
|
-
* The `
|
|
93
|
+
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
94
94
|
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
|
|
95
95
|
* (`VertexKey`).
|
|
96
96
|
* @returns The method is returning a boolean value.
|
|
97
97
|
*/
|
|
98
|
-
|
|
98
|
+
deleteVertex(vertexOrKey: V | VertexKey): boolean;
|
|
99
99
|
/**
|
|
100
100
|
* The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
|
|
101
101
|
* @param {V[] | VertexKey[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
|
|
@@ -103,7 +103,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
103
103
|
* @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
|
|
104
104
|
* were removed.
|
|
105
105
|
*/
|
|
106
|
-
|
|
106
|
+
removeManyVertices(vertices: V[] | VertexKey[]): boolean;
|
|
107
107
|
/**
|
|
108
108
|
* The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
|
|
109
109
|
* @param {VertexKey | V} v1 - The parameter v1 can be either a VertexKey or a V. A VertexKey represents the unique
|
|
@@ -117,12 +117,12 @@ class AbstractGraph {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
|
-
* The `
|
|
120
|
+
* The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
121
121
|
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
|
|
122
122
|
* (`VertexKey`).
|
|
123
123
|
* @returns The method is returning a boolean value.
|
|
124
124
|
*/
|
|
125
|
-
|
|
125
|
+
deleteVertex(vertexOrKey) {
|
|
126
126
|
const vertexKey = this._getVertexKey(vertexOrKey);
|
|
127
127
|
return this._vertices.delete(vertexKey);
|
|
128
128
|
}
|
|
@@ -133,10 +133,10 @@ class AbstractGraph {
|
|
|
133
133
|
* @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
|
|
134
134
|
* were removed.
|
|
135
135
|
*/
|
|
136
|
-
|
|
136
|
+
removeManyVertices(vertices) {
|
|
137
137
|
const removed = [];
|
|
138
138
|
for (const v of vertices) {
|
|
139
|
-
removed.push(this.
|
|
139
|
+
removed.push(this.deleteVertex(v));
|
|
140
140
|
}
|
|
141
141
|
return removed.length > 0;
|
|
142
142
|
}
|
|
@@ -529,7 +529,7 @@ class AbstractGraph {
|
|
|
529
529
|
if (vertexOrKey instanceof AbstractVertex)
|
|
530
530
|
distMap.set(vertexOrKey, Infinity);
|
|
531
531
|
}
|
|
532
|
-
const heap = new priority_queue_1.PriorityQueue((a, b) => a.key - b.key);
|
|
532
|
+
const heap = new priority_queue_1.PriorityQueue({ comparator: (a, b) => a.key - b.key });
|
|
533
533
|
heap.add({ key: 0, val: srcVertex });
|
|
534
534
|
distMap.set(srcVertex, 0);
|
|
535
535
|
preMap.set(srcVertex, null);
|
|
@@ -84,14 +84,14 @@ export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVerte
|
|
|
84
84
|
* @param {V | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
|
|
85
85
|
* @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
|
|
86
86
|
*/
|
|
87
|
-
|
|
87
|
+
deleteEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
|
|
88
88
|
/**
|
|
89
89
|
* The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
|
|
90
90
|
* @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
|
|
91
91
|
* and `dest`, which represent the source and destination vertices of the edge, respectively.
|
|
92
|
-
* @returns The method `
|
|
92
|
+
* @returns The method `deleteEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
|
|
93
93
|
*/
|
|
94
|
-
|
|
94
|
+
deleteEdge(edge: E): E | null;
|
|
95
95
|
/**
|
|
96
96
|
* The function removes edges between two vertices and returns the removed edges.
|
|
97
97
|
* @param {VertexKey | V} v1 - The parameter `v1` can be either a `VertexKey` or a `V`. A `VertexKey` represents the
|
|
@@ -100,7 +100,7 @@ export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVerte
|
|
|
100
100
|
* the second vertex in the edge that needs to be removed.
|
|
101
101
|
* @returns an array of removed edges (E[]).
|
|
102
102
|
*/
|
|
103
|
-
|
|
103
|
+
deleteEdgesBetween(v1: VertexKey | V, v2: VertexKey | V): E[];
|
|
104
104
|
/**
|
|
105
105
|
* The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
|
|
106
106
|
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
|
|
@@ -130,7 +130,7 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
130
130
|
* @param {V | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
|
|
131
131
|
* @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
|
|
132
132
|
*/
|
|
133
|
-
|
|
133
|
+
deleteEdgeSrcToDest(srcOrKey, destOrKey) {
|
|
134
134
|
const src = this._getVertex(srcOrKey);
|
|
135
135
|
const dest = this._getVertex(destOrKey);
|
|
136
136
|
let removed = null;
|
|
@@ -151,9 +151,9 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
151
151
|
* The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
|
|
152
152
|
* @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
|
|
153
153
|
* and `dest`, which represent the source and destination vertices of the edge, respectively.
|
|
154
|
-
* @returns The method `
|
|
154
|
+
* @returns The method `deleteEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
|
|
155
155
|
*/
|
|
156
|
-
|
|
156
|
+
deleteEdge(edge) {
|
|
157
157
|
let removed = null;
|
|
158
158
|
const src = this._getVertex(edge.src);
|
|
159
159
|
const dest = this._getVertex(edge.dest);
|
|
@@ -177,11 +177,11 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
177
177
|
* the second vertex in the edge that needs to be removed.
|
|
178
178
|
* @returns an array of removed edges (E[]).
|
|
179
179
|
*/
|
|
180
|
-
|
|
180
|
+
deleteEdgesBetween(v1, v2) {
|
|
181
181
|
const removed = [];
|
|
182
182
|
if (v1 && v2) {
|
|
183
|
-
const v1ToV2 = this.
|
|
184
|
-
const v2ToV1 = this.
|
|
183
|
+
const v1ToV2 = this.deleteEdgeSrcToDest(v1, v2);
|
|
184
|
+
const v2ToV1 = this.deleteEdgeSrcToDest(v2, v1);
|
|
185
185
|
v1ToV2 && removed.push(v1ToV2);
|
|
186
186
|
v2ToV1 && removed.push(v2ToV1);
|
|
187
187
|
}
|
|
@@ -62,7 +62,7 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E exten
|
|
|
62
62
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
63
63
|
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
|
|
64
64
|
*/
|
|
65
|
-
createVertex(key: VertexKey,
|
|
65
|
+
createVertex(key: VertexKey, lat?: number, long?: number, val?: V['val']): V;
|
|
66
66
|
/**
|
|
67
67
|
* The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
|
|
68
68
|
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
@@ -89,7 +89,7 @@ class MapGraph extends directed_graph_1.DirectedGraph {
|
|
|
89
89
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
90
90
|
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
|
|
91
91
|
*/
|
|
92
|
-
createVertex(key,
|
|
92
|
+
createVertex(key, lat = this.origin[0], long = this.origin[1], val) {
|
|
93
93
|
return new MapVertex(key, lat, long, val);
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
@@ -71,13 +71,13 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
|
|
|
71
71
|
* (VertexKey). It represents the second vertex of the edge that needs to be removed.
|
|
72
72
|
* @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
|
|
73
73
|
*/
|
|
74
|
-
|
|
74
|
+
deleteEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null;
|
|
75
75
|
/**
|
|
76
|
-
* The
|
|
76
|
+
* The deleteEdge function removes an edge between two vertices in a graph.
|
|
77
77
|
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
78
78
|
* @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
|
|
79
79
|
*/
|
|
80
|
-
|
|
80
|
+
deleteEdge(edge: E): E | null;
|
|
81
81
|
/**
|
|
82
82
|
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
|
|
83
83
|
* vertex.
|
|
@@ -109,7 +109,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
109
109
|
* (VertexKey). It represents the second vertex of the edge that needs to be removed.
|
|
110
110
|
* @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
|
|
111
111
|
*/
|
|
112
|
-
|
|
112
|
+
deleteEdgeBetween(v1, v2) {
|
|
113
113
|
const vertex1 = this._getVertex(v1);
|
|
114
114
|
const vertex2 = this._getVertex(v2);
|
|
115
115
|
if (!vertex1 || !vertex2) {
|
|
@@ -127,12 +127,12 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
|
|
|
127
127
|
return removed;
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
|
-
* The
|
|
130
|
+
* The deleteEdge function removes an edge between two vertices in a graph.
|
|
131
131
|
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
132
132
|
* @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
|
|
133
133
|
*/
|
|
134
|
-
|
|
135
|
-
return this.
|
|
134
|
+
deleteEdge(edge) {
|
|
135
|
+
return this.deleteEdgeBetween(edge.vertices[0], edge.vertices[1]);
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
138
|
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
|