graph-typed 1.43.1 → 1.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -381,7 +381,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
381
381
  * @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
382
382
  * @returns a boolean value.
383
383
  */
384
- isNodeOrNull(node: any): node is (N | null);
384
+ isNodeOrNull(node: any): node is N | null;
385
385
  /**
386
386
  * The function "isNodeKey" checks if a potential key is a number.
387
387
  * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
@@ -439,6 +439,13 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
439
439
  * binary tree nodes in a specific order.
440
440
  */
441
441
  [Symbol.iterator](node?: N | null | undefined): Generator<BTNKey, void, undefined>;
442
+ /**
443
+ * The `print` function is used to display a binary tree structure in a visually appealing way.
444
+ * @param {N | null | undefined} root - The `root` parameter is of type `BTNKey | N | null |
445
+ * undefined`. It represents the root node of a binary tree. The root node can have one of the
446
+ * following types:
447
+ */
448
+ print(beginRoot?: BTNKey | N | null | undefined): void;
442
449
  protected _defaultOneParamCallback: (node: N) => number;
443
450
  /**
444
451
  * Swap the data of two nodes in the binary tree.
@@ -466,11 +473,4 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
466
473
  * type `N` or `null`.
467
474
  */
468
475
  protected _setRoot(v: N | null | undefined): void;
469
- /**
470
- * The `print` function is used to display a binary tree structure in a visually appealing way.
471
- * @param {N | null | undefined} root - The `root` parameter is of type `BTNKey | N | null |
472
- * undefined`. It represents the root node of a binary tree. The root node can have one of the
473
- * following types:
474
- */
475
- print(beginRoot?: BTNKey | N | null | undefined): void;
476
476
  }
@@ -1445,6 +1445,68 @@ class BinaryTree {
1445
1445
  }
1446
1446
  }
1447
1447
  }
