data-structure-typed 1.47.7 → 1.47.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +17 -17
- package/dist/cjs/data-structures/graph/abstract-graph.js +30 -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 +28 -28
- 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 +17 -17
- package/dist/mjs/data-structures/graph/abstract-graph.js +30 -30
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/mjs/data-structures/graph/directed-graph.js +28 -28
- 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 +161 -161
- 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 +46 -46
- package/src/data-structures/graph/directed-graph.ts +40 -40
- 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 +10 -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.8](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).
|
|
@@ -445,6 +445,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
445
445
|
getBridges(): EO[];
|
|
446
446
|
protected abstract _addEdgeOnly(edge: EO): boolean;
|
|
447
447
|
protected _addVertexOnly(newVertex: VO): boolean;
|
|
448
|
-
protected _getVertex(vertexOrKey: VertexKey | VO): VO |
|
|
448
|
+
protected _getVertex(vertexOrKey: VertexKey | VO): VO | undefined;
|
|
449
449
|
protected _getVertexKey(vertexOrKey: VO | VertexKey): VertexKey;
|
|
450
450
|
}
|
|
@@ -60,14 +60,14 @@ class AbstractGraph {
|
|
|
60
60
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
61
61
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
62
62
|
*
|
|
63
|
-
* The function "getVertex" returns the vertex with the specified ID or
|
|
63
|
+
* The function "getVertex" returns the vertex with the specified ID or undefined if it doesn't exist.
|
|
64
64
|
* @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
|
|
65
65
|
* the `_vertices` map.
|
|
66
66
|
* @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertices`
|
|
67
|
-
* map. If the vertex does not exist, it returns `
|
|
67
|
+
* map. If the vertex does not exist, it returns `undefined`.
|
|
68
68
|
*/
|
|
69
69
|
getVertex(vertexKey) {
|
|
70
|
-
return this._vertices.get(vertexKey) ||
|
|
70
|
+
return this._vertices.get(vertexKey) || undefined;
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
@@ -305,7 +305,7 @@ class AbstractGraph {
|
|
|
305
305
|
const vertex2 = this._getVertex(v2);
|
|
306
306
|
const vertex1 = this._getVertex(v1);
|
|
307
307
|
if (!(vertex1 && vertex2)) {
|
|
308
|
-
return
|
|
308
|
+
return undefined;
|
|
309
309
|
}
|
|
310
310
|
const visited = new Map();
|
|
311
311
|
const queue = new queue_1.Queue([vertex1]);
|
|
@@ -330,7 +330,7 @@ class AbstractGraph {
|
|
|
330
330
|
}
|
|
331
331
|
cost++;
|
|
332
332
|
}
|
|
333
|
-
return
|
|
333
|
+
return undefined;
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
/**
|
|
@@ -354,7 +354,7 @@ class AbstractGraph {
|
|
|
354
354
|
* followed by iterative computation of the shortest path. This approach may result in exponential time complexity,
|
|
355
355
|
* so the default method is to use the Dijkstra algorithm to obtain the shortest weighted path.
|
|
356
356
|
* @returns The function `getMinPathBetween` returns an array of vertices (`VO[]`) representing the minimum path between
|
|
357
|
-
* two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `
|
|
357
|
+
* two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `undefined`.
|
|
358
358
|
*/
|
|
359
359
|
getMinPathBetween(v1, v2, isWeight, isDFS = false) {
|
|
360
360
|
var _a, _b;
|
|
@@ -374,7 +374,7 @@ class AbstractGraph {
|
|
|
374
374
|
}
|
|
375
375
|
index++;
|
|
376
376
|
}
|
|
377
|
-
return allPaths[minIndex] ||
|
|
377
|
+
return allPaths[minIndex] || undefined;
|
|
378
378
|
}
|
|
379
379
|
else {
|
|
380
380
|
return (_b = (_a = this.dijkstra(v1, v2, true, true)) === null || _a === void 0 ? void 0 : _a.minPath) !== null && _b !== void 0 ? _b : [];
|
|
@@ -423,9 +423,9 @@ class AbstractGraph {
|
|
|
423
423
|
* a graph without using a heap data structure.
|
|
424
424
|
* @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
|
|
425
425
|
* vertex object or a vertex ID.
|
|
426
|
-
* @param {VO | VertexKey |
|
|
426
|
+
* @param {VO | VertexKey | undefined} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
|
|
427
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 `
|
|
428
|
+
* identifier. If no destination is provided, the value is set to `undefined`.
|
|
429
429
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
430
430
|
* distance from the source vertex to the destination vertex should be calculated and returned in the result. If
|
|
431
431
|
* `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
|
|
@@ -440,9 +440,9 @@ class AbstractGraph {
|
|
|
440
440
|
if (genPaths === undefined)
|
|
441
441
|
genPaths = false;
|
|
442
442
|
if (dest === undefined)
|
|
443
|
-
dest =
|
|
443
|
+
dest = undefined;
|
|
444
444
|
let minDist = Infinity;
|
|
445
|
-
let minDest =
|
|
445
|
+
let minDest = undefined;
|
|
446
446
|
let minPath = [];
|
|
447
447
|
const paths = [];
|
|
448
448
|
const vertices = this._vertices;
|
|
@@ -450,9 +450,9 @@ class AbstractGraph {
|
|
|
450
450
|
const seen = new Set();
|
|
451
451
|
const preMap = new Map(); // predecessor
|
|
452
452
|
const srcVertex = this._getVertex(src);
|
|
453
|
-
const destVertex = dest ? this._getVertex(dest) :
|
|
453
|
+
const destVertex = dest ? this._getVertex(dest) : undefined;
|
|
454
454
|
if (!srcVertex) {
|
|
455
|
-
return
|
|
455
|
+
return undefined;
|
|
456
456
|
}
|
|
457
457
|
for (const vertex of vertices) {
|
|
458
458
|
const vertexOrKey = vertex[1];
|
|
@@ -460,10 +460,10 @@ class AbstractGraph {
|
|
|
460
460
|
distMap.set(vertexOrKey, Infinity);
|
|
461
461
|
}
|
|
462
462
|
distMap.set(srcVertex, 0);
|
|
463
|
-
preMap.set(srcVertex,
|
|
463
|
+
preMap.set(srcVertex, undefined);
|
|
464
464
|
const getMinOfNoSeen = () => {
|
|
465
465
|
let min = Infinity;
|
|
466
|
-
let minV =
|
|
466
|
+
let minV = undefined;
|
|
467
467
|
for (const [key, value] of distMap) {
|
|
468
468
|
if (!seen.has(key)) {
|
|
469
469
|
if (value < min) {
|
|
@@ -511,7 +511,7 @@ class AbstractGraph {
|
|
|
511
511
|
if (edge) {
|
|
512
512
|
const curFromMap = distMap.get(cur);
|
|
513
513
|
const neighborFromMap = distMap.get(neighbor);
|
|
514
|
-
// TODO after no-non-
|
|
514
|
+
// TODO after no-non-undefined-assertion not ensure the logic
|
|
515
515
|
if (curFromMap !== undefined && neighborFromMap !== undefined) {
|
|
516
516
|
if (edge.weight + curFromMap < neighborFromMap) {
|
|
517
517
|
distMap.set(neighbor, edge.weight + curFromMap);
|
|
@@ -558,7 +558,7 @@ class AbstractGraph {
|
|
|
558
558
|
* optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
|
|
559
559
|
* @param {VO | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
|
|
560
560
|
* start. It can be either a vertex object or a vertex ID.
|
|
561
|
-
* @param {VO | VertexKey |
|
|
561
|
+
* @param {VO | VertexKey | undefined} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
|
|
562
562
|
* vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
|
|
563
563
|
* will calculate the shortest paths to all other vertices from the source vertex.
|
|
564
564
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
@@ -576,9 +576,9 @@ class AbstractGraph {
|
|
|
576
576
|
if (genPaths === undefined)
|
|
577
577
|
genPaths = false;
|
|
578
578
|
if (dest === undefined)
|
|
579
|
-
dest =
|
|
579
|
+
dest = undefined;
|
|
580
580
|
let minDist = Infinity;
|
|
581
|
-
let minDest =
|
|
581
|
+
let minDest = undefined;
|
|
582
582
|
let minPath = [];
|
|
583
583
|
const paths = [];
|
|
584
584
|
const vertices = this._vertices;
|
|
@@ -586,9 +586,9 @@ class AbstractGraph {
|
|
|
586
586
|
const seen = new Set();
|
|
587
587
|
const preMap = new Map(); // predecessor
|
|
588
588
|
const srcVertex = this._getVertex(src);
|
|
589
|
-
const destVertex = dest ? this._getVertex(dest) :
|
|
589
|
+
const destVertex = dest ? this._getVertex(dest) : undefined;
|
|
590
590
|
if (!srcVertex)
|
|
591
|
-
return
|
|
591
|
+
return undefined;
|
|
592
592
|
for (const vertex of vertices) {
|
|
593
593
|
const vertexOrKey = vertex[1];
|
|
594
594
|
if (vertexOrKey instanceof AbstractVertex)
|
|
@@ -597,11 +597,11 @@ class AbstractGraph {
|
|
|
597
597
|
const heap = new priority_queue_1.PriorityQueue([], { comparator: (a, b) => a.key - b.key });
|
|
598
598
|
heap.add({ key: 0, value: srcVertex });
|
|
599
599
|
distMap.set(srcVertex, 0);
|
|
600
|
-
preMap.set(srcVertex,
|
|
600
|
+
preMap.set(srcVertex, undefined);
|
|
601
601
|
/**
|
|
602
602
|
* The function `getPaths` retrieves all paths from vertices to a specified minimum vertex.
|
|
603
|
-
* @param {VO |
|
|
604
|
-
*
|
|
603
|
+
* @param {VO | undefined} minV - The parameter `minV` is of type `VO | undefined`. It represents the minimum vertex value or
|
|
604
|
+
* undefined.
|
|
605
605
|
*/
|
|
606
606
|
const getPaths = (minV) => {
|
|
607
607
|
for (const vertex of vertices) {
|
|
@@ -737,7 +737,7 @@ class AbstractGraph {
|
|
|
737
737
|
}
|
|
738
738
|
}
|
|
739
739
|
}
|
|
740
|
-
let minDest =
|
|
740
|
+
let minDest = undefined;
|
|
741
741
|
if (getMin) {
|
|
742
742
|
distMap.forEach((d, v) => {
|
|
743
743
|
if (v !== srcVertex) {
|
|
@@ -813,7 +813,7 @@ class AbstractGraph {
|
|
|
813
813
|
* graph.
|
|
814
814
|
* @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
|
|
815
815
|
* property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
|
|
816
|
-
* `predecessor` property is a 2D array of vertices (or `
|
|
816
|
+
* `predecessor` property is a 2D array of vertices (or `undefined`) representing the predecessor vertices in the shortest
|
|
817
817
|
* path between vertices in the
|
|
818
818
|
*/
|
|
819
819
|
floydWarshall() {
|
|
@@ -827,7 +827,7 @@ class AbstractGraph {
|
|
|
827
827
|
costs[i] = [];
|
|
828
828
|
predecessor[i] = [];
|
|
829
829
|
for (let j = 0; j < n; j++) {
|
|
830
|
-
predecessor[i][j] =
|
|
830
|
+
predecessor[i][j] = undefined;
|
|
831
831
|
}
|
|
832
832
|
}
|
|
833
833
|
for (let i = 0; i < n; i++) {
|
|
@@ -919,7 +919,7 @@ class AbstractGraph {
|
|
|
919
919
|
}
|
|
920
920
|
const childLow = lowMap.get(neighbor);
|
|
921
921
|
const curLow = lowMap.get(cur);
|
|
922
|
-
// TODO after no-non-
|
|
922
|
+
// TODO after no-non-undefined-assertion not ensure the logic
|
|
923
923
|
if (curLow !== undefined && childLow !== undefined) {
|
|
924
924
|
lowMap.set(cur, Math.min(curLow, childLow));
|
|
925
925
|
}
|
|
@@ -943,7 +943,7 @@ class AbstractGraph {
|
|
|
943
943
|
}
|
|
944
944
|
}
|
|
945
945
|
};
|
|
946
|
-
dfs(root,
|
|
946
|
+
dfs(root, undefined);
|
|
947
947
|
let SCCs = new Map();
|
|
948
948
|
const getSCCs = () => {
|
|
949
949
|
const SCCs = new Map();
|
|
@@ -1038,7 +1038,7 @@ class AbstractGraph {
|
|
|
1038
1038
|
}
|
|
1039
1039
|
_getVertex(vertexOrKey) {
|
|
1040
1040
|
const vertexKey = this._getVertexKey(vertexOrKey);
|
|
1041
|
-
return this._vertices.get(vertexKey) ||
|
|
1041
|
+
return this._vertices.get(vertexKey) || undefined;
|
|
1042
1042
|
}
|
|
1043
1043
|
_getVertexKey(vertexOrKey) {
|
|
1044
1044
|
return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;
|