data-structure-typed 0.8.18 → 0.9.16
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/.idea/modules.xml +1 -1
- package/README.md +197 -2
- package/dist/data-structures/binary-tree/aa-tree.js +5 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +1 -5
- package/dist/data-structures/binary-tree/avl-tree.js +93 -46
- package/dist/data-structures/binary-tree/b-tree.js +5 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +14 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +20 -32
- package/dist/data-structures/binary-tree/binary-tree.js +480 -370
- package/dist/data-structures/binary-tree/bst.d.ts +4 -8
- package/dist/data-structures/binary-tree/bst.js +152 -107
- package/dist/data-structures/binary-tree/rb-tree.js +5 -2
- package/dist/data-structures/binary-tree/segment-tree.d.ts +3 -3
- package/dist/data-structures/binary-tree/segment-tree.js +91 -61
- package/dist/data-structures/binary-tree/splay-tree.js +5 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +31 -11
- package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
- package/dist/data-structures/graph/abstract-graph.d.ts +5 -33
- package/dist/data-structures/graph/abstract-graph.js +546 -311
- package/dist/data-structures/graph/directed-graph.d.ts +5 -13
- package/dist/data-structures/graph/directed-graph.js +250 -128
- package/dist/data-structures/graph/undirected-graph.d.ts +4 -3
- package/dist/data-structures/graph/undirected-graph.js +166 -81
- package/dist/data-structures/hash/coordinate-map.d.ts +1 -1
- package/dist/data-structures/hash/coordinate-map.js +38 -20
- package/dist/data-structures/hash/coordinate-set.js +33 -15
- package/dist/data-structures/hash/index.d.ts +5 -0
- package/dist/data-structures/hash/index.js +5 -0
- package/dist/data-structures/heap/heap.d.ts +2 -8
- package/dist/data-structures/heap/heap.js +36 -31
- package/dist/data-structures/heap/max-heap.d.ts +3 -2
- package/dist/data-structures/heap/max-heap.js +27 -9
- package/dist/data-structures/heap/min-heap.d.ts +3 -2
- package/dist/data-structures/heap/min-heap.js +27 -9
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +56 -53
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +8 -12
- package/dist/data-structures/linked-list/singly-linked-list.js +308 -174
- package/dist/data-structures/matrix/matrix.js +8 -7
- package/dist/data-structures/matrix/matrix2d.d.ts +5 -5
- package/dist/data-structures/matrix/matrix2d.js +80 -63
- package/dist/data-structures/matrix/navigator.d.ts +2 -16
- package/dist/data-structures/matrix/navigator.js +37 -18
- package/dist/data-structures/matrix/vector2d.d.ts +18 -18
- package/dist/data-structures/matrix/vector2d.js +117 -94
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -21
- package/dist/data-structures/priority-queue/priority-queue.js +159 -116
- package/dist/data-structures/queue/deque.js +82 -56
- package/dist/data-structures/queue/queue.d.ts +9 -10
- package/dist/data-structures/queue/queue.js +34 -34
- package/dist/data-structures/stack/stack.d.ts +9 -10
- package/dist/data-structures/stack/stack.js +31 -31
- package/dist/data-structures/trampoline.d.ts +14 -23
- package/dist/data-structures/trampoline.js +103 -25
- package/dist/data-structures/trie/trie.d.ts +13 -3
- package/dist/data-structures/trie/trie.js +234 -80
- package/dist/data-structures/types/abstract-graph.d.ts +29 -0
- package/dist/data-structures/types/abstract-graph.js +2 -0
- package/dist/data-structures/types/avl-tree.d.ts +5 -0
- package/dist/data-structures/types/avl-tree.js +2 -0
- package/dist/data-structures/types/binary-tree.d.ts +16 -0
- package/dist/data-structures/types/binary-tree.js +2 -0
- package/dist/data-structures/types/bst.d.ts +7 -0
- package/dist/data-structures/types/bst.js +2 -0
- package/dist/data-structures/types/directed-graph.d.ts +10 -0
- package/dist/data-structures/types/directed-graph.js +2 -0
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/types/doubly-linked-list.js +2 -0
- package/dist/data-structures/types/heap.d.ts +7 -0
- package/dist/data-structures/types/heap.js +2 -0
- package/dist/data-structures/types/index.d.ts +13 -0
- package/dist/data-structures/types/index.js +29 -0
- package/dist/data-structures/types/navigator.d.ts +14 -0
- package/dist/data-structures/types/navigator.js +2 -0
- package/dist/data-structures/types/priority-queue.d.ts +7 -0
- package/dist/data-structures/types/priority-queue.js +2 -0
- package/dist/data-structures/types/segment-tree.d.ts +1 -0
- package/dist/data-structures/types/segment-tree.js +2 -0
- package/dist/data-structures/types/singly-linked-list.d.ts +5 -0
- package/dist/data-structures/types/singly-linked-list.js +2 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -0
- package/dist/data-structures/types/tree-multiset.js +2 -0
- package/dist/{types → data-structures/types}/utils.d.ts +7 -1
- package/dist/{types → data-structures/types}/utils.js +20 -19
- package/dist/{utils.d.ts → utils/utils.d.ts} +6 -23
- package/dist/utils/utils.js +651 -0
- package/package.json +20 -42
- package/src/data-structures/binary-tree/avl-tree.ts +1 -6
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +4 -4
- package/src/data-structures/binary-tree/binary-tree.ts +184 -139
- package/src/data-structures/binary-tree/bst.ts +15 -24
- package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/src/data-structures/binary-tree/segment-tree.ts +20 -12
- package/src/data-structures/binary-tree/tree-multiset.ts +1 -4
- package/src/data-structures/diagrams/README.md +7 -0
- package/src/data-structures/graph/abstract-graph.ts +58 -94
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list.png +0 -0
- package/src/data-structures/graph/diagrams/max-flow.png +0 -0
- package/src/data-structures/graph/diagrams/mst.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/src/data-structures/graph/directed-graph.ts +12 -28
- package/src/data-structures/graph/undirected-graph.ts +11 -10
- package/src/data-structures/hash/coordinate-map.ts +1 -1
- package/src/data-structures/hash/index.ts +5 -0
- package/src/data-structures/heap/heap.ts +2 -11
- package/src/data-structures/heap/max-heap.ts +3 -2
- package/src/data-structures/heap/min-heap.ts +3 -2
- package/src/data-structures/index.ts +1 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -9
- package/src/data-structures/linked-list/singly-linked-list.ts +18 -32
- package/src/data-structures/matrix/matrix2d.ts +11 -11
- package/src/data-structures/matrix/navigator.ts +2 -14
- package/src/data-structures/matrix/vector2d.ts +52 -52
- package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/priority-queue.ts +70 -78
- package/src/data-structures/queue/deque.ts +2 -2
- package/src/data-structures/queue/queue.ts +12 -13
- package/src/data-structures/stack/stack.ts +12 -13
- package/src/data-structures/trampoline.ts +31 -71
- package/src/data-structures/trie/trie.ts +61 -11
- package/src/data-structures/types/abstract-graph.ts +51 -0
- package/src/data-structures/types/avl-tree.ts +6 -0
- package/src/data-structures/types/binary-tree.ts +15 -0
- package/src/data-structures/types/bst.ts +5 -0
- package/src/data-structures/types/directed-graph.ts +18 -0
- package/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/src/data-structures/types/heap.ts +8 -0
- package/src/data-structures/types/index.ts +13 -0
- package/src/data-structures/types/navigator.ts +12 -0
- package/src/data-structures/types/priority-queue.ts +9 -0
- package/src/data-structures/types/segment-tree.ts +1 -0
- package/src/data-structures/types/singly-linked-list.ts +15 -0
- package/src/data-structures/types/tree-multiset.ts +3 -0
- package/src/{types → data-structures/types}/utils.ts +20 -5
- package/src/utils/index.ts +1 -0
- package/src/{utils.ts → utils/utils.ts} +32 -132
- package/tsconfig.json +9 -6
- package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
- package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
- package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
- package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
- package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
- package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
- package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
- package/dist/types/data-structures/graph/index.d.ts +0 -3
- package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
- package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
- package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
- package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/pair.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +0 -72
- package/dist/types/data-structures/heap/index.d.ts +0 -3
- package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
- package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
- package/dist/types/data-structures/index.d.ts +0 -9
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
- package/dist/types/data-structures/linked-list/index.d.ts +0 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
- package/dist/types/data-structures/matrix/index.d.ts +0 -3
- package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
- package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
- package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
- package/dist/types/data-structures/queue/deque.d.ts +0 -37
- package/dist/types/data-structures/queue/index.d.ts +0 -1
- package/dist/types/data-structures/queue/queue.d.ts +0 -76
- package/dist/types/data-structures/stack/index.d.ts +0 -1
- package/dist/types/data-structures/stack/stack.d.ts +0 -69
- package/dist/types/data-structures/trampoline.d.ts +0 -25
- package/dist/types/data-structures/trie/index.d.ts +0 -1
- package/dist/types/data-structures/trie/trie.d.ts +0 -28
- package/dist/types/types/index.d.ts +0 -1
- package/dist/types/types/utils.d.ts +0 -46
- package/dist/utils.js +0 -569
- package/src/types/index.ts +0 -1
- package/src/types/patches/index.d.ts +0 -0
- /package/dist/{types → utils}/index.d.ts +0 -0
- /package/dist/{types → utils}/index.js +0 -0
|
@@ -1,88 +1,149 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
+
if (m) return m.call(o);
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
|
+
next: function () {
|
|
7
|
+
if (o && i >= o.length) o = void 0;
|
|
8
|
+
return { value: o && o[i++], done: !o };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
+
};
|
|
13
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
+
if (!m) return o;
|
|
16
|
+
var i = m.call(o), r, ar = [], e;
|
|
17
|
+
try {
|
|
18
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
9
19
|
}
|
|
10
|
-
|
|
11
|
-
|
|
20
|
+
catch (error) { e = { error: error }; }
|
|
21
|
+
finally {
|
|
22
|
+
try {
|
|
23
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
+
}
|
|
25
|
+
finally { if (e) throw e.error; }
|
|
26
|
+
}
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
+
if (ar || !(i in from)) {
|
|
32
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
+
ar[i] = from[i];
|
|
34
|
+
}
|
|
12
35
|
}
|
|
13
|
-
|
|
36
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.AbstractGraph = exports.AbstractEdge = exports.AbstractVertex = void 0;
|
|
40
|
+
var utils_1 = require("../../utils");
|
|
41
|
+
var priority_queue_1 = require("../priority-queue");
|
|
42
|
+
var AbstractVertex = /** @class */ (function () {
|
|
43
|
+
function AbstractVertex(id) {
|
|
14
44
|
this._id = id;
|
|
15
45
|
}
|
|
16
|
-
|
|
46
|
+
Object.defineProperty(AbstractVertex.prototype, "id", {
|
|
47
|
+
get: function () {
|
|
48
|
+
return this._id;
|
|
49
|
+
},
|
|
50
|
+
set: function (v) {
|
|
51
|
+
this._id = v;
|
|
52
|
+
},
|
|
53
|
+
enumerable: false,
|
|
54
|
+
configurable: true
|
|
55
|
+
});
|
|
56
|
+
return AbstractVertex;
|
|
57
|
+
}());
|
|
17
58
|
exports.AbstractVertex = AbstractVertex;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return this._weight;
|
|
21
|
-
}
|
|
22
|
-
set weight(v) {
|
|
23
|
-
this._weight = v;
|
|
24
|
-
}
|
|
25
|
-
get hashCode() {
|
|
26
|
-
return this._hashCode;
|
|
27
|
-
}
|
|
28
|
-
set hashCode(v) {
|
|
29
|
-
this._hashCode = v;
|
|
30
|
-
}
|
|
31
|
-
constructor(weight) {
|
|
59
|
+
var AbstractEdge = /** @class */ (function () {
|
|
60
|
+
function AbstractEdge(weight) {
|
|
32
61
|
if (weight === undefined)
|
|
33
62
|
weight = AbstractEdge.DEFAULT_EDGE_WEIGHT;
|
|
34
63
|
this._weight = weight;
|
|
35
64
|
this._hashCode = (0, utils_1.uuidV4)();
|
|
36
65
|
}
|
|
37
|
-
|
|
66
|
+
Object.defineProperty(AbstractEdge.prototype, "weight", {
|
|
67
|
+
get: function () {
|
|
68
|
+
return this._weight;
|
|
69
|
+
},
|
|
70
|
+
set: function (v) {
|
|
71
|
+
this._weight = v;
|
|
72
|
+
},
|
|
73
|
+
enumerable: false,
|
|
74
|
+
configurable: true
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(AbstractEdge.prototype, "hashCode", {
|
|
77
|
+
get: function () {
|
|
78
|
+
return this._hashCode;
|
|
79
|
+
},
|
|
80
|
+
set: function (v) {
|
|
81
|
+
this._hashCode = v;
|
|
82
|
+
},
|
|
83
|
+
enumerable: false,
|
|
84
|
+
configurable: true
|
|
85
|
+
});
|
|
86
|
+
AbstractEdge.DEFAULT_EDGE_WEIGHT = 1;
|
|
87
|
+
return AbstractEdge;
|
|
88
|
+
}());
|
|
38
89
|
exports.AbstractEdge = AbstractEdge;
|
|
39
|
-
AbstractEdge.DEFAULT_EDGE_WEIGHT = 1;
|
|
40
90
|
// Connected Component === Largest Connected Sub-Graph
|
|
41
|
-
|
|
42
|
-
|
|
91
|
+
var AbstractGraph = /** @class */ (function () {
|
|
92
|
+
function AbstractGraph() {
|
|
43
93
|
this._vertices = new Map();
|
|
44
94
|
// unionFind() {
|
|
45
95
|
// }
|
|
46
96
|
/**--- end find cycles --- */
|
|
47
97
|
// Minimum Spanning Tree
|
|
48
98
|
}
|
|
49
|
-
getVertex(vertexOrId) {
|
|
50
|
-
|
|
99
|
+
AbstractGraph.prototype.getVertex = function (vertexOrId) {
|
|
100
|
+
var vertexId = this.getVertexId(vertexOrId);
|
|
51
101
|
return this._vertices.get(vertexId) || null;
|
|
52
|
-
}
|
|
53
|
-
getVertexId(vertexOrId) {
|
|
102
|
+
};
|
|
103
|
+
AbstractGraph.prototype.getVertexId = function (vertexOrId) {
|
|
54
104
|
return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
|
|
55
|
-
}
|
|
56
|
-
containsVertex(vertexOrId) {
|
|
105
|
+
};
|
|
106
|
+
AbstractGraph.prototype.containsVertex = function (vertexOrId) {
|
|
57
107
|
return this._vertices.has(this.getVertexId(vertexOrId));
|
|
58
|
-
}
|
|
59
|
-
vertexSet() {
|
|
108
|
+
};
|
|
109
|
+
AbstractGraph.prototype.vertexSet = function () {
|
|
60
110
|
return this._vertices;
|
|
61
|
-
}
|
|
62
|
-
addVertex(newVertex) {
|
|
111
|
+
};
|
|
112
|
+
AbstractGraph.prototype.addVertex = function (newVertex) {
|
|
63
113
|
if (this.containsVertex(newVertex)) {
|
|
64
114
|
return false;
|
|
65
115
|
}
|
|
66
116
|
this._vertices.set(newVertex.id, newVertex);
|
|
67
117
|
return true;
|
|
68
|
-
}
|
|
69
|
-
removeVertex(vertexOrId) {
|
|
70
|
-
|
|
118
|
+
};
|
|
119
|
+
AbstractGraph.prototype.removeVertex = function (vertexOrId) {
|
|
120
|
+
var vertexId = this.getVertexId(vertexOrId);
|
|
71
121
|
return this._vertices.delete(vertexId);
|
|
72
|
-
}
|
|
73
|
-
removeAllVertices(vertices) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
122
|
+
};
|
|
123
|
+
AbstractGraph.prototype.removeAllVertices = function (vertices) {
|
|
124
|
+
var e_1, _a;
|
|
125
|
+
var removed = [];
|
|
126
|
+
try {
|
|
127
|
+
for (var vertices_1 = __values(vertices), vertices_1_1 = vertices_1.next(); !vertices_1_1.done; vertices_1_1 = vertices_1.next()) {
|
|
128
|
+
var v = vertices_1_1.value;
|
|
129
|
+
removed.push(this.removeVertex(v));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
133
|
+
finally {
|
|
134
|
+
try {
|
|
135
|
+
if (vertices_1_1 && !vertices_1_1.done && (_a = vertices_1.return)) _a.call(vertices_1);
|
|
136
|
+
}
|
|
137
|
+
finally { if (e_1) throw e_1.error; }
|
|
77
138
|
}
|
|
78
139
|
return removed.length > 0;
|
|
79
|
-
}
|
|
80
|
-
containsEdge(v1, v2) {
|
|
81
|
-
|
|
140
|
+
};
|
|
141
|
+
AbstractGraph.prototype.containsEdge = function (v1, v2) {
|
|
142
|
+
var edge = this.getEdge(v1, v2);
|
|
82
143
|
return !!edge;
|
|
83
|
-
}
|
|
84
|
-
setEdgeWeight(srcOrId, destOrId, weight) {
|
|
85
|
-
|
|
144
|
+
};
|
|
145
|
+
AbstractGraph.prototype.setEdgeWeight = function (srcOrId, destOrId, weight) {
|
|
146
|
+
var edge = this.getEdge(srcOrId, destOrId);
|
|
86
147
|
if (edge) {
|
|
87
148
|
edge.weight = weight;
|
|
88
149
|
return true;
|
|
@@ -90,76 +151,112 @@ class AbstractGraph {
|
|
|
90
151
|
else {
|
|
91
152
|
return false;
|
|
92
153
|
}
|
|
93
|
-
}
|
|
94
|
-
getAllPathsBetween(v1, v2) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
154
|
+
};
|
|
155
|
+
AbstractGraph.prototype.getAllPathsBetween = function (v1, v2) {
|
|
156
|
+
var _this = this;
|
|
157
|
+
var paths = [];
|
|
158
|
+
var vertex1 = this.getVertex(v1);
|
|
159
|
+
var vertex2 = this.getVertex(v2);
|
|
98
160
|
if (!(vertex1 && vertex2)) {
|
|
99
161
|
return [];
|
|
100
162
|
}
|
|
101
|
-
|
|
163
|
+
var dfs = function (cur, dest, visiting, path) {
|
|
164
|
+
var e_2, _a;
|
|
102
165
|
visiting.set(cur, true);
|
|
103
166
|
if (cur === dest) {
|
|
104
|
-
paths.push([vertex1,
|
|
167
|
+
paths.push(__spreadArray([vertex1], __read(path), false));
|
|
105
168
|
}
|
|
106
|
-
|
|
107
|
-
|
|
169
|
+
var neighbors = _this.getNeighbors(cur);
|
|
170
|
+
var _loop_1 = function (neighbor) {
|
|
108
171
|
if (!visiting.get(neighbor)) {
|
|
109
172
|
path.push(neighbor);
|
|
110
173
|
dfs(neighbor, dest, visiting, path);
|
|
111
|
-
(0, utils_1.arrayRemove)(path, vertex
|
|
174
|
+
(0, utils_1.arrayRemove)(path, function (vertex) { return vertex === neighbor; });
|
|
112
175
|
}
|
|
176
|
+
};
|
|
177
|
+
try {
|
|
178
|
+
for (var neighbors_1 = __values(neighbors), neighbors_1_1 = neighbors_1.next(); !neighbors_1_1.done; neighbors_1_1 = neighbors_1.next()) {
|
|
179
|
+
var neighbor = neighbors_1_1.value;
|
|
180
|
+
_loop_1(neighbor);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
184
|
+
finally {
|
|
185
|
+
try {
|
|
186
|
+
if (neighbors_1_1 && !neighbors_1_1.done && (_a = neighbors_1.return)) _a.call(neighbors_1);
|
|
187
|
+
}
|
|
188
|
+
finally { if (e_2) throw e_2.error; }
|
|
113
189
|
}
|
|
114
190
|
visiting.set(cur, false);
|
|
115
191
|
};
|
|
116
192
|
dfs(vertex1, vertex2, new Map(), []);
|
|
117
193
|
return paths;
|
|
118
|
-
}
|
|
119
|
-
getPathSumWeight(path) {
|
|
194
|
+
};
|
|
195
|
+
AbstractGraph.prototype.getPathSumWeight = function (path) {
|
|
120
196
|
var _a;
|
|
121
|
-
|
|
122
|
-
for (
|
|
197
|
+
var sum = 0;
|
|
198
|
+
for (var i = 0; i < path.length; i++) {
|
|
123
199
|
sum += ((_a = this.getEdge(path[i], path[i + 1])) === null || _a === void 0 ? void 0 : _a.weight) || 0;
|
|
124
200
|
}
|
|
125
201
|
return sum;
|
|
126
|
-
}
|
|
127
|
-
getMinCostBetween(v1, v2, isWeight) {
|
|
202
|
+
};
|
|
203
|
+
AbstractGraph.prototype.getMinCostBetween = function (v1, v2, isWeight) {
|
|
204
|
+
var e_3, _a, e_4, _b;
|
|
128
205
|
if (isWeight === undefined)
|
|
129
206
|
isWeight = false;
|
|
130
207
|
if (isWeight) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
208
|
+
var allPaths = this.getAllPathsBetween(v1, v2);
|
|
209
|
+
var min = Infinity;
|
|
210
|
+
try {
|
|
211
|
+
for (var allPaths_1 = __values(allPaths), allPaths_1_1 = allPaths_1.next(); !allPaths_1_1.done; allPaths_1_1 = allPaths_1.next()) {
|
|
212
|
+
var path = allPaths_1_1.value;
|
|
213
|
+
min = Math.min(this.getPathSumWeight(path), min);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
217
|
+
finally {
|
|
218
|
+
try {
|
|
219
|
+
if (allPaths_1_1 && !allPaths_1_1.done && (_a = allPaths_1.return)) _a.call(allPaths_1);
|
|
220
|
+
}
|
|
221
|
+
finally { if (e_3) throw e_3.error; }
|
|
135
222
|
}
|
|
136
223
|
return min;
|
|
137
224
|
}
|
|
138
225
|
else {
|
|
139
226
|
// BFS
|
|
140
|
-
|
|
141
|
-
|
|
227
|
+
var vertex2 = this.getVertex(v2);
|
|
228
|
+
var vertex1 = this.getVertex(v1);
|
|
142
229
|
if (!(vertex1 && vertex2)) {
|
|
143
230
|
return null;
|
|
144
231
|
}
|
|
145
|
-
|
|
146
|
-
|
|
232
|
+
var visited = new Map();
|
|
233
|
+
var queue = [vertex1];
|
|
147
234
|
visited.set(vertex1, true);
|
|
148
|
-
|
|
235
|
+
var cost = 0;
|
|
149
236
|
while (queue.length > 0) {
|
|
150
|
-
for (
|
|
151
|
-
|
|
237
|
+
for (var i = 0; i < queue.length; i++) {
|
|
238
|
+
var cur = queue.shift();
|
|
152
239
|
if (cur === vertex2) {
|
|
153
240
|
return cost;
|
|
154
241
|
}
|
|
155
242
|
// TODO consider optimizing to AbstractGraph
|
|
156
243
|
if (cur !== undefined) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
244
|
+
var neighbors = this.getNeighbors(cur);
|
|
245
|
+
try {
|
|
246
|
+
for (var neighbors_2 = (e_4 = void 0, __values(neighbors)), neighbors_2_1 = neighbors_2.next(); !neighbors_2_1.done; neighbors_2_1 = neighbors_2.next()) {
|
|
247
|
+
var neighbor = neighbors_2_1.value;
|
|
248
|
+
if (!visited.has(neighbor)) {
|
|
249
|
+
visited.set(neighbor, true);
|
|
250
|
+
queue.push(neighbor);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
255
|
+
finally {
|
|
256
|
+
try {
|
|
257
|
+
if (neighbors_2_1 && !neighbors_2_1.done && (_b = neighbors_2.return)) _b.call(neighbors_2);
|
|
162
258
|
}
|
|
259
|
+
finally { if (e_4) throw e_4.error; }
|
|
163
260
|
}
|
|
164
261
|
}
|
|
165
262
|
}
|
|
@@ -167,53 +264,79 @@ class AbstractGraph {
|
|
|
167
264
|
}
|
|
168
265
|
return null;
|
|
169
266
|
}
|
|
170
|
-
}
|
|
171
|
-
getMinPathBetween(v1, v2, isWeight) {
|
|
267
|
+
};
|
|
268
|
+
AbstractGraph.prototype.getMinPathBetween = function (v1, v2, isWeight) {
|
|
269
|
+
var e_5, _a;
|
|
270
|
+
var _this = this;
|
|
172
271
|
if (isWeight === undefined)
|
|
173
272
|
isWeight = false;
|
|
174
273
|
if (isWeight) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
274
|
+
var allPaths = this.getAllPathsBetween(v1, v2);
|
|
275
|
+
var min = Infinity;
|
|
276
|
+
var minIndex = -1;
|
|
277
|
+
var index = 0;
|
|
278
|
+
try {
|
|
279
|
+
for (var allPaths_2 = __values(allPaths), allPaths_2_1 = allPaths_2.next(); !allPaths_2_1.done; allPaths_2_1 = allPaths_2.next()) {
|
|
280
|
+
var path = allPaths_2_1.value;
|
|
281
|
+
var pathSumWeight = this.getPathSumWeight(path);
|
|
282
|
+
if (pathSumWeight < min) {
|
|
283
|
+
min = pathSumWeight;
|
|
284
|
+
minIndex = index;
|
|
285
|
+
}
|
|
286
|
+
index++;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
290
|
+
finally {
|
|
291
|
+
try {
|
|
292
|
+
if (allPaths_2_1 && !allPaths_2_1.done && (_a = allPaths_2.return)) _a.call(allPaths_2);
|
|
293
|
+
}
|
|
294
|
+
finally { if (e_5) throw e_5.error; }
|
|
186
295
|
}
|
|
187
296
|
return allPaths[minIndex] || null;
|
|
188
297
|
}
|
|
189
298
|
else {
|
|
190
299
|
// BFS
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (!(
|
|
300
|
+
var minPath_1 = [];
|
|
301
|
+
var vertex1_1 = this.getVertex(v1);
|
|
302
|
+
var vertex2 = this.getVertex(v2);
|
|
303
|
+
if (!(vertex1_1 && vertex2)) {
|
|
195
304
|
return [];
|
|
196
305
|
}
|
|
197
|
-
|
|
306
|
+
var dfs_1 = function (cur, dest, visiting, path) {
|
|
307
|
+
var e_6, _a;
|
|
198
308
|
visiting.set(cur, true);
|
|
199
309
|
if (cur === dest) {
|
|
200
|
-
|
|
310
|
+
minPath_1 = __spreadArray([vertex1_1], __read(path), false);
|
|
201
311
|
return;
|
|
202
312
|
}
|
|
203
|
-
|
|
204
|
-
|
|
313
|
+
var neighbors = _this.getNeighbors(cur);
|
|
314
|
+
var _loop_2 = function (neighbor) {
|
|
205
315
|
if (!visiting.get(neighbor)) {
|
|
206
316
|
path.push(neighbor);
|
|
207
|
-
|
|
208
|
-
(0, utils_1.arrayRemove)(path, vertex
|
|
317
|
+
dfs_1(neighbor, dest, visiting, path);
|
|
318
|
+
(0, utils_1.arrayRemove)(path, function (vertex) { return vertex === neighbor; });
|
|
209
319
|
}
|
|
320
|
+
};
|
|
321
|
+
try {
|
|
322
|
+
for (var neighbors_3 = __values(neighbors), neighbors_3_1 = neighbors_3.next(); !neighbors_3_1.done; neighbors_3_1 = neighbors_3.next()) {
|
|
323
|
+
var neighbor = neighbors_3_1.value;
|
|
324
|
+
_loop_2(neighbor);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
328
|
+
finally {
|
|
329
|
+
try {
|
|
330
|
+
if (neighbors_3_1 && !neighbors_3_1.done && (_a = neighbors_3.return)) _a.call(neighbors_3);
|
|
331
|
+
}
|
|
332
|
+
finally { if (e_6) throw e_6.error; }
|
|
210
333
|
}
|
|
211
334
|
visiting.set(cur, false);
|
|
212
335
|
};
|
|
213
|
-
|
|
214
|
-
return
|
|
336
|
+
dfs_1(vertex1_1, vertex2, new Map(), []);
|
|
337
|
+
return minPath_1;
|
|
215
338
|
}
|
|
216
|
-
}
|
|
339
|
+
};
|
|
217
340
|
/**
|
|
218
341
|
* Dijkstra algorithm time: O(VE) space: O(V + E)
|
|
219
342
|
* @param src
|
|
@@ -221,60 +344,98 @@ class AbstractGraph {
|
|
|
221
344
|
* @param getMinDist
|
|
222
345
|
* @param genPaths
|
|
223
346
|
*/
|
|
224
|
-
dijkstraWithoutHeap(src, dest, getMinDist, genPaths) {
|
|
347
|
+
AbstractGraph.prototype.dijkstraWithoutHeap = function (src, dest, getMinDist, genPaths) {
|
|
348
|
+
var e_7, _a, e_8, _b;
|
|
225
349
|
if (getMinDist === undefined)
|
|
226
350
|
getMinDist = false;
|
|
227
351
|
if (genPaths === undefined)
|
|
228
352
|
genPaths = false;
|
|
229
353
|
if (dest === undefined)
|
|
230
354
|
dest = null;
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
355
|
+
var minDist = Infinity;
|
|
356
|
+
var minDest = null;
|
|
357
|
+
var minPath = [];
|
|
358
|
+
var paths = [];
|
|
359
|
+
var vertices = this._vertices;
|
|
360
|
+
var distMap = new Map();
|
|
361
|
+
var seen = new Set();
|
|
362
|
+
var preMap = new Map(); // predecessor
|
|
363
|
+
var srcVertex = this.getVertex(src);
|
|
364
|
+
var destVertex = dest ? this.getVertex(dest) : null;
|
|
241
365
|
if (!srcVertex) {
|
|
242
366
|
return null;
|
|
243
367
|
}
|
|
244
|
-
|
|
245
|
-
|
|
368
|
+
try {
|
|
369
|
+
for (var vertices_2 = __values(vertices), vertices_2_1 = vertices_2.next(); !vertices_2_1.done; vertices_2_1 = vertices_2.next()) {
|
|
370
|
+
var vertex = vertices_2_1.value;
|
|
371
|
+
var vertexOrId = vertex[1];
|
|
372
|
+
if (vertexOrId instanceof AbstractVertex)
|
|
373
|
+
distMap.set(vertexOrId, Infinity);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
377
|
+
finally {
|
|
378
|
+
try {
|
|
379
|
+
if (vertices_2_1 && !vertices_2_1.done && (_a = vertices_2.return)) _a.call(vertices_2);
|
|
380
|
+
}
|
|
381
|
+
finally { if (e_7) throw e_7.error; }
|
|
246
382
|
}
|
|
247
383
|
distMap.set(srcVertex, 0);
|
|
248
384
|
preMap.set(srcVertex, null);
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
385
|
+
var getMinOfNoSeen = function () {
|
|
386
|
+
var e_9, _a;
|
|
387
|
+
var min = Infinity;
|
|
388
|
+
var minV = null;
|
|
389
|
+
try {
|
|
390
|
+
for (var distMap_1 = __values(distMap), distMap_1_1 = distMap_1.next(); !distMap_1_1.done; distMap_1_1 = distMap_1.next()) {
|
|
391
|
+
var _b = __read(distMap_1_1.value, 2), key = _b[0], val = _b[1];
|
|
392
|
+
if (!seen.has(key)) {
|
|
393
|
+
if (val < min) {
|
|
394
|
+
min = val;
|
|
395
|
+
minV = key;
|
|
396
|
+
}
|
|
257
397
|
}
|
|
258
398
|
}
|
|
259
399
|
}
|
|
400
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
401
|
+
finally {
|
|
402
|
+
try {
|
|
403
|
+
if (distMap_1_1 && !distMap_1_1.done && (_a = distMap_1.return)) _a.call(distMap_1);
|
|
404
|
+
}
|
|
405
|
+
finally { if (e_9) throw e_9.error; }
|
|
406
|
+
}
|
|
260
407
|
return minV;
|
|
261
408
|
};
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
409
|
+
var getPaths = function (minV) {
|
|
410
|
+
var e_10, _a;
|
|
411
|
+
try {
|
|
412
|
+
for (var vertices_3 = __values(vertices), vertices_3_1 = vertices_3.next(); !vertices_3_1.done; vertices_3_1 = vertices_3.next()) {
|
|
413
|
+
var vertex = vertices_3_1.value;
|
|
414
|
+
var vertexOrId = vertex[1];
|
|
415
|
+
if (vertexOrId instanceof AbstractVertex) {
|
|
416
|
+
var path = [vertexOrId];
|
|
417
|
+
var parent = preMap.get(vertexOrId);
|
|
418
|
+
while (parent) {
|
|
419
|
+
path.push(parent);
|
|
420
|
+
parent = preMap.get(parent);
|
|
421
|
+
}
|
|
422
|
+
var reversed = path.reverse();
|
|
423
|
+
if (vertex[1] === minV)
|
|
424
|
+
minPath = reversed;
|
|
425
|
+
paths.push(reversed);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
430
|
+
finally {
|
|
431
|
+
try {
|
|
432
|
+
if (vertices_3_1 && !vertices_3_1.done && (_a = vertices_3.return)) _a.call(vertices_3);
|
|
433
|
+
}
|
|
434
|
+
finally { if (e_10) throw e_10.error; }
|
|
274
435
|
}
|
|
275
436
|
};
|
|
276
|
-
for (
|
|
277
|
-
|
|
437
|
+
for (var i = 1; i < vertices.size; i++) {
|
|
438
|
+
var cur = getMinOfNoSeen();
|
|
278
439
|
if (cur) {
|
|
279
440
|
seen.add(cur);
|
|
280
441
|
if (destVertex && destVertex === cur) {
|
|
@@ -284,28 +445,38 @@ class AbstractGraph {
|
|
|
284
445
|
if (genPaths) {
|
|
285
446
|
getPaths(destVertex);
|
|
286
447
|
}
|
|
287
|
-
return { distMap, preMap, seen, paths, minDist, minPath };
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
448
|
+
return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
|
|
449
|
+
}
|
|
450
|
+
var neighbors = this.getNeighbors(cur);
|
|
451
|
+
try {
|
|
452
|
+
for (var neighbors_4 = (e_8 = void 0, __values(neighbors)), neighbors_4_1 = neighbors_4.next(); !neighbors_4_1.done; neighbors_4_1 = neighbors_4.next()) {
|
|
453
|
+
var neighbor = neighbors_4_1.value;
|
|
454
|
+
if (!seen.has(neighbor)) {
|
|
455
|
+
var edge = this.getEdge(cur, neighbor);
|
|
456
|
+
if (edge) {
|
|
457
|
+
var curFromMap = distMap.get(cur);
|
|
458
|
+
var neighborFromMap = distMap.get(neighbor);
|
|
459
|
+
// TODO after no-non-null-assertion not ensure the logic
|
|
460
|
+
if (curFromMap !== undefined && neighborFromMap !== undefined) {
|
|
461
|
+
if (edge.weight + curFromMap < neighborFromMap) {
|
|
462
|
+
distMap.set(neighbor, edge.weight + curFromMap);
|
|
463
|
+
preMap.set(neighbor, cur);
|
|
464
|
+
}
|
|
301
465
|
}
|
|
302
466
|
}
|
|
303
467
|
}
|
|
304
468
|
}
|
|
305
469
|
}
|
|
470
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
471
|
+
finally {
|
|
472
|
+
try {
|
|
473
|
+
if (neighbors_4_1 && !neighbors_4_1.done && (_b = neighbors_4.return)) _b.call(neighbors_4);
|
|
474
|
+
}
|
|
475
|
+
finally { if (e_8) throw e_8.error; }
|
|
476
|
+
}
|
|
306
477
|
}
|
|
307
478
|
}
|
|
308
|
-
getMinDist && distMap.forEach((d, v)
|
|
479
|
+
getMinDist && distMap.forEach(function (d, v) {
|
|
309
480
|
if (v !== srcVertex) {
|
|
310
481
|
if (d < minDist) {
|
|
311
482
|
minDist = d;
|
|
@@ -315,8 +486,8 @@ class AbstractGraph {
|
|
|
315
486
|
}
|
|
316
487
|
});
|
|
317
488
|
genPaths && getPaths(minDest);
|
|
318
|
-
return { distMap, preMap, seen, paths, minDist, minPath };
|
|
319
|
-
}
|
|
489
|
+
return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
|
|
490
|
+
};
|
|
320
491
|
/**
|
|
321
492
|
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
322
493
|
* @param src
|
|
@@ -324,52 +495,79 @@ class AbstractGraph {
|
|
|
324
495
|
* @param getMinDist
|
|
325
496
|
* @param genPaths
|
|
326
497
|
*/
|
|
327
|
-
dijkstra(src, dest, getMinDist, genPaths) {
|
|
328
|
-
var _a;
|
|
498
|
+
AbstractGraph.prototype.dijkstra = function (src, dest, getMinDist, genPaths) {
|
|
499
|
+
var e_11, _a, e_12, _b;
|
|
500
|
+
var _c;
|
|
329
501
|
if (getMinDist === undefined)
|
|
330
502
|
getMinDist = false;
|
|
331
503
|
if (genPaths === undefined)
|
|
332
504
|
genPaths = false;
|
|
333
505
|
if (dest === undefined)
|
|
334
506
|
dest = null;
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
507
|
+
var minDist = Infinity;
|
|
508
|
+
var minDest = null;
|
|
509
|
+
var minPath = [];
|
|
510
|
+
var paths = [];
|
|
511
|
+
var vertices = this._vertices;
|
|
512
|
+
var distMap = new Map();
|
|
513
|
+
var seen = new Set();
|
|
514
|
+
var preMap = new Map(); // predecessor
|
|
515
|
+
var srcVertex = this.getVertex(src);
|
|
516
|
+
var destVertex = dest ? this.getVertex(dest) : null;
|
|
345
517
|
if (!srcVertex) {
|
|
346
518
|
return null;
|
|
347
519
|
}
|
|
348
|
-
|
|
349
|
-
|
|
520
|
+
try {
|
|
521
|
+
for (var vertices_4 = __values(vertices), vertices_4_1 = vertices_4.next(); !vertices_4_1.done; vertices_4_1 = vertices_4.next()) {
|
|
522
|
+
var vertex = vertices_4_1.value;
|
|
523
|
+
var vertexOrId = vertex[1];
|
|
524
|
+
if (vertexOrId instanceof AbstractVertex)
|
|
525
|
+
distMap.set(vertexOrId, Infinity);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
529
|
+
finally {
|
|
530
|
+
try {
|
|
531
|
+
if (vertices_4_1 && !vertices_4_1.done && (_a = vertices_4.return)) _a.call(vertices_4);
|
|
532
|
+
}
|
|
533
|
+
finally { if (e_11) throw e_11.error; }
|
|
350
534
|
}
|
|
351
|
-
|
|
535
|
+
var heap = new priority_queue_1.PriorityQueue({ comparator: function (a, b) { return a.id - b.id; } });
|
|
352
536
|
heap.offer({ id: 0, val: srcVertex });
|
|
353
537
|
distMap.set(srcVertex, 0);
|
|
354
538
|
preMap.set(srcVertex, null);
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
539
|
+
var getPaths = function (minV) {
|
|
540
|
+
var e_13, _a;
|
|
541
|
+
try {
|
|
542
|
+
for (var vertices_5 = __values(vertices), vertices_5_1 = vertices_5.next(); !vertices_5_1.done; vertices_5_1 = vertices_5.next()) {
|
|
543
|
+
var vertex = vertices_5_1.value;
|
|
544
|
+
var vertexOrId = vertex[1];
|
|
545
|
+
if (vertexOrId instanceof AbstractVertex) {
|
|
546
|
+
var path = [vertexOrId];
|
|
547
|
+
var parent = preMap.get(vertexOrId);
|
|
548
|
+
while (parent) {
|
|
549
|
+
path.push(parent);
|
|
550
|
+
parent = preMap.get(parent);
|
|
551
|
+
}
|
|
552
|
+
var reversed = path.reverse();
|
|
553
|
+
if (vertex[1] === minV)
|
|
554
|
+
minPath = reversed;
|
|
555
|
+
paths.push(reversed);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
560
|
+
finally {
|
|
561
|
+
try {
|
|
562
|
+
if (vertices_5_1 && !vertices_5_1.done && (_a = vertices_5.return)) _a.call(vertices_5);
|
|
563
|
+
}
|
|
564
|
+
finally { if (e_13) throw e_13.error; }
|
|
367
565
|
}
|
|
368
566
|
};
|
|
369
567
|
while (heap.size > 0) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
568
|
+
var curHeapNode = heap.poll();
|
|
569
|
+
var dist = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.id;
|
|
570
|
+
var cur = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.val;
|
|
373
571
|
if (dist !== undefined) {
|
|
374
572
|
if (cur) {
|
|
375
573
|
seen.add(cur);
|
|
@@ -380,29 +578,39 @@ class AbstractGraph {
|
|
|
380
578
|
if (genPaths) {
|
|
381
579
|
getPaths(destVertex);
|
|
382
580
|
}
|
|
383
|
-
return { distMap, preMap, seen, paths, minDist, minPath };
|
|
581
|
+
return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
|
|
384
582
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
if (
|
|
390
|
-
|
|
391
|
-
if (
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
583
|
+
var neighbors = this.getNeighbors(cur);
|
|
584
|
+
try {
|
|
585
|
+
for (var neighbors_5 = (e_12 = void 0, __values(neighbors)), neighbors_5_1 = neighbors_5.next(); !neighbors_5_1.done; neighbors_5_1 = neighbors_5.next()) {
|
|
586
|
+
var neighbor = neighbors_5_1.value;
|
|
587
|
+
if (!seen.has(neighbor)) {
|
|
588
|
+
var weight = (_c = this.getEdge(cur, neighbor)) === null || _c === void 0 ? void 0 : _c.weight;
|
|
589
|
+
if (typeof weight === 'number') {
|
|
590
|
+
var distSrcToNeighbor = distMap.get(neighbor);
|
|
591
|
+
if (distSrcToNeighbor) {
|
|
592
|
+
if (dist + weight < distSrcToNeighbor) {
|
|
593
|
+
heap.offer({ id: dist + weight, val: neighbor });
|
|
594
|
+
preMap.set(neighbor, cur);
|
|
595
|
+
distMap.set(neighbor, dist + weight);
|
|
596
|
+
}
|
|
396
597
|
}
|
|
397
598
|
}
|
|
398
599
|
}
|
|
399
600
|
}
|
|
400
601
|
}
|
|
602
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
603
|
+
finally {
|
|
604
|
+
try {
|
|
605
|
+
if (neighbors_5_1 && !neighbors_5_1.done && (_b = neighbors_5.return)) _b.call(neighbors_5);
|
|
606
|
+
}
|
|
607
|
+
finally { if (e_12) throw e_12.error; }
|
|
608
|
+
}
|
|
401
609
|
}
|
|
402
610
|
}
|
|
403
611
|
}
|
|
404
612
|
if (getMinDist) {
|
|
405
|
-
distMap.forEach((d, v)
|
|
613
|
+
distMap.forEach(function (d, v) {
|
|
406
614
|
if (v !== srcVertex) {
|
|
407
615
|
if (d < minDist) {
|
|
408
616
|
minDist = d;
|
|
@@ -415,8 +623,8 @@ class AbstractGraph {
|
|
|
415
623
|
if (genPaths) {
|
|
416
624
|
getPaths(minDest);
|
|
417
625
|
}
|
|
418
|
-
return { distMap, preMap, seen, paths, minDist, minPath };
|
|
419
|
-
}
|
|
626
|
+
return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
|
|
627
|
+
};
|
|
420
628
|
/**
|
|
421
629
|
* BellmanFord time:O(VE) space:O(V)
|
|
422
630
|
* one to rest pairs
|
|
@@ -425,39 +633,40 @@ class AbstractGraph {
|
|
|
425
633
|
* @param getMin
|
|
426
634
|
* @param genPath
|
|
427
635
|
*/
|
|
428
|
-
bellmanFord(src, scanNegativeCycle, getMin, genPath) {
|
|
636
|
+
AbstractGraph.prototype.bellmanFord = function (src, scanNegativeCycle, getMin, genPath) {
|
|
637
|
+
var e_14, _a;
|
|
429
638
|
if (getMin === undefined)
|
|
430
639
|
getMin = false;
|
|
431
640
|
if (genPath === undefined)
|
|
432
641
|
genPath = false;
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
642
|
+
var srcVertex = this.getVertex(src);
|
|
643
|
+
var paths = [];
|
|
644
|
+
var distMap = new Map();
|
|
645
|
+
var preMap = new Map(); // predecessor
|
|
646
|
+
var min = Infinity;
|
|
647
|
+
var minPath = [];
|
|
439
648
|
// TODO
|
|
440
|
-
|
|
649
|
+
var hasNegativeCycle;
|
|
441
650
|
if (scanNegativeCycle)
|
|
442
651
|
hasNegativeCycle = false;
|
|
443
652
|
if (!srcVertex)
|
|
444
|
-
return { hasNegativeCycle, distMap, preMap, paths, min, minPath };
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
this._vertices.forEach(vertex
|
|
653
|
+
return { hasNegativeCycle: hasNegativeCycle, distMap: distMap, preMap: preMap, paths: paths, min: min, minPath: minPath };
|
|
654
|
+
var vertices = this._vertices;
|
|
655
|
+
var numOfVertices = vertices.size;
|
|
656
|
+
var edges = this.edgeSet();
|
|
657
|
+
var numOfEdges = edges.length;
|
|
658
|
+
this._vertices.forEach(function (vertex) {
|
|
450
659
|
distMap.set(vertex, Infinity);
|
|
451
660
|
});
|
|
452
661
|
distMap.set(srcVertex, 0);
|
|
453
|
-
for (
|
|
454
|
-
for (
|
|
455
|
-
|
|
662
|
+
for (var i = 1; i < numOfVertices; ++i) {
|
|
663
|
+
for (var j = 0; j < numOfEdges; ++j) {
|
|
664
|
+
var ends = this.getEndsOfEdge(edges[j]);
|
|
456
665
|
if (ends) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
666
|
+
var _b = __read(ends, 2), s = _b[0], d = _b[1];
|
|
667
|
+
var weight = edges[j].weight;
|
|
668
|
+
var sWeight = distMap.get(s);
|
|
669
|
+
var dWeight = distMap.get(d);
|
|
461
670
|
if (sWeight !== undefined && dWeight !== undefined) {
|
|
462
671
|
if (distMap.get(s) !== Infinity && sWeight + weight < dWeight) {
|
|
463
672
|
distMap.set(d, sWeight + weight);
|
|
@@ -467,9 +676,9 @@ class AbstractGraph {
|
|
|
467
676
|
}
|
|
468
677
|
}
|
|
469
678
|
}
|
|
470
|
-
|
|
679
|
+
var minDest = null;
|
|
471
680
|
if (getMin) {
|
|
472
|
-
distMap.forEach((d, v)
|
|
681
|
+
distMap.forEach(function (d, v) {
|
|
473
682
|
if (v !== srcVertex) {
|
|
474
683
|
if (d < min) {
|
|
475
684
|
min = d;
|
|
@@ -480,59 +689,72 @@ class AbstractGraph {
|
|
|
480
689
|
});
|
|
481
690
|
}
|
|
482
691
|
if (genPath) {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
692
|
+
try {
|
|
693
|
+
for (var vertices_6 = __values(vertices), vertices_6_1 = vertices_6.next(); !vertices_6_1.done; vertices_6_1 = vertices_6.next()) {
|
|
694
|
+
var vertex = vertices_6_1.value;
|
|
695
|
+
var vertexOrId = vertex[1];
|
|
696
|
+
if (vertexOrId instanceof AbstractVertex) {
|
|
697
|
+
var path = [vertexOrId];
|
|
698
|
+
var parent = preMap.get(vertexOrId);
|
|
699
|
+
while (parent !== undefined) {
|
|
700
|
+
path.push(parent);
|
|
701
|
+
parent = preMap.get(parent);
|
|
702
|
+
}
|
|
703
|
+
var reversed = path.reverse();
|
|
704
|
+
if (vertex[1] === minDest)
|
|
705
|
+
minPath = reversed;
|
|
706
|
+
paths.push(reversed);
|
|
707
|
+
}
|
|
489
708
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
709
|
+
}
|
|
710
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
711
|
+
finally {
|
|
712
|
+
try {
|
|
713
|
+
if (vertices_6_1 && !vertices_6_1.done && (_a = vertices_6.return)) _a.call(vertices_6);
|
|
714
|
+
}
|
|
715
|
+
finally { if (e_14) throw e_14.error; }
|
|
494
716
|
}
|
|
495
717
|
}
|
|
496
|
-
for (
|
|
497
|
-
|
|
718
|
+
for (var j = 0; j < numOfEdges; ++j) {
|
|
719
|
+
var ends = this.getEndsOfEdge(edges[j]);
|
|
498
720
|
if (ends) {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
721
|
+
var _c = __read(ends, 1), s = _c[0];
|
|
722
|
+
var weight = edges[j].weight;
|
|
723
|
+
var sWeight = distMap.get(s);
|
|
502
724
|
if (sWeight) {
|
|
503
725
|
if (sWeight !== Infinity && sWeight + weight < sWeight)
|
|
504
726
|
hasNegativeCycle = true;
|
|
505
727
|
}
|
|
506
728
|
}
|
|
507
729
|
}
|
|
508
|
-
return { hasNegativeCycle, distMap, preMap, paths, min, minPath };
|
|
509
|
-
}
|
|
730
|
+
return { hasNegativeCycle: hasNegativeCycle, distMap: distMap, preMap: preMap, paths: paths, min: min, minPath: minPath };
|
|
731
|
+
};
|
|
510
732
|
/**
|
|
511
733
|
* Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
|
|
512
734
|
* all pairs
|
|
513
735
|
*/
|
|
514
|
-
floyd() {
|
|
736
|
+
AbstractGraph.prototype.floyd = function () {
|
|
515
737
|
var _a;
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
738
|
+
var idAndVertices = __spreadArray([], __read(this._vertices), false);
|
|
739
|
+
var n = idAndVertices.length;
|
|
740
|
+
var costs = [];
|
|
741
|
+
var predecessor = [];
|
|
520
742
|
// successors
|
|
521
|
-
for (
|
|
743
|
+
for (var i = 0; i < n; i++) {
|
|
522
744
|
costs[i] = [];
|
|
523
745
|
predecessor[i] = [];
|
|
524
|
-
for (
|
|
746
|
+
for (var j = 0; j < n; j++) {
|
|
525
747
|
predecessor[i][j] = null;
|
|
526
748
|
}
|
|
527
749
|
}
|
|
528
|
-
for (
|
|
529
|
-
for (
|
|
750
|
+
for (var i = 0; i < n; i++) {
|
|
751
|
+
for (var j = 0; j < n; j++) {
|
|
530
752
|
costs[i][j] = ((_a = this.getEdge(idAndVertices[i][1], idAndVertices[j][1])) === null || _a === void 0 ? void 0 : _a.weight) || Infinity;
|
|
531
753
|
}
|
|
532
754
|
}
|
|
533
|
-
for (
|
|
534
|
-
for (
|
|
535
|
-
for (
|
|
755
|
+
for (var k = 0; k < n; k++) {
|
|
756
|
+
for (var i = 0; i < n; i++) {
|
|
757
|
+
for (var j = 0; j < n; j++) {
|
|
536
758
|
if (costs[i][j] > costs[i][k] + costs[k][j]) {
|
|
537
759
|
costs[i][j] = costs[i][k] + costs[k][j];
|
|
538
760
|
predecessor[i][j] = idAndVertices[k][1];
|
|
@@ -540,8 +762,8 @@ class AbstractGraph {
|
|
|
540
762
|
}
|
|
541
763
|
}
|
|
542
764
|
}
|
|
543
|
-
return { costs, predecessor };
|
|
544
|
-
}
|
|
765
|
+
return { costs: costs, predecessor: predecessor };
|
|
766
|
+
};
|
|
545
767
|
/**--- start find cycles --- */
|
|
546
768
|
/**
|
|
547
769
|
* Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
|
|
@@ -550,11 +772,12 @@ class AbstractGraph {
|
|
|
550
772
|
* Tarjan solve the bi-connected components of undirected graphs;
|
|
551
773
|
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
552
774
|
*/
|
|
553
|
-
tarjan(needArticulationPoints, needBridges, needSCCs, needCycles) {
|
|
775
|
+
AbstractGraph.prototype.tarjan = function (needArticulationPoints, needBridges, needSCCs, needCycles) {
|
|
554
776
|
// !! in undirected graph we will not let child visit parent when DFS
|
|
555
777
|
// !! articulation point(in DFS search tree not in graph): (cur !== root && cur.has(child)) && (low(child) >= dfn(cur)) || (cur === root && cur.children() >= 2)
|
|
556
778
|
// !! bridge: low(child) > dfn(cur)
|
|
557
|
-
|
|
779
|
+
var _this = this;
|
|
780
|
+
var defaultConfig = false;
|
|
558
781
|
if (needArticulationPoints === undefined)
|
|
559
782
|
needArticulationPoints = defaultConfig;
|
|
560
783
|
if (needBridges === undefined)
|
|
@@ -563,60 +786,71 @@ class AbstractGraph {
|
|
|
563
786
|
needSCCs = defaultConfig;
|
|
564
787
|
if (needCycles === undefined)
|
|
565
788
|
needCycles = defaultConfig;
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
vertices.forEach(v
|
|
789
|
+
var dfnMap = new Map();
|
|
790
|
+
var lowMap = new Map();
|
|
791
|
+
var vertices = this._vertices;
|
|
792
|
+
vertices.forEach(function (v) {
|
|
570
793
|
dfnMap.set(v, -1);
|
|
571
794
|
lowMap.set(v, Infinity);
|
|
572
795
|
});
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
796
|
+
var _a = __read(vertices.values(), 1), root = _a[0];
|
|
797
|
+
var articulationPoints = [];
|
|
798
|
+
var bridges = [];
|
|
799
|
+
var dfn = 0;
|
|
800
|
+
var dfs = function (cur, parent) {
|
|
801
|
+
var e_15, _a;
|
|
578
802
|
dfn++;
|
|
579
803
|
dfnMap.set(cur, dfn);
|
|
580
804
|
lowMap.set(cur, dfn);
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
if (childLow !== undefined && curFromMap !== undefined) {
|
|
597
|
-
if (needArticulationPoints) {
|
|
598
|
-
if ((cur === root && childCount >= 2) || ((cur !== root) && (childLow >= curFromMap))) {
|
|
599
|
-
// todo not ensure the logic if (cur === root && childCount >= 2 || ((cur !== root) && (childLow >= curFromMap))) {
|
|
600
|
-
articulationPoints.push(cur);
|
|
601
|
-
}
|
|
805
|
+
var neighbors = _this.getNeighbors(cur);
|
|
806
|
+
var childCount = 0; // child in DFS tree not child in graph
|
|
807
|
+
try {
|
|
808
|
+
for (var neighbors_6 = __values(neighbors), neighbors_6_1 = neighbors_6.next(); !neighbors_6_1.done; neighbors_6_1 = neighbors_6.next()) {
|
|
809
|
+
var neighbor = neighbors_6_1.value;
|
|
810
|
+
if (neighbor !== parent) {
|
|
811
|
+
if (dfnMap.get(neighbor) === -1) {
|
|
812
|
+
childCount++;
|
|
813
|
+
dfs(neighbor, cur);
|
|
814
|
+
}
|
|
815
|
+
var childLow = lowMap.get(neighbor);
|
|
816
|
+
var curLow = lowMap.get(cur);
|
|
817
|
+
// TODO after no-non-null-assertion not ensure the logic
|
|
818
|
+
if (curLow !== undefined && childLow !== undefined) {
|
|
819
|
+
lowMap.set(cur, Math.min(curLow, childLow));
|
|
602
820
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
if (
|
|
607
|
-
|
|
821
|
+
var curFromMap = dfnMap.get(cur);
|
|
822
|
+
if (childLow !== undefined && curFromMap !== undefined) {
|
|
823
|
+
if (needArticulationPoints) {
|
|
824
|
+
if ((cur === root && childCount >= 2) || ((cur !== root) && (childLow >= curFromMap))) {
|
|
825
|
+
// todo not ensure the logic if (cur === root && childCount >= 2 || ((cur !== root) && (childLow >= curFromMap))) {
|
|
826
|
+
articulationPoints.push(cur);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
if (needBridges) {
|
|
830
|
+
if (childLow > curFromMap) {
|
|
831
|
+
var edgeCurToNeighbor = _this.getEdge(cur, neighbor);
|
|
832
|
+
if (edgeCurToNeighbor) {
|
|
833
|
+
bridges.push(edgeCurToNeighbor);
|
|
834
|
+
}
|
|
608
835
|
}
|
|
609
836
|
}
|
|
610
837
|
}
|
|
611
838
|
}
|
|
612
839
|
}
|
|
613
840
|
}
|
|
841
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
842
|
+
finally {
|
|
843
|
+
try {
|
|
844
|
+
if (neighbors_6_1 && !neighbors_6_1.done && (_a = neighbors_6.return)) _a.call(neighbors_6);
|
|
845
|
+
}
|
|
846
|
+
finally { if (e_15) throw e_15.error; }
|
|
847
|
+
}
|
|
614
848
|
};
|
|
615
849
|
dfs(root, null);
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
lowMap.forEach((low, vertex)
|
|
850
|
+
var SCCs = new Map();
|
|
851
|
+
var getSCCs = function () {
|
|
852
|
+
var SCCs = new Map();
|
|
853
|
+
lowMap.forEach(function (low, vertex) {
|
|
620
854
|
var _a;
|
|
621
855
|
if (!SCCs.has(low)) {
|
|
622
856
|
SCCs.set(low, [vertex]);
|
|
@@ -630,19 +864,20 @@ class AbstractGraph {
|
|
|
630
864
|
if (needSCCs) {
|
|
631
865
|
SCCs = getSCCs();
|
|
632
866
|
}
|
|
633
|
-
|
|
867
|
+
var cycles = new Map();
|
|
634
868
|
if (needCycles) {
|
|
635
|
-
|
|
636
|
-
if (
|
|
637
|
-
|
|
869
|
+
var SCCs_1 = new Map();
|
|
870
|
+
if (SCCs_1.size < 1) {
|
|
871
|
+
SCCs_1 = getSCCs();
|
|
638
872
|
}
|
|
639
|
-
|
|
873
|
+
SCCs_1.forEach(function (SCC, low) {
|
|
640
874
|
if (SCC.length > 1) {
|
|
641
875
|
cycles.set(low, SCC);
|
|
642
876
|
}
|
|
643
877
|
});
|
|
644
878
|
}
|
|
645
|
-
return { dfnMap, lowMap, bridges, articulationPoints, SCCs, cycles };
|
|
646
|
-
}
|
|
647
|
-
|
|
879
|
+
return { dfnMap: dfnMap, lowMap: lowMap, bridges: bridges, articulationPoints: articulationPoints, SCCs: SCCs, cycles: cycles };
|
|
880
|
+
};
|
|
881
|
+
return AbstractGraph;
|
|
882
|
+
}());
|
|
648
883
|
exports.AbstractGraph = AbstractGraph;
|