Skip to content

Commit adf905b

Browse files
authored
Merge pull request #28 from antvis/0.1.9
chore: separate sync and async functions into different entries;
2 parents eba5caa + f05dbdd commit adf905b

9 files changed

Lines changed: 135 additions & 68 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# ChangeLog
2+
3+
#### 0.1.9
4+
5+
- chore: separate sync and async functions into different entries;
6+
27
#### 0.1.8
38

49
- fix: CPU usage increases due to 0.1.3-beta ~ 0.1.3 with publicPath configuration;

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",
3+
"version": "0.1.9",
44
"description": "graph algorithm",
55
"keywords": [
66
"graph",

packages/graph/src/adjacent-matrix.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GraphData, Matrix } from "./types";
22

3-
const adjMatrix = (graphData: GraphData, directed?: boolean) => {
3+
const adjMatrix = (graphData: GraphData, directed?: boolean): Matrix[] => {
44
const { nodes, edges } = graphData;
55
const matrix: Matrix[] = [];
66
// map node with index in data.nodes

packages/graph/src/asyncIndex.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import {
2+
getAdjMatrixAsync,
3+
connectedComponentAsync,
4+
getDegreeAsync,
5+
getInDegreeAsync,
6+
getOutDegreeAsync,
7+
detectCycleAsync,
8+
detectAllCyclesAsync,
9+
detectAllDirectedCycleAsync,
10+
detectAllUndirectedCycleAsync,
11+
dijkstraAsync,
12+
findAllPathAsync,
13+
findShortestPathAsync,
14+
floydWarshallAsync,
15+
labelPropagationAsync,
16+
louvainAsync,
17+
minimumSpanningTreeAsync,
18+
pageRankAsync,
19+
getNeighborsAsync,
20+
GADDIAsync,
21+
} from './workers/index';
22+
23+
const detectDirectedCycleAsync = detectCycleAsync;
24+
25+
export {
26+
getAdjMatrixAsync,
27+
connectedComponentAsync,
28+
getDegreeAsync,
29+
getInDegreeAsync,
30+
getOutDegreeAsync,
31+
detectCycleAsync,
32+
detectDirectedCycleAsync,
33+
detectAllCyclesAsync,
34+
detectAllDirectedCycleAsync,
35+
detectAllUndirectedCycleAsync,
36+
dijkstraAsync,
37+
findAllPathAsync,
38+
findShortestPathAsync,
39+
floydWarshallAsync,
40+
labelPropagationAsync,
41+
louvainAsync,
42+
minimumSpanningTreeAsync,
43+
pageRankAsync,
44+
getNeighborsAsync,
45+
GADDIAsync,
46+
};
47+
48+
export default {
49+
getAdjMatrixAsync,
50+
connectedComponentAsync,
51+
getDegreeAsync,
52+
getInDegreeAsync,
53+
getOutDegreeAsync,
54+
detectCycleAsync,
55+
detectDirectedCycleAsync,
56+
detectAllCyclesAsync,
57+
detectAllDirectedCycleAsync,
58+
detectAllUndirectedCycleAsync,
59+
dijkstraAsync,
60+
findAllPathAsync,
61+
findShortestPathAsync,
62+
floydWarshallAsync,
63+
labelPropagationAsync,
64+
louvainAsync,
65+
minimumSpanningTreeAsync,
66+
pageRankAsync,
67+
getNeighborsAsync,
68+
GADDIAsync,
69+
};

packages/graph/src/degree.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default degree;
2929
* @param graphData 图数据
3030
* @param nodeId 节点ID
3131
*/
32-
export const getInDegree = (graphData: GraphData, nodeId: string) => {
32+
export const getInDegree = (graphData: GraphData, nodeId: string): number => {
3333
const nodeDegree = degree(graphData)
3434
if (nodeDegree[nodeId]) {
3535
return degree(graphData)[nodeId].inDegree
@@ -42,7 +42,7 @@ export const getInDegree = (graphData: GraphData, nodeId: string) => {
4242
* @param graphData 图数据
4343
* @param nodeId 节点ID
4444
*/
45-
export const getOutDegree = (graphData: GraphData, nodeId: string) => {
45+
export const getOutDegree = (graphData: GraphData, nodeId: string): number => {
4646
const nodeDegree = degree(graphData)
4747
if (nodeDegree[nodeId]) {
4848
return degree(graphData)[nodeId].outDegree

packages/graph/src/detect-cycle.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import getConnectedComponents, { detectStrongConnectComponents } from './connect
33
import { GraphData, IAlgorithmCallbacks, NodeConfig } from './types';
44
import { getNeighbors } from './util';
55

6-
const detectDirectedCycle = (graphData: GraphData) => {
6+
const detectDirectedCycle = (graphData: GraphData): {
7+
[key: string]: string;
8+
} => {
79
let cycle: {
810
[key: string]: string;
911
} = null;

packages/graph/src/index.ts

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,9 @@ import pageRank from './pageRank';
1515
import GADDI from './gaddi';
1616
import Stack from './structs/stack';
1717
import { getNeighbors } from './util';
18+
import { IAlgorithm } from './types';
1819

1920
const detectDirectedCycle = detectCycle;
20-
const detectDirectedCycleAsync = detectCycleAsync;
21-
22-
import {
23-
getAdjMatrixAsync,
24-
connectedComponentAsync,
25-
getDegreeAsync,
26-
getInDegreeAsync,
27-
getOutDegreeAsync,
28-
detectCycleAsync,
29-
detectAllCyclesAsync,
30-
detectAllDirectedCycleAsync,
31-
detectAllUndirectedCycleAsync,
32-
dijkstraAsync,
33-
findAllPathAsync,
34-
findShortestPathAsync,
35-
floydWarshallAsync,
36-
labelPropagationAsync,
37-
louvainAsync,
38-
minimumSpanningTreeAsync,
39-
pageRankAsync,
40-
getNeighborsAsync,
41-
GADDIAsync,
42-
} from './workers/index';
4321

4422
export {
4523
getAdjMatrix,
@@ -65,26 +43,7 @@ export {
6543
getNeighbors,
6644
Stack,
6745
GADDI,
68-
getAdjMatrixAsync,
69-
connectedComponentAsync,
70-
getDegreeAsync,
71-
getInDegreeAsync,
72-
getOutDegreeAsync,
73-
detectCycleAsync,
74-
detectDirectedCycleAsync,
75-
detectAllCyclesAsync,
76-
detectAllDirectedCycleAsync,
77-
detectAllUndirectedCycleAsync,
78-
dijkstraAsync,
79-
findAllPathAsync,
80-
findShortestPathAsync,
81-
floydWarshallAsync,
82-
labelPropagationAsync,
83-
louvainAsync,
84-
minimumSpanningTreeAsync,
85-
pageRankAsync,
86-
getNeighborsAsync,
87-
GADDIAsync,
46+
IAlgorithm
8847
};
8948

9049
export default {
@@ -111,24 +70,4 @@ export default {
11170
getNeighbors,
11271
Stack,
11372
GADDI,
114-
getAdjMatrixAsync,
115-
connectedComponentAsync,
116-
getDegreeAsync,
117-
getInDegreeAsync,
118-
getOutDegreeAsync,
119-
detectCycleAsync,
120-
detectDirectedCycleAsync,
121-
detectAllCyclesAsync,
122-
detectAllDirectedCycleAsync,
123-
detectAllUndirectedCycleAsync,
124-
dijkstraAsync,
125-
findAllPathAsync,
126-
findShortestPathAsync,
127-
floydWarshallAsync,
128-
labelPropagationAsync,
129-
louvainAsync,
130-
minimumSpanningTreeAsync,
131-
pageRankAsync,
132-
getNeighborsAsync,
133-
GADDIAsync,
13473
};

packages/graph/src/types.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,54 @@ export interface DegreeType {
4848
outDegree: number;
4949
}
5050
}
51+
52+
53+
export interface IAlgorithm {
54+
getAdjMatrix: (graphData: GraphData, directed?: boolean) => Matrix[],
55+
breadthFirstSearch: (
56+
graphData: GraphData,
57+
startNodeId: string,
58+
originalCallbacks?: IAlgorithmCallbacks,
59+
) => void,
60+
connectedComponent: (graphData: GraphData, directed?: boolean) => NodeConfig[][],
61+
getDegree: (graphData: GraphData) => DegreeType,
62+
getInDegree: (graphData: GraphData, nodeId: string) => number,
63+
getOutDegree: (graphData: GraphData, nodeId: string) => number,
64+
detectCycle: (graphData: GraphData) => { [key: string]: string },
65+
detectDirectedCycle: (graphData: GraphData) => { [key: string]: string },
66+
detectAllCycles: (graphData: GraphData, directed?: boolean, nodeIds?: string[], include?: boolean) => any,
67+
detectAllDirectedCycle: (graphData: GraphData, nodeIds?: string[], include?: boolean) => any,
68+
detectAllUndirectedCycle: (graphData: GraphData, nodeIds?: string[], include?: boolean) => any,
69+
depthFirstSearch: (graphData: GraphData, startNodeId: string, callbacks?: IAlgorithmCallbacks) => void,
70+
dijkstra: (graphData: GraphData, source: string, directed?: boolean, weightPropertyName?: string) => { length: object, allPath: object, path: object},
71+
findAllPath: (graphData: GraphData, start: string, end: string, directed?: boolean) => any,
72+
findShortestPath: (graphData: GraphData, start: string, end: string, directed?: boolean, weightPropertyName?: string) => any,
73+
floydWarshall: (graphData: GraphData, directed?: boolean) => Matrix[],
74+
labelPropagation: (graphData: GraphData, directed?: boolean, weightPropertyName?: string, maxIteration?: number) => ClusterData,
75+
louvain: (graphData: GraphData, directed: boolean, weightPropertyName: string, threshold: number) => ClusterData,
76+
minimumSpanningTree: (graphData: GraphData, weight?: string, algo?: string) => EdgeConfig[],
77+
pageRank: (graphData: GraphData, epsilon?: number, linkProb?: number) => { [key: string]: number},
78+
getNeighbors: (nodeId: string, edges?: EdgeConfig[], type?: 'target' | 'source' | undefined) => string[],
79+
Stack: any,
80+
GADDI: (graphData: GraphData, pattern: GraphData, directed: boolean, k: number, length: number, nodeLabelProp: string, edgeLabelProp: string) => GraphData[],
81+
getAdjMatrixAsync: (graphData: GraphData, directed?: boolean) => Matrix[],
82+
connectedComponentAsync: (graphData: GraphData, directed?: boolean) => NodeConfig[][],
83+
getDegreeAsync: (graphData: GraphData) => DegreeType,
84+
getInDegreeAsync: (graphData: GraphData, nodeId: string) => number,
85+
getOutDegreeAsync: (graphData: GraphData, nodeId: string) => number,
86+
detectCycleAsync: (graphData: GraphData) => { [key: string]: string },
87+
detectDirectedCycleAsync: (graphData: GraphData) => { [key: string]: string },
88+
detectAllCyclesAsync: (graphData: GraphData, directed?: boolean, nodeIds?: string[], include?: boolean) => any,
89+
detectAllDirectedCycleAsync: (graphData: GraphData, nodeIds?: string[], include?: boolean) => any,
90+
detectAllUndirectedCycleAsync: (graphData: GraphData, nodeIds?: string[], include?: boolean) => any,
91+
dijkstraAsync: (graphData: GraphData, source: string, directed?: boolean, weightPropertyName?: string) => { length: object, allPath: object, path: object},
92+
findAllPathAsync: (graphData: GraphData, start: string, end: string, directed?: boolean) => any,
93+
findShortestPathAsync: (graphData: GraphData, start: string, end: string, directed?: boolean, weightPropertyName?: string) => any,
94+
floydWarshallAsync: (graphData: GraphData, directed?: boolean) => Matrix[],
95+
labelPropagationAsync: (graphData: GraphData, directed?: boolean, weightPropertyName?: string, maxIteration?: number) => ClusterData,
96+
louvainAsync: (graphData: GraphData, directed: boolean, weightPropertyName: string, threshold: number) => ClusterData,
97+
minimumSpanningTreeAsync: (graphData: GraphData, weight?: string, algo?: string) => EdgeConfig[],
98+
pageRankAsync: (graphData: GraphData, epsilon?: number, linkProb?: number) => { [key: string]: number},
99+
getNeighborsAsync: (nodeId: string, edges?: EdgeConfig[], type?: 'target' | 'source' | undefined) => string[],
100+
GADDIAsync: (graphData: GraphData, pattern: GraphData, directed: boolean, k: number, length: number, nodeLabelProp: string, edgeLabelProp: string) => GraphData[],
101+
}

packages/graph/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const resolve = require('path').resolve;
44
module.exports = {
55
entry: {
66
index: './src/index.ts',
7+
async: './src/asyncIndex.ts'
78
},
89
output: {
910
filename: '[name].min.js',

0 commit comments

Comments
 (0)