1448
+ /**
1449
+ * The `print` function is used to display a binary tree structure in a visually appealing way.
1450
+ * @param {N | null | undefined} root - The `root` parameter is of type `BTNKey | N | null |
1451
+ * undefined`. It represents the root node of a binary tree. The root node can have one of the
1452
+ * following types:
1453
+ */
1454
+ print(beginRoot = this.root) {
1455
+ beginRoot = this.ensureNotKey(beginRoot);
1456
+ if (!beginRoot)
1457
+ return;
1458
+ const display = (root) => {
1459
+ const [lines, , ,] = _displayAux(root);
1460
+ for (const line of lines) {
1461
+ console.log(line);
1462
+ }
1463
+ };
1464
+ const _displayAux = (node) => {
1465
+ if (!this.isRealNode(node)) {
1466
+ return [[], 0, 0, 0];
1467
+ }
1468
+ if (this.isRealNode(node) && !this.isRealNode(node.right) && !this.isRealNode(node.left)) {
1469
+ const line = `${node.key}`;
1470
+ const width = line.length;
1471
+ const height = 1;
1472
+ const middle = Math.floor(width / 2);
1473
+ return [[line], width, height, middle];
1474
+ }
1475
+ if (this.isRealNode(node) && !this.isRealNode(node.right)) {
1476
+ const [lines, n, p, x] = _displayAux(node.left);
1477
+ const s = `${node.key}`;
1478
+ const u = s.length;
1479
+ const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s;
1480
+ const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u);
1481
+ const shifted_lines = lines.map(line => line + ' '.repeat(u));
1482
+ return [[first_line, second_line, ...shifted_lines], n + u, p + 2, n + Math.floor(u / 2)];
1483
+ }
1484
+ if (this.isRealNode(node) && !this.isRealNode(node.left)) {
1485
+ const [lines, n, p, u] = _displayAux(node.right);
1486
+ const s = `${node.key}`;
1487
+ const x = s.length;
1488
+ const first_line = s + '_'.repeat(x) + ' '.repeat(n - x);
1489
+ const second_line = ' '.repeat(u + x) + '\\' + ' '.repeat(n - x - 1);
1490
+ const shifted_lines = lines.map(line => ' '.repeat(u) + line);
1491
+ return [[first_line, second_line, ...shifted_lines], n + x, p + 2, Math.floor(u / 2)];
1492
+ }
1493
+ const [left, n, p, x] = _displayAux(node.left);
1494
+ const [right, m, q, y] = _displayAux(node.right);
1495
+ const s = `${node.key}`;
1496
+ const u = s.length;
1497
+ const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s + '_'.repeat(y) + ' '.repeat(m - y);
1498
+ const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u + y) + '\\' + ' '.repeat(m - y - 1);
1499
+ if (p < q) {
1500
+ left.push(...new Array(q - p).fill(' '.repeat(n)));
1501
+ }
1502
+ else if (q < p) {
1503
+ right.push(...new Array(p - q).fill(' '.repeat(m)));
1504
+ }
1505
+ const zipped_lines = left.map((a, i) => a + ' '.repeat(u) + right[i]);
1506
+ return [[first_line, second_line, ...zipped_lines], n + m + u, Math.max(p, q) + 2, n + Math.floor(u / 2)];
1507
+ };
1508
+ display(beginRoot);
1509
+ }
1448
1510
  /**
1449
1511
  * Swap the data of two nodes in the binary tree.
1450
1512
  * @param {N} srcNode - The source node to swap.
@@ -1518,67 +1580,5 @@ class BinaryTree {
1518
1580
  }
1519
1581
  this._root = v;
1520
1582
  }
1521
- /**
1522
- * The `print` function is used to display a binary tree structure in a visually appealing way.
1523
- * @param {N | null | undefined} root - The `root` parameter is of type `BTNKey | N | null |
1524
- * undefined`. It represents the root node of a binary tree. The root node can have one of the
1525
- * following types:
1526
- */
1527
- print(beginRoot = this.root) {
1528
- beginRoot = this.ensureNotKey(beginRoot);
1529
- if (!beginRoot)
1530
- return;
1531
- const display = (root) => {
1532
- const [lines, , ,] = _displayAux(root);
1533
- for (const line of lines) {
1534
- console.log(line);
1535
- }
1536
- };
1537
- const _displayAux = (node) => {
1538
- if (!this.isRealNode(node)) {
1539
- return [[], 0, 0, 0];
1540
- }
1541
- if (this.isRealNode(node) && !this.isRealNode(node.right) && !this.isRealNode(node.left)) {
1542
- const line = `${node.key}`;
1543
- const width = line.length;
1544
- const height = 1;
1545
- const middle = Math.floor(width / 2);
1546
- return [[line], width, height, middle];
1547
- }
1548
- if (this.isRealNode(node) && !this.isRealNode(node.right)) {
1549
- const [lines, n, p, x] = _displayAux(node.left);
1550
- const s = `${node.key}`;
1551
- const u = s.length;
1552
- const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s;
1553
- const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u);
1554
- const shifted_lines = lines.map(line => line + ' '.repeat(u));
1555
- return [[first_line, second_line, ...shifted_lines], n + u, p + 2, n + Math.floor(u / 2)];
1556
- }
1557
- if (this.isRealNode(node) && !this.isRealNode(node.left)) {
1558
- const [lines, n, p, u] = _displayAux(node.right);
1559
- const s = `${node.key}`;
1560
- const x = s.length;
1561
- const first_line = s + '_'.repeat(x) + ' '.repeat(n - x);
1562
- const second_line = ' '.repeat(u + x) + '\\' + ' '.repeat(n - x - 1);
1563
- const shifted_lines = lines.map(line => ' '.repeat(u) + line);
1564
- return [[first_line, second_line, ...shifted_lines], n + x, p + 2, Math.floor(u / 2)];
1565
- }
1566
- const [left, n, p, x] = _displayAux(node.left);
1567
- const [right, m, q, y] = _displayAux(node.right);
1568
- const s = `${node.key}`;
1569
- const u = s.length;
1570
- const first_line = ' '.repeat(x + 1) + '_'.repeat(n - x - 1) + s + '_'.repeat(y) + ' '.repeat(m - y);
1571
- const second_line = ' '.repeat(x) + '/' + ' '.repeat(n - x - 1 + u + y) + '\\' + ' '.repeat(m - y - 1);
1572
- if (p < q) {
1573
- left.push(...new Array(q - p).fill(' '.repeat(n)));
1574
- }
1575
- else if (q < p) {
1576
- right.push(...new Array(p - q).fill(' '.repeat(m)));
1577
- }
1578
- const zipped_lines = left.map((a, i) => a + ' '.repeat(u) + right[i]);
1579
- return [[first_line, second_line, ...zipped_lines], n + m + u, Math.max(p, q) + 2, n + Math.floor(u / 2)];
1580
- };
1581
- display(beginRoot);
1582
- }
1583
1583
  }
