data-structure-typed 1.47.7 → 1.47.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/CHANGELOG.md +1 -1
- package/README.md +98 -17
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +22 -17
- package/dist/cjs/data-structures/graph/abstract-graph.js +71 -30
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/cjs/data-structures/graph/directed-graph.js +29 -29
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/cjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/cjs/data-structures/queue/queue.js +13 -13
- package/dist/cjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/cjs/data-structures/stack/stack.js +7 -7
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +22 -17
- package/dist/mjs/data-structures/graph/abstract-graph.js +71 -30
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/mjs/data-structures/graph/directed-graph.js +29 -29
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/mjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/mjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/mjs/data-structures/queue/queue.js +13 -13
- package/dist/mjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/mjs/data-structures/stack/stack.js +7 -7
- package/dist/mjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/umd/data-structure-typed.js +203 -162
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/segment-tree.ts +10 -10
- package/src/data-structures/graph/abstract-graph.ts +92 -46
- package/src/data-structures/graph/directed-graph.ts +41 -41
- package/src/data-structures/graph/undirected-graph.ts +26 -26
- package/src/data-structures/linked-list/doubly-linked-list.ts +45 -45
- package/src/data-structures/linked-list/singly-linked-list.ts +38 -38
- package/src/data-structures/linked-list/skip-linked-list.ts +4 -4
- package/src/data-structures/queue/queue.ts +13 -13
- package/src/data-structures/stack/stack.ts +9 -9
- package/src/types/data-structures/graph/abstract-graph.ts +2 -2
- package/test/integration/index.html +102 -33
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
- package/test/unit/data-structures/graph/abstract-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/directed-graph.test.ts +51 -10
- package/test/unit/data-structures/graph/undirected-graph.test.ts +3 -3
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -3
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +1 -1
- package/test/unit/data-structures/stack/stack.test.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file.
|
|
|
8
8
|
- [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
|
|
9
9
|
- [`auto-changelog`](https://github.com/CookPete/auto-changelog)
|
|
10
10
|
|
|
11
|
-
## [v1.47.
|
|
11
|
+
## [v1.47.9](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
|
|
12
12
|
|
|
13
13
|
### Changes
|
|
14
14
|
|
package/README.md
CHANGED
|
@@ -308,65 +308,146 @@ const orgStrArr = ["trie", "trial", "trick", "trip", "tree", "trend", "triangle"
|
|
|
308
308
|
const entries = [[6, 6], [1, 1], [2, 2], [7, 7], [5, 5], [3, 3], [4, 4], [9, 9], [8, 8]];
|
|
309
309
|
|
|
310
310
|
const queue = new Queue(orgArr);
|
|
311
|
-
queue.print();
|
|
311
|
+
queue.print();
|
|
312
|
+
// [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
312
313
|
|
|
313
314
|
const deque = new Deque(orgArr);
|
|
314
|
-
deque.print();
|
|
315
|
+
deque.print();
|
|
316
|
+
// [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
315
317
|
|
|
316
318
|
const sList = new SinglyLinkedList(orgArr);
|
|
317
|
-
sList.print();
|
|
319
|
+
sList.print();
|
|
320
|
+
// [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
318
321
|
|
|
319
322
|
const dList = new DoublyLinkedList(orgArr);
|
|
320
|
-
dList.print();
|
|
323
|
+
dList.print();
|
|
324
|
+
// [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
321
325
|
|
|
322
326
|
const stack = new Stack(orgArr);
|
|
323
|
-
stack.print();
|
|
327
|
+
stack.print();
|
|
328
|
+
// [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
324
329
|
|
|
325
330
|
const minHeap = new MinHeap(orgArr);
|
|
326
|
-
minHeap.print();
|
|
331
|
+
minHeap.print();
|
|
332
|
+
// [1, 5, 2, 7, 6, 3, 4, 9, 8]
|
|
327
333
|
|
|
328
334
|
const maxPQ = new MaxPriorityQueue(orgArr);
|
|
329
|
-
maxPQ.print();
|
|
335
|
+
maxPQ.print();
|
|
336
|
+
// [9, 8, 4, 7, 5, 2, 3, 1, 6]
|
|
330
337
|
|
|
331
338
|
const biTree = new BinaryTree(entries);
|
|
332
339
|
biTree.print();
|
|
340
|
+
// ___6___
|
|
341
|
+
// / \
|
|
342
|
+
// ___1_ _2_
|
|
343
|
+
// / \ / \
|
|
344
|
+
// _7_ 5 3 4
|
|
345
|
+
// / \
|
|
346
|
+
// 9 8
|
|
333
347
|
|
|
334
348
|
const bst = new BST(entries);
|
|
335
349
|
bst.print();
|
|
350
|
+
// _____5___
|
|
351
|
+
// / \
|
|
352
|
+
// _2_ _7_
|
|
353
|
+
// / \ / \
|
|
354
|
+
// 1 3_ 6 8_
|
|
355
|
+
// \ \
|
|
356
|
+
// 4 9
|
|
357
|
+
|
|
336
358
|
|
|
337
359
|
const rbTree = new RedBlackTree(entries);
|
|
338
360
|
rbTree.print();
|
|
361
|
+
// ___4___
|
|
362
|
+
// / \
|
|
363
|
+
// _2_ _6___
|
|
364
|
+
// / \ / \
|
|
365
|
+
// 1 3 5 _8_
|
|
366
|
+
// / \
|
|
367
|
+
// 7 9
|
|
368
|
+
|
|
339
369
|
|
|
340
370
|
const avl = new AVLTree(entries);
|
|
341
371
|
avl.print();
|
|
372
|
+
// ___4___
|
|
373
|
+
// / \
|
|
374
|
+
// _2_ _6___
|
|
375
|
+
// / \ / \
|
|
376
|
+
// 1 3 5 _8_
|
|
377
|
+
// / \
|
|
378
|
+
// 7 9
|
|
342
379
|
|
|
343
380
|
const treeMulti = new TreeMultimap(entries);
|
|
344
381
|
treeMulti.print();
|
|
382
|
+
// ___4___
|
|
383
|
+
// / \
|
|
384
|
+
// _2_ _6___
|
|
385
|
+
// / \ / \
|
|
386
|
+
// 1 3 5 _8_
|
|
387
|
+
// / \
|
|
388
|
+
// 7 9
|
|
345
389
|
|
|
346
390
|
const hm = new HashMap(entries);
|
|
347
|
-
hm.print()
|
|
391
|
+
hm.print()
|
|
392
|
+
// [[6, 6], [1, 1], [2, 2], [7, 7], [5, 5], [3, 3], [4, 4], [9, 9], [8, 8]]
|
|
393
|
+
|
|
348
394
|
const rbTreeH = new RedBlackTree(hm);
|
|
349
395
|
rbTreeH.print();
|
|
396
|
+
// ___4___
|
|
397
|
+
// / \
|
|
398
|
+
// _2_ _6___
|
|
399
|
+
// / \ / \
|
|
400
|
+
// 1 3 5 _8_
|
|
401
|
+
// / \
|
|
402
|
+
// 7 9
|
|
350
403
|
|
|
351
404
|
const pq = new MinPriorityQueue(orgArr);
|
|
352
|
-
pq.print();
|
|
405
|
+
pq.print();
|
|
406
|
+
// [1, 5, 2, 7, 6, 3, 4, 9, 8]
|
|
407
|
+
|
|
353
408
|
const bst1 = new BST(pq);
|
|
354
409
|
bst1.print();
|
|
410
|
+
// _____5___
|
|
411
|
+
// / \
|
|
412
|
+
// _2_ _7_
|
|
413
|
+
// / \ / \
|
|
414
|
+
// 1 3_ 6 8_
|
|
415
|
+
// \ \
|
|
416
|
+
// 4 9
|
|
355
417
|
|
|
356
418
|
const dq1 = new Deque(orgArr);
|
|
357
|
-
dq1.print();
|
|
419
|
+
dq1.print();
|
|
420
|
+
// [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
358
421
|
const rbTree1 = new RedBlackTree(dq1);
|
|
359
422
|
rbTree1.print();
|
|
423
|
+
// _____5___
|
|
424
|
+
// / \
|
|
425
|
+
// _2___ _7___
|
|
426
|
+
// / \ / \
|
|
427
|
+
// 1 _4 6 _9
|
|
428
|
+
// / /
|
|
429
|
+
// 3 8
|
|
430
|
+
|
|
360
431
|
|
|
361
432
|
const trie2 = new Trie(orgStrArr);
|
|
362
|
-
trie2.print();
|
|
433
|
+
trie2.print();
|
|
434
|
+
// ['trie', 'trial', 'triangle', 'trick', 'trip', 'tree', 'trend', 'track', 'trace', 'transmit']
|
|
363
435
|
const heap2 = new Heap(trie2, { comparator: (a, b) => Number(a) - Number(b) });
|
|
364
|
-
heap2.print();
|
|
436
|
+
heap2.print();
|
|
437
|
+
// ['transmit', 'trace', 'tree', 'trend', 'track', 'trial', 'trip', 'trie', 'trick', 'triangle']
|
|
365
438
|
const dq2 = new Deque(heap2);
|
|
366
|
-
dq2.print();
|
|
439
|
+
dq2.print();
|
|
440
|
+
// ['transmit', 'trace', 'tree', 'trend', 'track', 'trial', 'trip', 'trie', 'trick', 'triangle']
|
|
367
441
|
const entries2 = dq2.map((el, i) => [i, el]);
|
|
368
442
|
const avl2 = new AVLTree(entries2);
|
|
369
443
|
avl2.print();
|
|
444
|
+
// ___3_______
|
|
445
|
+
// / \
|
|
446
|
+
// _1_ ___7_
|
|
447
|
+
// / \ / \
|
|
448
|
+
// 0 2 _5_ 8_
|
|
449
|
+
// / \ \
|
|
450
|
+
// 4 6 9
|
|
370
451
|
```
|
|
371
452
|
|
|
372
453
|
## API docs & Examples
|
|
@@ -379,7 +460,7 @@ avl2.print();
|
|
|
379
460
|
|
|
380
461
|
## Data Structures
|
|
381
462
|
|
|
382
|
-
<table>
|
|
463
|
+
<table style="display: table; width:100%; table-layout: fixed;">
|
|
383
464
|
<thead>
|
|
384
465
|
<tr>
|
|
385
466
|
<th>Data Structure</th>
|
|
@@ -520,7 +601,7 @@ avl2.print();
|
|
|
520
601
|
|
|
521
602
|
## Standard library data structure comparison
|
|
522
603
|
|
|
523
|
-
<table>
|
|
604
|
+
<table style="display: table; width:100%; table-layout: fixed;">
|
|
524
605
|
<thead>
|
|
525
606
|
<tr>
|
|
526
607
|
<th>Data Structure Typed</th>
|
|
@@ -752,7 +833,7 @@ avl2.print();
|
|
|
752
833
|
|
|
753
834
|
## Built-in classic algorithms
|
|
754
835
|
|
|
755
|
-
<table>
|
|
836
|
+
<table style="display: table; width:100%; table-layout: fixed;">
|
|
756
837
|
<thead>
|
|
757
838
|
<tr>
|
|
758
839
|
<th>Algorithm</th>
|
|
@@ -853,7 +934,7 @@ avl2.print();
|
|
|
853
934
|
|
|
854
935
|
## Software Engineering Design Standards
|
|
855
936
|
|
|
856
|
-
<table>
|
|
937
|
+
<table style="display: table; width:100%; table-layout: fixed;">
|
|
857
938
|
<tr>
|
|
858
939
|
<th>Principle</th>
|
|
859
940
|
<th>Description</th>
|
|
@@ -9,11 +9,11 @@ import type { SegmentTreeNodeVal } from '../../types';
|
|
|
9
9
|
export declare class SegmentTreeNode {
|
|
10
10
|
start: number;
|
|
11
11
|
end: number;
|
|
12
|
-
value: SegmentTreeNodeVal |
|
|
12
|
+
value: SegmentTreeNodeVal | undefined;
|
|
13
13
|
sum: number;
|
|
14
|
-
left: SegmentTreeNode |
|
|
15
|
-
right: SegmentTreeNode |
|
|
16
|
-
constructor(start: number, end: number, sum: number, value?: SegmentTreeNodeVal |
|
|
14
|
+
left: SegmentTreeNode | undefined;
|
|
15
|
+
right: SegmentTreeNode | undefined;
|
|
16
|
+
constructor(start: number, end: number, sum: number, value?: SegmentTreeNodeVal | undefined);
|
|
17
17
|
}
|
|
18
18
|
export declare class SegmentTree {
|
|
19
19
|
/**
|
|
@@ -32,8 +32,8 @@ export declare class SegmentTree {
|
|
|
32
32
|
get start(): number;
|
|
33
33
|
protected _end: number;
|
|
34
34
|
get end(): number;
|
|
35
|
-
protected _root: SegmentTreeNode |
|
|
36
|
-
get root(): SegmentTreeNode |
|
|
35
|
+
protected _root: SegmentTreeNode | undefined;
|
|
36
|
+
get root(): SegmentTreeNode | undefined;
|
|
37
37
|
/**
|
|
38
38
|
* The build function creates a segment tree by recursively dividing the given range into smaller segments and assigning
|
|
39
39
|
* the sum of values to each segment.
|
|
@@ -12,14 +12,14 @@ class SegmentTreeNode {
|
|
|
12
12
|
constructor(start, end, sum, value) {
|
|
13
13
|
this.start = 0;
|
|
14
14
|
this.end = 0;
|
|
15
|
-
this.value =
|
|
15
|
+
this.value = undefined;
|
|
16
16
|
this.sum = 0;
|
|
17
|
-
this.left =
|
|
18
|
-
this.right =
|
|
17
|
+
this.left = undefined;
|
|
18
|
+
this.right = undefined;
|
|
19
19
|
this.start = start;
|
|
20
20
|
this.end = end;
|
|
21
21
|
this.sum = sum;
|
|
22
|
-
this.value = value ||
|
|
22
|
+
this.value = value || undefined;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.SegmentTreeNode = SegmentTreeNode;
|
|
@@ -45,7 +45,7 @@ class SegmentTree {
|
|
|
45
45
|
this._root = this.build(start, end);
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
|
-
this._root =
|
|
48
|
+
this._root = undefined;
|
|
49
49
|
this._values = [];
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -96,7 +96,7 @@ class SegmentTree {
|
|
|
96
96
|
* @returns The function does not return anything.
|
|
97
97
|
*/
|
|
98
98
|
updateNode(index, sum, value) {
|
|
99
|
-
const root = this.root ||
|
|
99
|
+
const root = this.root || undefined;
|
|
100
100
|
if (!root) {
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
@@ -132,7 +132,7 @@ class SegmentTree {
|
|
|
132
132
|
* @returns The function `querySumByRange` returns a number.
|
|
133
133
|
*/
|
|
134
134
|
querySumByRange(indexA, indexB) {
|
|
135
|
-
const root = this.root ||
|
|
135
|
+
const root = this.root || undefined;
|
|
136
136
|
if (!root) {
|
|
137
137
|
return 0;
|
|
138
138
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segment-tree.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/segment-tree.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAIH,MAAa,eAAe;IAQ1B,YAAY,KAAa,EAAE,GAAW,EAAE,GAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"segment-tree.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/segment-tree.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAIH,MAAa,eAAe;IAQ1B,YAAY,KAAa,EAAE,GAAW,EAAE,GAAW,EAAE,KAAsC;QAP3F,UAAK,GAAG,CAAC,CAAC;QACV,QAAG,GAAG,CAAC,CAAC;QACR,UAAK,GAAmC,SAAS,CAAC;QAClD,QAAG,GAAG,CAAC,CAAC;QACR,SAAI,GAAgC,SAAS,CAAC;QAC9C,UAAK,GAAgC,SAAS,CAAC;QAG7C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,SAAS,CAAC;IAClC,CAAC;CACF;AAdD,0CAcC;AAED,MAAa,WAAW;IACtB;;;;;;;;OAQG;IACH,YAAY,MAAgB,EAAE,KAAc,EAAE,GAAY;QAehD,YAAO,GAAa,EAAE,CAAC;QAMvB,WAAM,GAAG,CAAC,CAAC;QApBnB,KAAK,GAAG,KAAK,IAAI,CAAC,CAAC;QACnB,GAAG,GAAG,GAAG,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAEhB,IAAI,MAAM,CAAC,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AAC,CAAC;gBACjB,IAAI,GAAG,CAAC,IAAI,EAAE;oBACZ,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;iBACjC;gBACD,IAAI,GAAG,CAAC,KAAK,EAAE;oBACb,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;iBACvC;gBACD,OAAO,OAAO,GAAG,QAAQ,CAAC;aAC3B;QACH,CAAC,CAAC;QACF,OAAO,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;CACF;AAnKD,kCAmKC"}
|
|
@@ -47,13 +47,13 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
47
47
|
* @param value
|
|
48
48
|
*/
|
|
49
49
|
abstract createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
|
|
50
|
-
abstract deleteEdge(edge: EO): EO |
|
|
51
|
-
abstract getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO |
|
|
50
|
+
abstract deleteEdge(edge: EO): EO | undefined;
|
|
51
|
+
abstract getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
|
|
52
52
|
abstract degreeOf(vertexOrKey: VO | VertexKey): number;
|
|
53
53
|
abstract edgeSet(): EO[];
|
|
54
54
|
abstract edgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
55
55
|
abstract getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
56
|
-
abstract getEndsOfEdge(edge: EO): [VO, VO] |
|
|
56
|
+
abstract getEndsOfEdge(edge: EO): [VO, VO] | undefined;
|
|
57
57
|
/**
|
|
58
58
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
59
59
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -62,13 +62,13 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
62
62
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
63
63
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
64
64
|
*
|
|
65
|
-
* The function "getVertex" returns the vertex with the specified ID or
|
|
65
|
+
* The function "getVertex" returns the vertex with the specified ID or undefined if it doesn't exist.
|
|
66
66
|
* @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
|
|
67
67
|
* the `_vertices` map.
|
|
68
68
|
* @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertices`
|
|
69
|
-
* map. If the vertex does not exist, it returns `
|
|
69
|
+
* map. If the vertex does not exist, it returns `undefined`.
|
|
70
70
|
*/
|
|
71
|
-
getVertex(vertexKey: VertexKey): VO |
|
|
71
|
+
getVertex(vertexKey: VertexKey): VO | undefined;
|
|
72
72
|
/**
|
|
73
73
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
74
74
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -201,7 +201,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
201
201
|
* vertices. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
|
|
202
202
|
* minimum number of
|
|
203
203
|
*/
|
|
204
|
-
getMinCostBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): number |
|
|
204
|
+
getMinCostBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): number | undefined;
|
|
205
205
|
/**
|
|
206
206
|
* Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
|
|
207
207
|
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
|
|
@@ -223,9 +223,9 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
223
223
|
* followed by iterative computation of the shortest path. This approach may result in exponential time complexity,
|
|
224
224
|
* so the default method is to use the Dijkstra algorithm to obtain the shortest weighted path.
|
|
225
225
|
* @returns The function `getMinPathBetween` returns an array of vertices (`VO[]`) representing the minimum path between
|
|
226
|
-
* two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `
|
|
226
|
+
* two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `undefined`.
|
|
227
227
|
*/
|
|
228
|
-
getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean, isDFS?: boolean): VO[] |
|
|
228
|
+
getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean, isDFS?: boolean): VO[] | undefined;
|
|
229
229
|
/**
|
|
230
230
|
* Dijkstra algorithm time: O(VE) space: O(VO + EO)
|
|
231
231
|
* /
|
|
@@ -242,9 +242,9 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
242
242
|
* a graph without using a heap data structure.
|
|
243
243
|
* @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
|
|
244
244
|
* vertex object or a vertex ID.
|
|
245
|
-
* @param {VO | VertexKey |
|
|
245
|
+
* @param {VO | VertexKey | undefined} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
|
|
246
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 `
|
|
247
|
+
* identifier. If no destination is provided, the value is set to `undefined`.
|
|
248
248
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
249
249
|
* distance from the source vertex to the destination vertex should be calculated and returned in the result. If
|
|
250
250
|
* `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
|
|
@@ -253,7 +253,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
253
253
|
* shortest paths from the source vertex to all other vertices in the graph. If `genPaths
|
|
254
254
|
* @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
|
|
255
255
|
*/
|
|
256
|
-
dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey |
|
|
256
|
+
dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
|
|
257
257
|
/**
|
|
258
258
|
* Dijkstra algorithm time: O(logVE) space: O(VO + EO)
|
|
259
259
|
*
|
|
@@ -276,7 +276,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
276
276
|
* optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
|
|
277
277
|
* @param {VO | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
|
|
278
278
|
* start. It can be either a vertex object or a vertex ID.
|
|
279
|
-
* @param {VO | VertexKey |
|
|
279
|
+
* @param {VO | VertexKey | undefined} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
|
|
280
280
|
* vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
|
|
281
281
|
* will calculate the shortest paths to all other vertices from the source vertex.
|
|
282
282
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
@@ -287,7 +287,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
287
287
|
* shortest paths from the source vertex to all other vertices in the graph. If `genPaths
|
|
288
288
|
* @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
|
|
289
289
|
*/
|
|
290
|
-
dijkstra(src: VO | VertexKey, dest?: VO | VertexKey |
|
|
290
|
+
dijkstra(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
|
|
291
291
|
/**
|
|
292
292
|
* Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
|
|
293
293
|
* Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
|
|
@@ -353,12 +353,12 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
353
353
|
* graph.
|
|
354
354
|
* @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
|
|
355
355
|
* property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
|
|
356
|
-
* `predecessor` property is a 2D array of vertices (or `
|
|
356
|
+
* `predecessor` property is a 2D array of vertices (or `undefined`) representing the predecessor vertices in the shortest
|
|
357
357
|
* path between vertices in the
|
|
358
358
|
*/
|
|
359
359
|
floydWarshall(): {
|
|
360
360
|
costs: number[][];
|
|
361
|
-
predecessor: (VO |
|
|
361
|
+
predecessor: (VO | undefined)[][];
|
|
362
362
|
};
|
|
363
363
|
/**
|
|
364
364
|
* Time Complexity: O(V + E) - Linear time (Tarjan's algorithm).
|
|
@@ -443,8 +443,13 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
443
443
|
* @returns the bridges found using the Tarjan algorithm.
|
|
444
444
|
*/
|
|
445
445
|
getBridges(): EO[];
|
|
446
|
+
[Symbol.iterator](): Iterator<[VertexKey, V | undefined]>;
|
|
447
|
+
forEach(callback: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => void): void;
|
|
448
|
+
filter(predicate: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => boolean): [VertexKey, V | undefined][];
|
|
449
|
+
map<T>(callback: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => T): T[];
|
|
450
|
+
reduce<T>(callback: (accumulator: T, entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => T, initialValue: T): T;
|
|
446
451
|
protected abstract _addEdgeOnly(edge: EO): boolean;
|
|
447
452
|
protected _addVertexOnly(newVertex: VO): boolean;
|
|
448
|
-
protected _getVertex(vertexOrKey: VertexKey | VO): VO |
|
|
453
|
+
protected _getVertex(vertexOrKey: VertexKey | VO): VO | undefined;
|
|
449
454
|
protected _getVertexKey(vertexOrKey: VO | VertexKey): VertexKey;
|
|
450
455
|
}
|