Skip to content

Commit 15b6367

Browse files
committed
feat: export detectAllCycles, detectAllDirectedCycle, detectAllUndirectedCycle
1 parent 939f02f commit 15b6367

5 files changed

Lines changed: 61 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
- fix: CPU usage increases due to 0.1.3-beta ~ 0.1.3 with publicPath configuration;
55
- fix: CPU usage increases due to 0.1.6 ~ 0.17 with browser output;
6+
- feat: export fix: export detectAllCycles, detectAllDirectedCycle, detectAllUndirectedCycle;
67

78
#### 0.1.6
89

@@ -12,6 +13,7 @@
1213

1314
- fix: worker async problem;
1415
- chore: unify allPath and allPaths;
16+
1517
#### 0.1.2
1618

1719
- fix: failed to find result problem in dijkstra;

packages/graph/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/algorithm",
3-
"version": "0.1.8-beta.7",
3+
"version": "0.1.8",
44
"description": "graph algorithm",
55
"keywords": [
66
"graph",

packages/graph/src/index.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import breadthFirstSearch from './bfs';
33
import connectedComponent from './connected-component';
44
import getDegree from './degree';
55
import { getInDegree, getOutDegree } from './degree';
6-
import detectCycle from './detect-cycle';
6+
import detectCycle, { detectAllCycles, detectAllDirectedCycle, detectAllUndirectedCycle } from './detect-cycle';
77
import depthFirstSearch from './dfs';
88
import dijkstra from './dijkstra';
99
import { findAllPath, findShortestPath } from './find-path';
@@ -16,13 +16,19 @@ import GADDI from './gaddi';
1616
import Stack from './structs/stack';
1717
import { getNeighbors } from './util';
1818

19+
const detectDirectedCycle = detectCycle;
20+
const detectDirectedCycleAsync = detectCycleAsync;
21+
1922
import {
2023
getAdjMatrixAsync,
2124
connectedComponentAsync,
2225
getDegreeAsync,
2326
getInDegreeAsync,
2427
getOutDegreeAsync,
2528
detectCycleAsync,
29+
detectAllCyclesAsync,
30+
detectAllDirectedCycleAsync,
31+
detectAllUndirectedCycleAsync,
2632
dijkstraAsync,
2733
findAllPathAsync,
2834
findShortestPathAsync,
@@ -43,6 +49,10 @@ export {
4349
getInDegree,
4450
getOutDegree,
4551
detectCycle,
52+
detectDirectedCycle,
53+
detectAllCycles,
54+
detectAllDirectedCycle,
55+
detectAllUndirectedCycle,
4656
depthFirstSearch,
4757
dijkstra,
4858
findAllPath,
@@ -61,6 +71,10 @@ export {
6171
getInDegreeAsync,
6272
getOutDegreeAsync,
6373
detectCycleAsync,
74+
detectDirectedCycleAsync,
75+
detectAllCyclesAsync,
76+
detectAllDirectedCycleAsync,
77+
detectAllUndirectedCycleAsync,
6478
dijkstraAsync,
6579
findAllPathAsync,
6680
findShortestPathAsync,
@@ -81,6 +95,10 @@ export default {
8195
getInDegree,
8296
getOutDegree,
8397
detectCycle,
98+
detectDirectedCycle,
99+
detectAllCycles,
100+
detectAllDirectedCycle,
101+
detectAllUndirectedCycle,
84102
depthFirstSearch,
85103
dijkstra,
86104
findAllPath,
@@ -99,6 +117,10 @@ export default {
99117
getInDegreeAsync,
100118
getOutDegreeAsync,
101119
detectCycleAsync,
120+
detectDirectedCycleAsync,
121+
detectAllCyclesAsync,
122+
detectAllDirectedCycleAsync,
123+
detectAllUndirectedCycleAsync,
102124
dijkstraAsync,
103125
findAllPathAsync,
104126
findShortestPathAsync,

packages/graph/src/workers/constant.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ export const ALGORITHM = {
44
connectedComponent: 'connectedComponent',
55
depthFirstSearch: 'depthFirstSearch',
66
detectCycle: 'detectCycle',
7+
detectDirectedCycle: 'detectDirectedCycle',
8+
detectAllCycles: 'detectAllCycles',
9+
detectAllDirectedCycle: 'detectAllDirectedCycle',
10+
detectAllUndirectedCycle: 'detectAllUndirectedCycle',
711
dijkstra: 'dijkstra',
812
findAllPath: 'findAllPath',
913
findShortestPath: 'findShortestPath',

packages/graph/src/workers/index.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
GraphData,
33
DegreeType,
44
Matrix,
5-
IAlgorithmCallbacks,
65
ClusterData,
76
EdgeConfig,
87
NodeConfig,
@@ -49,14 +48,41 @@ const getOutDegreeAsync = (graphData: GraphData, nodeId: string) =>
4948
createWorker<DegreeType>(ALGORITHM.getOutDegree)(graphData, nodeId);
5049

5150
/**
52-
* 检测图中的 Cycle
51+
* 检测图中的(有向) Cycle
5352
* @param graphData 图数据
5453
*/
5554
const detectCycleAsync = (graphData: GraphData) =>
5655
createWorker<{
5756
[key: string]: string;
5857
}>(ALGORITHM.detectCycle)(graphData);
5958

59+
/**
60+
* 检测图中的(无向) Cycle
61+
* @param graphData 图数据
62+
*/
63+
const detectAllCyclesAsync = (graphData: GraphData) =>
64+
createWorker<{
65+
[key: string]: string;
66+
}>(ALGORITHM.detectAllCycles)(graphData);
67+
68+
/**
69+
* 检测图中的所有(有向) Cycle
70+
* @param graphData 图数据
71+
*/
72+
const detectAllDirectedCycleAsync = (graphData: GraphData) =>
73+
createWorker<{
74+
[key: string]: string;
75+
}>(ALGORITHM.detectAllDirectedCycle)(graphData);
76+
77+
/**
78+
* 检测图中的所有(无向) Cycle
79+
* @param graphData 图数据
80+
*/
81+
const detectAllUndirectedCycleAsync = (graphData: GraphData) =>
82+
createWorker<{
83+
[key: string]: string;
84+
}>(ALGORITHM.detectAllUndirectedCycle)(graphData);
85+
6086
/**
6187
* Dijkstra's algorithm, See {@link https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm}
6288
* @param graphData 图数据
@@ -211,6 +237,9 @@ export {
211237
getInDegreeAsync,
212238
getOutDegreeAsync,
213239
detectCycleAsync,
240+
detectAllCyclesAsync,
241+
detectAllDirectedCycleAsync,
242+
detectAllUndirectedCycleAsync,
214243
dijkstraAsync,
215244
findAllPathAsync,
216245
findShortestPathAsync,

0 commit comments

Comments
 (0)