data-structure-typed 1.50.1 → 1.50.3
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 +2 -1
- package/README.md +30 -28
- package/README_zh-CN.md +1 -1
- package/SPECIFICATION.md +56 -0
- package/SPONSOR-zh-CN.md +90 -0
- package/SPONSOR.md +54 -0
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +149 -161
- package/dist/cjs/data-structures/base/iterable-base.d.ts +120 -9
- package/dist/cjs/data-structures/base/iterable-base.js +143 -7
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +72 -47
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +101 -72
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +484 -376
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +92 -79
- package/dist/cjs/data-structures/binary-tree/bst.js +68 -76
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +127 -57
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +152 -99
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +72 -58
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +102 -85
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -78
- package/dist/cjs/data-structures/graph/abstract-graph.js +3 -189
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +73 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +131 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +8 -0
- package/dist/cjs/data-structures/graph/map-graph.js +14 -0
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +76 -7
- package/dist/cjs/data-structures/graph/undirected-graph.js +151 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +254 -28
- package/dist/cjs/data-structures/hash/hash-map.js +347 -78
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +95 -25
- package/dist/cjs/data-structures/heap/heap.js +95 -26
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +126 -63
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +141 -77
- 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 +154 -106
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +164 -115
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +63 -36
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.d.ts +35 -4
- package/dist/cjs/data-structures/matrix/matrix.js +50 -11
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +139 -35
- package/dist/cjs/data-structures/queue/deque.js +200 -62
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +103 -49
- package/dist/cjs/data-structures/queue/queue.js +111 -49
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +51 -21
- package/dist/cjs/data-structures/stack/stack.js +58 -22
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/tree/tree.d.ts +57 -3
- package/dist/cjs/data-structures/tree/tree.js +77 -11
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +135 -34
- package/dist/cjs/data-structures/trie/trie.js +153 -33
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/hash/hash-map.d.ts +4 -3
- package/dist/cjs/types/utils/utils.d.ts +1 -0
- package/dist/mjs/data-structures/base/iterable-base.d.ts +120 -9
- package/dist/mjs/data-structures/base/iterable-base.js +143 -7
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +72 -47
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +102 -73
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +483 -375
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +92 -79
- package/dist/mjs/data-structures/binary-tree/bst.js +68 -76
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +127 -57
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +153 -100
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +72 -58
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +102 -86
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -78
- package/dist/mjs/data-structures/graph/abstract-graph.js +3 -188
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +73 -0
- package/dist/mjs/data-structures/graph/directed-graph.js +131 -0
- package/dist/mjs/data-structures/graph/map-graph.d.ts +8 -0
- package/dist/mjs/data-structures/graph/map-graph.js +14 -0
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +76 -7
- package/dist/mjs/data-structures/graph/undirected-graph.js +152 -19
- package/dist/mjs/data-structures/hash/hash-map.d.ts +254 -28
- package/dist/mjs/data-structures/hash/hash-map.js +353 -84
- package/dist/mjs/data-structures/heap/heap.d.ts +95 -25
- package/dist/mjs/data-structures/heap/heap.js +95 -26
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +126 -63
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +144 -80
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +154 -106
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +166 -117
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +63 -36
- package/dist/mjs/data-structures/matrix/matrix.d.ts +35 -4
- package/dist/mjs/data-structures/matrix/matrix.js +50 -11
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/mjs/data-structures/queue/deque.d.ts +139 -35
- package/dist/mjs/data-structures/queue/deque.js +205 -67
- package/dist/mjs/data-structures/queue/queue.d.ts +103 -49
- package/dist/mjs/data-structures/queue/queue.js +111 -49
- package/dist/mjs/data-structures/stack/stack.d.ts +51 -21
- package/dist/mjs/data-structures/stack/stack.js +58 -22
- package/dist/mjs/data-structures/tree/tree.d.ts +57 -3
- package/dist/mjs/data-structures/tree/tree.js +80 -14
- package/dist/mjs/data-structures/trie/trie.d.ts +135 -34
- package/dist/mjs/data-structures/trie/trie.js +156 -36
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/hash/hash-map.d.ts +4 -3
- package/dist/mjs/types/utils/utils.d.ts +1 -0
- package/dist/umd/data-structure-typed.js +3121 -1583
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +61 -55
- package/src/data-structures/base/iterable-base.ts +184 -19
- package/src/data-structures/binary-tree/avl-tree.ts +134 -100
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +674 -671
- package/src/data-structures/binary-tree/bst.ts +127 -136
- package/src/data-structures/binary-tree/rb-tree.ts +199 -166
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multimap.ts +138 -115
- package/src/data-structures/graph/abstract-graph.ts +4 -211
- package/src/data-structures/graph/directed-graph.ts +152 -0
- package/src/data-structures/graph/map-graph.ts +15 -0
- package/src/data-structures/graph/undirected-graph.ts +171 -19
- package/src/data-structures/hash/hash-map.ts +389 -96
- package/src/data-structures/heap/heap.ts +97 -26
- package/src/data-structures/linked-list/doubly-linked-list.ts +156 -83
- package/src/data-structures/linked-list/singly-linked-list.ts +174 -120
- package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
- package/src/data-structures/matrix/matrix.ts +52 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
- package/src/data-structures/priority-queue/priority-queue.ts +8 -0
- package/src/data-structures/queue/deque.ts +225 -70
- package/src/data-structures/queue/queue.ts +118 -49
- package/src/data-structures/stack/stack.ts +63 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +173 -38
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/hash/hash-map.ts +4 -3
- package/src/types/utils/utils.ts +2 -0
- package/test/performance/data-structures/graph/directed-graph.test.ts +4 -4
- package/test/performance/data-structures/queue/deque.test.ts +26 -25
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +37 -0
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -17
- package/test/unit/data-structures/binary-tree/bst.test.ts +65 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +38 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -32
- package/test/unit/data-structures/graph/abstract-graph.test.ts +11 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +190 -5
- package/test/unit/data-structures/graph/undirected-graph.test.ts +263 -18
- package/test/unit/data-structures/hash/hash-map.test.ts +376 -353
- package/test/unit/data-structures/heap/heap.test.ts +18 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +24 -5
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +20 -2
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +65 -5
- package/test/unit/data-structures/queue/queue.test.ts +24 -5
- package/test/unit/data-structures/stack/stack.test.ts +17 -0
- package/test/unit/data-structures/trie/trie.test.ts +17 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UndirectedEdge, UndirectedGraph, UndirectedVertex } from '../../../../src';
|
|
2
|
-
import
|
|
2
|
+
import saltyVertices from './salty-vertexes.json';
|
|
3
3
|
import saltyEdges from './salty-edges.json';
|
|
4
4
|
|
|
5
5
|
describe('UndirectedGraph Operation Test', () => {
|
|
@@ -17,7 +17,7 @@ describe('UndirectedGraph Operation Test', () => {
|
|
|
17
17
|
expect(graph.getEndsOfEdge(new UndirectedEdge('c', 'd'))).toBe(undefined);
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
it('should add
|
|
20
|
+
it('should add vertices', () => {
|
|
21
21
|
const vertex1 = new UndirectedVertex('A');
|
|
22
22
|
const vertex2 = new UndirectedVertex('B');
|
|
23
23
|
|
|
@@ -76,8 +76,8 @@ describe('UndirectedGraph', () => {
|
|
|
76
76
|
undirectedGraph = new UndirectedGraph<string, string>();
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
// Test adding
|
|
80
|
-
it('should add
|
|
79
|
+
// Test adding vertices to the graph
|
|
80
|
+
it('should add vertices to the graph', () => {
|
|
81
81
|
const vertexA = new UndirectedVertex('A', 'Location A');
|
|
82
82
|
const vertexB = new UndirectedVertex('B', 'Location B');
|
|
83
83
|
|
|
@@ -130,7 +130,7 @@ describe('UndirectedGraph', () => {
|
|
|
130
130
|
const edgeAB = new UndirectedEdge('A', 'B', 3, 'Edge between A and B');
|
|
131
131
|
const edgeBC = new UndirectedEdge('B', 'C', 4, 'Edge between B and C');
|
|
132
132
|
|
|
133
|
-
edgeAB.
|
|
133
|
+
edgeAB.endpoints = edgeAB.endpoints;
|
|
134
134
|
expect(undirectedGraph.edgeMap.size).toBe(0);
|
|
135
135
|
undirectedGraph.addVertex(vertexA);
|
|
136
136
|
undirectedGraph.addVertex(vertexB);
|
|
@@ -151,7 +151,7 @@ describe('UndirectedGraph', () => {
|
|
|
151
151
|
|
|
152
152
|
it('should getAllPathsBetween work well in 66 vertexes 97 edges graph', () => {
|
|
153
153
|
const graph = new UndirectedGraph<{ name: string }, number>();
|
|
154
|
-
for (const v of
|
|
154
|
+
for (const v of saltyVertices) {
|
|
155
155
|
graph.addVertex(v.name, v);
|
|
156
156
|
}
|
|
157
157
|
for (const e of saltyEdges) {
|
|
@@ -181,16 +181,16 @@ describe('UndirectedGraph', () => {
|
|
|
181
181
|
dg.addVertex('hey');
|
|
182
182
|
dg.addEdge('hello', 'hi');
|
|
183
183
|
dg.addEdge('hello', 'hey');
|
|
184
|
-
expect(dg.getEdge('hello', 'hi')?.
|
|
185
|
-
expect(dg.getEdge('hello', 'hi')?.
|
|
186
|
-
expect(dg.getEdge('hello', 'hey')?.
|
|
187
|
-
expect(dg.getEdge('hello', 'hey')?.
|
|
184
|
+
expect(dg.getEdge('hello', 'hi')?.endpoints[0]).toBe('hello');
|
|
185
|
+
expect(dg.getEdge('hello', 'hi')?.endpoints[1]).toBe('hi');
|
|
186
|
+
expect(dg.getEdge('hello', 'hey')?.endpoints[0]).toBe('hello');
|
|
187
|
+
expect(dg.getEdge('hello', 'hey')?.endpoints[1]).toBe('hey');
|
|
188
188
|
dg.deleteEdge('hello', 'hi');
|
|
189
189
|
expect(dg.getEdge('hello', 'hi')).toBe(undefined);
|
|
190
190
|
expect(dg.getEdge('hello', 'hey')).toBeInstanceOf(UndirectedEdge);
|
|
191
191
|
});
|
|
192
192
|
|
|
193
|
-
test('Removing a vertex of a
|
|
193
|
+
test('Removing a vertex of a UndirectedGraph should delete additional edges', () => {
|
|
194
194
|
const graph = new UndirectedGraph();
|
|
195
195
|
|
|
196
196
|
graph.addVertex('Hello');
|
|
@@ -212,13 +212,13 @@ describe('UndirectedGraph', () => {
|
|
|
212
212
|
dg.addEdge('hello', 'earth');
|
|
213
213
|
dg.addEdge('world', 'earth');
|
|
214
214
|
|
|
215
|
-
expect(dg.getEdge('hello', 'world')?.
|
|
215
|
+
expect(dg.getEdge('hello', 'world')?.endpoints[0]).toBe('hello');
|
|
216
216
|
expect(dg.edgeSet().length).toBe(3);
|
|
217
|
-
expect(dg.edgeSet()[0].
|
|
217
|
+
expect(dg.edgeSet()[0].endpoints).toEqual(['hello', 'world']);
|
|
218
218
|
|
|
219
219
|
dg.deleteVertex('hello');
|
|
220
220
|
expect(dg.edgeSet().length).toBe(1);
|
|
221
|
-
expect(dg.edgeSet()?.[0].
|
|
221
|
+
expect(dg.edgeSet()?.[0].endpoints[0]).toBe('world');
|
|
222
222
|
|
|
223
223
|
expect(dg.getEdge('hello', 'world')).toBe(undefined);
|
|
224
224
|
});
|
|
@@ -244,15 +244,15 @@ describe('cycles, strongly connected components, bridges, articular points in Un
|
|
|
244
244
|
graph.addEdge('E', 'H');
|
|
245
245
|
graph.addEdge('H', 'F');
|
|
246
246
|
const cycles = graph.getCycles();
|
|
247
|
-
const
|
|
247
|
+
// const cCs = graph.getCCs();
|
|
248
248
|
const bridges = graph.getBridges();
|
|
249
|
-
const
|
|
249
|
+
const cutVertices = graph.getCutVertices();
|
|
250
250
|
const dfnMap = graph.getDFNMap();
|
|
251
251
|
const lowMap = graph.getLowMap();
|
|
252
252
|
expect(cycles.length).toBe(3);
|
|
253
|
-
expect(
|
|
253
|
+
// expect(cCs.size).toBe(5);
|
|
254
254
|
expect(bridges.length).toBe(4);
|
|
255
|
-
expect(
|
|
255
|
+
expect(cutVertices.length).toBe(4);
|
|
256
256
|
expect(dfnMap.size).toBe(8);
|
|
257
257
|
expect(lowMap.size).toBe(8);
|
|
258
258
|
});
|
|
@@ -356,3 +356,248 @@ describe('UndirectedGraph getCycles', () => {
|
|
|
356
356
|
]);
|
|
357
357
|
});
|
|
358
358
|
});
|
|
359
|
+
|
|
360
|
+
describe('UndirectedGraph tarjan', () => {
|
|
361
|
+
test('should simple cycles graph tarjan cycles return correct result', () => {
|
|
362
|
+
const graph = new UndirectedGraph();
|
|
363
|
+
|
|
364
|
+
graph.addVertex('A');
|
|
365
|
+
graph.addVertex('B');
|
|
366
|
+
graph.addVertex('C');
|
|
367
|
+
graph.addVertex('D');
|
|
368
|
+
|
|
369
|
+
graph.addEdge('A', 'B');
|
|
370
|
+
graph.addEdge('B', 'C');
|
|
371
|
+
graph.addEdge('C', 'A');
|
|
372
|
+
graph.addEdge('A', 'D');
|
|
373
|
+
graph.addEdge('D', 'C');
|
|
374
|
+
const cycles = graph.getCycles();
|
|
375
|
+
expect(cycles.length).toBe(3);
|
|
376
|
+
expect(cycles).toEqual([
|
|
377
|
+
['A', 'B', 'C'],
|
|
378
|
+
['A', 'B', 'C', 'D'],
|
|
379
|
+
['A', 'C', 'D']
|
|
380
|
+
]);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
function createExampleGraph1() {
|
|
384
|
+
const graph = new UndirectedGraph();
|
|
385
|
+
graph.addVertex('A');
|
|
386
|
+
graph.addVertex('B');
|
|
387
|
+
graph.addVertex('C');
|
|
388
|
+
graph.addVertex('D');
|
|
389
|
+
graph.addVertex('E');
|
|
390
|
+
graph.addEdge('A', 'B');
|
|
391
|
+
graph.addEdge('A', 'C');
|
|
392
|
+
graph.addEdge('B', 'D');
|
|
393
|
+
graph.addEdge('C', 'D');
|
|
394
|
+
graph.addEdge('D', 'E');
|
|
395
|
+
graph.addEdge('E', 'B');
|
|
396
|
+
return graph;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
test('should tarjan cut vertexes return correct result', () => {
|
|
400
|
+
const graph = createExampleGraph1();
|
|
401
|
+
const cutVertices = graph.tarjan().cutVertices;
|
|
402
|
+
expect(cutVertices.length).toBe(0);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
test('should tarjan bridges return correct result', () => {
|
|
406
|
+
const graph = createExampleGraph1();
|
|
407
|
+
const bridges = graph.tarjan().bridges;
|
|
408
|
+
expect(bridges.length).toBe(0);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
test('should 3 cycles graph tarjan cut vertexes return correct result', () => {
|
|
412
|
+
const graph = createExampleGraph1();
|
|
413
|
+
const cutVertices = graph.tarjan().cutVertices;
|
|
414
|
+
expect(cutVertices.length).toBe(0);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
test('should 3 cycles graph tarjan bridges return correct result', () => {
|
|
418
|
+
const graph = createExampleGraph1();
|
|
419
|
+
const bridges = graph.tarjan().bridges;
|
|
420
|
+
expect(bridges.length).toBe(0);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
test('should cuttable graph tarjan cut vertexes return correct result', () => {
|
|
424
|
+
const graph = createExampleGraph3();
|
|
425
|
+
const cutVertices = graph.tarjan().cutVertices;
|
|
426
|
+
expect(cutVertices.length).toBe(3);
|
|
427
|
+
expect(cutVertices.map(cv => cv.key)).toEqual(['B', 'E', 'A']);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
test('should cuttable graph tarjan bridges return correct result', () => {
|
|
431
|
+
const graph = createExampleGraph3();
|
|
432
|
+
const bridges = graph.tarjan().bridges;
|
|
433
|
+
expect(bridges.length).toBe(2);
|
|
434
|
+
expect(bridges.map(edge => edge.endpoints)).toEqual([
|
|
435
|
+
['A', 'B'],
|
|
436
|
+
['A', 'E']
|
|
437
|
+
]);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
test('should more cuttable graph tarjan cut vertexes return correct result', () => {
|
|
441
|
+
const graph = createExampleGraph4();
|
|
442
|
+
const cutVertices = graph.tarjan().cutVertices;
|
|
443
|
+
expect(cutVertices.length).toBe(4);
|
|
444
|
+
expect(cutVertices.map(cv => cv.key)).toEqual(['H', 'B', 'E', 'A']);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
test('should more cuttable graph tarjan bridges return correct result', () => {
|
|
448
|
+
const graph = createExampleGraph4();
|
|
449
|
+
const bridges = graph.tarjan().bridges;
|
|
450
|
+
expect(bridges.length).toBe(2);
|
|
451
|
+
expect(bridges.map(edge => edge.endpoints)).toEqual([
|
|
452
|
+
['A', 'B'],
|
|
453
|
+
['A', 'E']
|
|
454
|
+
]);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
test('should uncuttable graph tarjan cut vertexes return correct result', () => {
|
|
458
|
+
const graph = createExampleGraph5();
|
|
459
|
+
const cutVertices = graph.tarjan().cutVertices;
|
|
460
|
+
expect(cutVertices.length).toBe(1);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
test('should uncuttable graph tarjan bridges return correct result', () => {
|
|
464
|
+
const graph = createExampleGraph5();
|
|
465
|
+
const bridges = graph.tarjan().bridges;
|
|
466
|
+
expect(bridges.length).toBe(0);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
function createExampleGraph2() {
|
|
470
|
+
const graph = createExampleGraph1();
|
|
471
|
+
graph.addVertex('F');
|
|
472
|
+
graph.addVertex('G');
|
|
473
|
+
graph.addEdge('B', 'F');
|
|
474
|
+
graph.addEdge('F', 'E');
|
|
475
|
+
graph.addEdge('C', 'G');
|
|
476
|
+
graph.addEdge('G', 'A');
|
|
477
|
+
return graph;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
test('should 3 cycles graph tarjan cycles return correct result', () => {
|
|
481
|
+
const graph = createExampleGraph2();
|
|
482
|
+
const cycles = graph.getCycles();
|
|
483
|
+
expect(cycles.length).toBe(10);
|
|
484
|
+
expect(cycles).toEqual([
|
|
485
|
+
['A', 'B', 'D', 'C'],
|
|
486
|
+
['A', 'B', 'D', 'C', 'G'],
|
|
487
|
+
['A', 'B', 'E', 'D', 'C'],
|
|
488
|
+
['A', 'B', 'E', 'D', 'C', 'G'],
|
|
489
|
+
['A', 'B', 'F', 'E', 'D', 'C'],
|
|
490
|
+
['A', 'B', 'F', 'E', 'D', 'C', 'G'],
|
|
491
|
+
['A', 'C', 'G'],
|
|
492
|
+
['B', 'D', 'E'],
|
|
493
|
+
['B', 'D', 'E', 'F'],
|
|
494
|
+
['B', 'E', 'F']
|
|
495
|
+
]);
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
function createExampleGraph3() {
|
|
499
|
+
const graph = new UndirectedGraph();
|
|
500
|
+
graph.addVertex('A');
|
|
501
|
+
graph.addVertex('B');
|
|
502
|
+
graph.addVertex('C');
|
|
503
|
+
graph.addVertex('D');
|
|
504
|
+
graph.addVertex('E');
|
|
505
|
+
graph.addVertex('F');
|
|
506
|
+
graph.addVertex('G');
|
|
507
|
+
graph.addEdge('A', 'B');
|
|
508
|
+
graph.addEdge('B', 'C');
|
|
509
|
+
graph.addEdge('C', 'D');
|
|
510
|
+
graph.addEdge('D', 'B');
|
|
511
|
+
graph.addEdge('A', 'E');
|
|
512
|
+
graph.addEdge('E', 'F');
|
|
513
|
+
graph.addEdge('F', 'G');
|
|
514
|
+
graph.addEdge('G', 'E');
|
|
515
|
+
return graph;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
test('should cuttable graph tarjan cycles return correct result', () => {
|
|
519
|
+
const graph = createExampleGraph3();
|
|
520
|
+
const cycles = graph.getCycles();
|
|
521
|
+
expect(cycles.length).toBe(2);
|
|
522
|
+
expect(cycles).toEqual([
|
|
523
|
+
['B', 'C', 'D'],
|
|
524
|
+
['E', 'F', 'G']
|
|
525
|
+
]);
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
// test('should cuttable graph tarjan CCs return correct result', () => {
|
|
529
|
+
// const graph = createExampleGraph3();
|
|
530
|
+
// const ccs = graph.tarjan().CCs;
|
|
531
|
+
// expect(ccs.size).toBe(3);
|
|
532
|
+
// expect(getAsVerticesArrays(ccs)).toEqual([["D", "C", "B"], ["G", "F", "E"], ["A"]]);
|
|
533
|
+
// });
|
|
534
|
+
|
|
535
|
+
function createExampleGraph4() {
|
|
536
|
+
const graph = createExampleGraph3();
|
|
537
|
+
graph.addVertex('H');
|
|
538
|
+
graph.addVertex('I');
|
|
539
|
+
graph.addVertex('J');
|
|
540
|
+
graph.addVertex('K');
|
|
541
|
+
graph.addEdge('C', 'H');
|
|
542
|
+
graph.addEdge('H', 'I');
|
|
543
|
+
graph.addEdge('I', 'D');
|
|
544
|
+
graph.addEdge('H', 'J');
|
|
545
|
+
graph.addEdge('J', 'K');
|
|
546
|
+
graph.addEdge('K', 'H');
|
|
547
|
+
return graph;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
test('should more cuttable graph tarjan cycles return correct result', () => {
|
|
551
|
+
const graph = createExampleGraph4();
|
|
552
|
+
const cycles = graph.getCycles();
|
|
553
|
+
expect(cycles.length).toBe(5);
|
|
554
|
+
expect(cycles).toEqual([
|
|
555
|
+
['B', 'C', 'D'],
|
|
556
|
+
['B', 'C', 'H', 'I', 'D'],
|
|
557
|
+
['C', 'D', 'I', 'H'],
|
|
558
|
+
['E', 'F', 'G'],
|
|
559
|
+
['H', 'J', 'K']
|
|
560
|
+
]);
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
// test('should more cuttable graph tarjan SCCs return correct result', () => {
|
|
564
|
+
// const graph = createExampleGraph4();
|
|
565
|
+
// const ccs = graph.tarjan().CCs;
|
|
566
|
+
// expect(ccs.size).toBe(3);
|
|
567
|
+
// expect(getAsVerticesArrays(ccs)).toEqual([["K", "J", "I", "H", "D", "C", "B"], ["G", "F", "E"], ["A"]]);
|
|
568
|
+
// });
|
|
569
|
+
|
|
570
|
+
function createExampleGraph5() {
|
|
571
|
+
const graph = createExampleGraph4();
|
|
572
|
+
graph.addEdge('F', 'H');
|
|
573
|
+
return graph;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
test('should uncuttable graph tarjan cycles return correct result', () => {
|
|
577
|
+
const graph = createExampleGraph5();
|
|
578
|
+
const cycles = graph.getCycles();
|
|
579
|
+
expect(cycles.length).toBe(13);
|
|
580
|
+
expect(cycles).toEqual([
|
|
581
|
+
['A', 'B', 'C', 'D', 'I', 'H', 'F', 'E'],
|
|
582
|
+
['A', 'B', 'C', 'D', 'I', 'H', 'F', 'G', 'E'],
|
|
583
|
+
['A', 'B', 'C', 'H', 'F', 'E'],
|
|
584
|
+
['A', 'B', 'C', 'H', 'F', 'G', 'E'],
|
|
585
|
+
['A', 'B', 'D', 'C', 'H', 'F', 'E'],
|
|
586
|
+
['A', 'B', 'D', 'C', 'H', 'F', 'G', 'E'],
|
|
587
|
+
['A', 'B', 'D', 'I', 'H', 'F', 'E'],
|
|
588
|
+
['A', 'B', 'D', 'I', 'H', 'F', 'G', 'E'],
|
|
589
|
+
['B', 'C', 'D'],
|
|
590
|
+
['B', 'C', 'H', 'I', 'D'],
|
|
591
|
+
['C', 'D', 'I', 'H'],
|
|
592
|
+
['E', 'F', 'G'],
|
|
593
|
+
['H', 'J', 'K']
|
|
594
|
+
]);
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
// test('should uncuttable graph tarjan SCCs return correct result', () => {
|
|
598
|
+
// const graph = createExampleGraph5();
|
|
599
|
+
// const ccs = graph.tarjan().CCs;
|
|
600
|
+
// expect(ccs.size).toBe(3);
|
|
601
|
+
// expect(getAsVerticesArrays(ccs)).toEqual([["K", "J", "I", "H", "D", "C", "B"], ["G", "F", "E"], ["A"]]);
|
|
602
|
+
// });
|
|
603
|
+
});
|