1584
1584
  exports.BinaryTree = BinaryTree;
@@ -5,9 +5,9 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { BiTreeDeleteResult, BTNCallback, BTNKey, IterationType, RBTNColor, RedBlackTreeNodeNested, RBTreeOptions } from '../../types';
9
- import { BST, BSTNode } from "./bst";
10
- import { IBinaryTree } from "../../interfaces";
8
+ import { BiTreeDeleteResult, BTNCallback, BTNKey, IterationType, RBTNColor, RBTreeOptions, RedBlackTreeNodeNested } from '../../types';
9
+ import { BST, BSTNode } from './bst';
10
+ import { IBinaryTree } from '../../interfaces';
11
11
  export declare class RedBlackTreeNode<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTreeNodeNested<V>> extends BSTNode<V, N> {
12
12
  color: RBTNColor;
13
13
  constructor(key: BTNKey, value?: V, color?: RBTNColor);
@@ -20,6 +20,7 @@ export declare class RedBlackTreeNode<V = any, N extends RedBlackTreeNode<V, N>
20
20
  * 5. Black balance: Every path from any node to each of its leaf nodes contains the same number of black nodes.
21
21
  */
22
22
  export declare class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTreeNode<V, RedBlackTreeNodeNested<V>>> extends BST<V, N> implements IBinaryTree<V, N> {
23
+ NIL: N;
23
24
  /**
24
25
  * The constructor function initializes a Red-Black Tree with an optional set of options.
25
26
  * @param {RBTreeOptions} [options] - The `options` parameter is an optional object that can be
@@ -30,7 +31,6 @@ export declare class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = Re
30
31
  get root(): N;
31
32
  protected _size: number;
32
33
  get size(): number;
33
- NIL: N;
34
34
  /**
35
35
  * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
36
36
  * Space Complexity: O(1)
@@ -33,8 +33,8 @@ class RedBlackTree extends bst_1.BST {
33
33
  */
34
34
  constructor(options) {
35
35
  super(options);
36
- this._size = 0;
37
36
  this.NIL = new RedBlackTreeNode(NaN);
37
+ this._size = 0;
38
38
  this._root = this.NIL;
39
39
  }
40
40
  get root() {
@@ -69,26 +69,6 @@ export declare class TreeMultimap<V = any, N extends TreeMultimapNode<V, N> = Tr
69
69
  * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
70
70
  * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
71
71
  */
72
- /**
73
- * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
74
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
75
- *
76
- * The function adds a new node to a binary tree, either as the left child or the right child of a
77
- * given parent node.
78
- * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be
79
- * added to the binary tree. It can be of type `N` (which represents a node in the binary tree) or
80
- * `undefined` if there is no node to add.
81
- * @param {BTNKey | N | undefined} parent - The `parent` parameter represents the parent node to
82
- * which the new node will be added as a child. It can be either a node object (`N`) or a key value
83
- * (`BTNKey`).
84
- * @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was
85
- * added, or `undefined` if no node was added.
86
- */
87
- protected _addTo(newNode: N | undefined, parent: BTNKey | N | undefined): N | undefined;
88
- /**
89
- * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each.
90
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
91
- */
92
72
  /**
93
73
  * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each.
94
74
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
@@ -104,8 +84,8 @@ export declare class TreeMultimap<V = any, N extends TreeMultimapNode<V, N> = Tr
104
84
  */
105
85
  addMany(keysOrNodes: (BTNKey | N | undefined)[], data?: V[]): (N | undefined)[];
106
86
  /**
107
- * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
108
- * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes.
87
+ * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each.
88
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
109
89
  */
110
90
  /**
111
91
  * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
@@ -120,8 +100,8 @@ export declare class TreeMultimap<V = any, N extends TreeMultimapNode<V, N> = Tr
120
100
  */
121
101
  perfectlyBalance(iterationType?: IterationType): boolean;
122
102
  /**
123
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity.
124
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
103
+ * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
104
+ * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes.
125
105
  */
126
106
  /**
127
107
  * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity.
@@ -143,10 +123,30 @@ export declare class TreeMultimap<V = any, N extends TreeMultimapNode<V, N> = Tr
143
123
  * @returns an array of `BiTreeDeleteResult<N>`.
144
124
  */
145
125
  delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BiTreeDeleteResult<N>[];
126
+ /**
127
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity.
128
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
129
+ */
146
130
  /**
147
131
  * The clear() function clears the contents of a data structure and sets the count to zero.
148
132
  */
149
133
  clear(): void;
134
+ /**
135
+ * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
136
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
137
+ *
138
+ * The function adds a new node to a binary tree, either as the left child or the right child of a
139
+ * given parent node.
140
+ * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be
141
+ * added to the binary tree. It can be of type `N` (which represents a node in the binary tree) or
142
+ * `undefined` if there is no node to add.
143
+ * @param {BTNKey | N | undefined} parent - The `parent` parameter represents the parent node to
144
+ * which the new node will be added as a child. It can be either a node object (`N`) or a key value
145
+ * (`BTNKey`).
146
+ * @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was
147
+ * added, or `undefined` if no node was added.
148
+ */
149
+ protected _addTo(newNode: N | undefined, parent: BTNKey | N | undefined): N | undefined;
150
150
  /**
151
151
  * The `_swap` function swaps the key, value, count, and height properties between two nodes.
152
152
  * @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node from
@@ -150,52 +150,6 @@ class TreeMultimap extends avl_tree_1.AVLTree {
150
150
  * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
151
151
  * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
152
152
  */
153
- /**
154
- * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
155
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
156
- *
157
- * The function adds a new node to a binary tree, either as the left child or the right child of a
158
- * given parent node.
159
- * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be
160
- * added to the binary tree. It can be of type `N` (which represents a node in the binary tree) or
161
- * `undefined` if there is no node to add.
162
- * @param {BTNKey | N | undefined} parent - The `parent` parameter represents the parent node to
163
- * which the new node will be added as a child. It can be either a node object (`N`) or a key value
164
- * (`BTNKey`).
165
- * @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was
166
- * added, or `undefined` if no node was added.
167
- */
168
- _addTo(newNode, parent) {
169
- parent = this.ensureNotKey(parent);
170
- if (parent) {
171
- if (parent.left === undefined) {
172
- parent.left = newNode;
173
- if (newNode !== undefined) {
174
- this._size = this.size + 1;
175
- this._count += newNode.count;
176
- }
177
- return parent.left;
178
- }
179
- else if (parent.right === undefined) {
180
- parent.right = newNode;
181
- if (newNode !== undefined) {
182
- this._size = this.size + 1;
183
- this._count += newNode.count;
184
- }
185
- return parent.right;
186
- }
187
- else {
188
- return;
189
- }
190
- }
191
- else {
192
- return;
193
- }
194
- }
195
- /**
196
- * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each.
197
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
198
- */
199
153
  /**
200
154
  * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each.
201
155
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
@@ -226,8 +180,8 @@ class TreeMultimap extends avl_tree_1.AVLTree {
226
180
  return inserted;
227
181
  }
228
182
  /**
229
- * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
230
- * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes.
183
+ * Time Complexity: O(k log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each.
184
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
231
185
  */
232
186
  /**
233
187
  * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
@@ -277,8 +231,8 @@ class TreeMultimap extends avl_tree_1.AVLTree {
277
231
  }
278
232
  }
279
233
  /**
280
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity.
281
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
234
+ * Time Complexity: O(n log n) - logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node.
235
+ * Space Complexity: O(n) - linear space, as it creates an array to store the sorted nodes.
282
236
  */
283
237
  /**
284
238
  * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity.
@@ -357,6 +311,10 @@ class TreeMultimap extends avl_tree_1.AVLTree {
357
311
  }
358
312
  return deletedResult;
359
313
  }
314
+ /**
315
+ * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (AVLTree) has logarithmic time complexity.
316
+ * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
317
+ */
360
318
  /**
361
319
  * The clear() function clears the contents of a data structure and sets the count to zero.
362
320
  */
@@ -364,6 +322,48 @@ class TreeMultimap extends avl_tree_1.AVLTree {
364
322
  super.clear();
365
323
  this._count = 0;
366
324
  }
325
+ /**
326
+ * Time Complexity: O(1) - constant time, as it performs basic pointer assignments.
327
+ * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
328
+ *
329
+ * The function adds a new node to a binary tree, either as the left child or the right child of a
330
+ * given parent node.
331
+ * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be
332
+ * added to the binary tree. It can be of type `N` (which represents a node in the binary tree) or
333
+ * `undefined` if there is no node to add.
334
+ * @param {BTNKey | N | undefined} parent - The `parent` parameter represents the parent node to
335
+ * which the new node will be added as a child. It can be either a node object (`N`) or a key value
336
+ * (`BTNKey`).
337
+ * @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was
338
+ * added, or `undefined` if no node was added.
339
+ */
340
+ _addTo(newNode, parent) {
341
+ parent = this.ensureNotKey(parent);
342
+ if (parent) {
343
+ if (parent.left === undefined) {
344
+ parent.left = newNode;
345
+ if (newNode !== undefined) {
346
+ this._size = this.size + 1;
347
+ this._count += newNode.count;
348
+ }
349
+ return parent.left;
350
+ }
351
+ else if (parent.right === undefined) {
352
+ parent.right = newNode;
353
+ if (newNode !== undefined) {
354
+ this._size = this.size + 1;
355
+ this._count += newNode.count;
356
+ }
357
+ return parent.right;
358
+ }
359
+ else {
360
+ return;
361
+ }
362
+ }
363
+ else {
364
+ return;
365
+ }
366
+ }
367
367
  /**
368
368
  * The `_swap` function swaps the key, value, count, and height properties between two nodes.
369
369
  * @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node from
@@ -235,24 +235,24 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
235
235
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
236
236
  */
237
237
  /**
238
- * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
239
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
240
- *
241
- * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
242
- * a graph without using a heap data structure.
243
- * @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
244
- * vertex object or a vertex ID.
245
- * @param {VO | VertexKey | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
246
- * parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
247
- * identifier. If no destination is provided, the value is set to `null`.
248
- * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
249
- * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
250
- * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
251
- * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
252
- * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
253
- * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
254
- * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
255
- */
238
+ * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
239
+ * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
240
+ *
241
+ * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
242
+ * a graph without using a heap data structure.
243
+ * @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
244
+ * vertex object or a vertex ID.
245
+ * @param {VO | VertexKey | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
246
+ * parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
247
+ * identifier. If no destination is provided, the value is set to `null`.
248
+ * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
249
+ * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
250
+ * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
251
+ * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
252
+ * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
253
+ * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
254
+ * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
255
+ */
256
256
  dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
257
257
  /**
258
258
  * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
@@ -268,25 +268,25 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
268
268
  * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
269
269
  */
270
270
  /**
271
- * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
272
- * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
273
- *
274
- * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
275
- * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
276
- * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
277
- * @param {VO | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
278
- * start. It can be either a vertex object or a vertex ID.
279
- * @param {VO | VertexKey | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
280
- * vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
281
- * will calculate the shortest paths to all other vertices from the source vertex.
282
- * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
283
- * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
284
- * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
285
- * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
286
- * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
287
- * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
288
- * @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
289
- */
271
+ * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
272
+ * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
273
+ *
274
+ * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
275
+ * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
276
+ * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
277
+ * @param {VO | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
278
+ * start. It can be either a vertex object or a vertex ID.
279
+ * @param {VO | VertexKey | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
280
+ * vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
281
+ * will calculate the shortest paths to all other vertices from the source vertex.
282
+ * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
283
+ * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
284
+ * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
285
+ * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
286
+ * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
287
+ * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
288
+ * @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
289
+ */
290
290
  dijkstra(src: VO | VertexKey, dest?: VO | VertexKey | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
291
291
  /**
292
292
  * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
@@ -416,24 +416,24 @@ class AbstractGraph {
416
416
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
417
417
  */
418
418
  /**
419
- * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
420
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
421
- *
422
- * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
423
- * a graph without using a heap data structure.
424
- * @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
425
- * vertex object or a vertex ID.
426
- * @param {VO | VertexKey | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
427
- * parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
428
- * identifier. If no destination is provided, the value is set to `null`.
429
- * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
430
- * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
431
- * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
432
- * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
433
- * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
434
- * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
435
- * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
436
- */
419
+ * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
420
+ * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
421
+ *
422
+ * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
423
+ * a graph without using a heap data structure.
424
+ * @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
425
+ * vertex object or a vertex ID.
426
+ * @param {VO | VertexKey | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
427
+ * parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
428
+ * identifier. If no destination is provided, the value is set to `null`.
429
+ * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
430
+ * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
431
+ * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
432
+ * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
433
+ * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
434
+ * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
435
+ * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
436
+ */
437
437
  dijkstraWithoutHeap(src, dest, getMinDist, genPaths) {
438
438
  if (getMinDist === undefined)
439
439
  getMinDist = false;
@@ -550,25 +550,25 @@ class AbstractGraph {
550
550
  * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
551
551
  */
552
552
  /**
553
- * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
554
- * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
555
- *
556
- * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
557
- * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
558
- * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
559
- * @param {VO | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
560
- * start. It can be either a vertex object or a vertex ID.
561
- * @param {VO | VertexKey | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
562
- * vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
563
- * will calculate the shortest paths to all other vertices from the source vertex.
564
- * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
565
- * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
566
- * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
567
- * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
568
- * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
569
- * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
570
- * @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
571
- */
553
+ * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
554
+ * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
555
+ *
556
+ * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
557
+ * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
558
+ * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
559
+ * @param {VO | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
560
+ * start. It can be either a vertex object or a vertex ID.
561
+ * @param {VO | VertexKey | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
562
+ * vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
563
+ * will calculate the shortest paths to all other vertices from the source vertex.
564
+ * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
565
+ * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
566
+ * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
567
+ * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
568
+ * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
569
+ * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
570
+ * @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
571
+ */
572
572
  dijkstra(src, dest, getMinDist, genPaths) {
573
573
  var _a;
574
574
  if (getMinDist === undefined)
@@ -1,5 +1,5 @@
1
1
  import { BinaryTreeNode } from '../data-structures';
2
- import { BiTreeDeleteResult, BinaryTreeNodeNested, BTNCallback, BTNKey } from '../types';
2
+ import { BinaryTreeNodeNested, BiTreeDeleteResult, BTNCallback, BTNKey } from '../types';
3
3
  export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>> {
4
4
  createNode(key: BTNKey, value?: N['value']): N;
5
5
  add(keyOrNode: BTNKey | N | null, value?: N['value']): N | null | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graph-typed",
3
- "version": "1.43.1",
3
+ "version": "1.44.0",
4
4
  "description": "Graph. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -136,6 +136,6 @@
136
136
  "typescript": "^4.9.5"
137
137
  },
138
138
  "dependencies": {
139
- "data-structure-typed": "^1.43.1"
139
+ "data-structure-typed": "^1.44.0"
140
140
  }
141
141
  }