Skip to content

Commit

Permalink
Merge pull request antvis#28 from antvis/0.1.9
Browse files Browse the repository at this point in the history
chore: separate sync and async functions into different entries;
  • Loading branch information
Yanyan-Wang committed Jun 3, 2021
2 parents eba5caa + f05dbdd commit adf905b
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 68 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# ChangeLog

#### 0.1.9

- chore: separate sync and async functions into different entries;

#### 0.1.8

- fix: CPU usage increases due to 0.1.3-beta ~ 0.1.3 with publicPath configuration;
Expand Down
2 changes: 1 addition & 1 deletion packages/graph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/algorithm",
"version": "0.1.8",
"version": "0.1.9",
"description": "graph algorithm",
"keywords": [
"graph",
Expand Down
2 changes: 1 addition & 1 deletion packages/graph/src/adjacent-matrix.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GraphData, Matrix } from "./types";

const adjMatrix = (graphData: GraphData, directed?: boolean) => {
const adjMatrix = (graphData: GraphData, directed?: boolean): Matrix[] => {
const { nodes, edges } = graphData;
const matrix: Matrix[] = [];
// map node with index in data.nodes
Expand Down
69 changes: 69 additions & 0 deletions packages/graph/src/asyncIndex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {
getAdjMatrixAsync,
connectedComponentAsync,
getDegreeAsync,
getInDegreeAsync,
getOutDegreeAsync,
detectCycleAsync,
detectAllCyclesAsync,
detectAllDirectedCycleAsync,
detectAllUndirectedCycleAsync,
dijkstraAsync,
findAllPathAsync,
findShortestPathAsync,
floydWarshallAsync,
labelPropagationAsync,
louvainAsync,
minimumSpanningTreeAsync,
pageRankAsync,
getNeighborsAsync,
GADDIAsync,
} from './workers/index';

const detectDirectedCycleAsync = detectCycleAsync;

export {
getAdjMatrixAsync,
connectedComponentAsync,
getDegreeAsync,
getInDegreeAsync,
getOutDegreeAsync,
detectCycleAsync,
detectDirectedCycleAsync,
detectAllCyclesAsync,
detectAllDirectedCycleAsync,
detectAllUndirectedCycleAsync,
dijkstraAsync,
findAllPathAsync,
findShortestPathAsync,
floydWarshallAsync,
labelPropagationAsync,
louvainAsync,
minimumSpanningTreeAsync,
pageRankAsync,
getNeighborsAsync,
GADDIAsync,
};

export default {
getAdjMatrixAsync,
connectedComponentAsync,
getDegreeAsync,
getInDegreeAsync,
getOutDegreeAsync,
detectCycleAsync,
detectDirectedCycleAsync,
detectAllCyclesAsync,
detectAllDirectedCycleAsync,
detectAllUndirectedCycleAsync,
dijkstraAsync,
findAllPathAsync,
findShortestPathAsync,
floydWarshallAsync,
labelPropagationAsync,
louvainAsync,
minimumSpanningTreeAsync,
pageRankAsync,
getNeighborsAsync,
GADDIAsync,
};
4 changes: 2 additions & 2 deletions packages/graph/src/degree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default degree;
* @param graphData 图数据
* @param nodeId 节点ID
*/
export const getInDegree = (graphData: GraphData, nodeId: string) => {
export const getInDegree = (graphData: GraphData, nodeId: string): number => {
const nodeDegree = degree(graphData)
if (nodeDegree[nodeId]) {
return degree(graphData)[nodeId].inDegree
Expand All @@ -42,7 +42,7 @@ export const getInDegree = (graphData: GraphData, nodeId: string) => {
* @param graphData 图数据
* @param nodeId 节点ID
*/
export const getOutDegree = (graphData: GraphData, nodeId: string) => {
export const getOutDegree = (graphData: GraphData, nodeId: string): number => {
const nodeDegree = degree(graphData)
if (nodeDegree[nodeId]) {
return degree(graphData)[nodeId].outDegree
Expand Down
4 changes: 3 additions & 1 deletion packages/graph/src/detect-cycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import getConnectedComponents, { detectStrongConnectComponents } from './connect
import { GraphData, IAlgorithmCallbacks, NodeConfig } from './types';
import { getNeighbors } from './util';

const detectDirectedCycle = (graphData: GraphData) => {
const detectDirectedCycle = (graphData: GraphData): {
[key: string]: string;
} => {
let cycle: {
[key: string]: string;
} = null;
Expand Down
65 changes: 2 additions & 63 deletions packages/graph/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,9 @@ import pageRank from './pageRank';
import GADDI from './gaddi';
import Stack from './structs/stack';
import { getNeighbors } from './util';
import { IAlgorithm } from './types';

const detectDirectedCycle = detectCycle;
const detectDirectedCycleAsync = detectCycleAsync;

import {
getAdjMatrixAsync,
connectedComponentAsync,
getDegreeAsync,
getInDegreeAsync,
getOutDegreeAsync,
detectCycleAsync,
detectAllCyclesAsync,
detectAllDirectedCycleAsync,
detectAllUndirectedCycleAsync,
dijkstraAsync,
findAllPathAsync,
findShortestPathAsync,
floydWarshallAsync,
labelPropagationAsync,
louvainAsync,
minimumSpanningTreeAsync,
pageRankAsync,
getNeighborsAsync,
GADDIAsync,
} from './workers/index';

export {
getAdjMatrix,
Expand All @@ -65,26 +43,7 @@ export {
getNeighbors,
Stack,
GADDI,
getAdjMatrixAsync,
connectedComponentAsync,
getDegreeAsync,
getInDegreeAsync,
getOutDegreeAsync,
detectCycleAsync,
detectDirectedCycleAsync,
detectAllCyclesAsync,
detectAllDirectedCycleAsync,
detectAllUndirectedCycleAsync,
dijkstraAsync,
findAllPathAsync,
findShortestPathAsync,
floydWarshallAsync,
labelPropagationAsync,
louvainAsync,
minimumSpanningTreeAsync,
pageRankAsync,
getNeighborsAsync,
GADDIAsync,
IAlgorithm
};

export default {
Expand All @@ -111,24 +70,4 @@ export default {
getNeighbors,
Stack,
GADDI,
getAdjMatrixAsync,
connectedComponentAsync,
getDegreeAsync,
getInDegreeAsync,
getOutDegreeAsync,
detectCycleAsync,
detectDirectedCycleAsync,
detectAllCyclesAsync,
detectAllDirectedCycleAsync,
detectAllUndirectedCycleAsync,
dijkstraAsync,
findAllPathAsync,
findShortestPathAsync,
floydWarshallAsync,
labelPropagationAsync,
louvainAsync,
minimumSpanningTreeAsync,
pageRankAsync,
getNeighborsAsync,
GADDIAsync,
};
51 changes: 51 additions & 0 deletions packages/graph/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,54 @@ export interface DegreeType {
outDegree: number;
}
}


export interface IAlgorithm {
getAdjMatrix: (graphData: GraphData, directed?: boolean) => Matrix[],
breadthFirstSearch: (
graphData: GraphData,
startNodeId: string,
originalCallbacks?: IAlgorithmCallbacks,
) => void,
connectedComponent: (graphData: GraphData, directed?: boolean) => NodeConfig[][],
getDegree: (graphData: GraphData) => DegreeType,
getInDegree: (graphData: GraphData, nodeId: string) => number,
getOutDegree: (graphData: GraphData, nodeId: string) => number,
detectCycle: (graphData: GraphData) => { [key: string]: string },
detectDirectedCycle: (graphData: GraphData) => { [key: string]: string },
detectAllCycles: (graphData: GraphData, directed?: boolean, nodeIds?: string[], include?: boolean) => any,
detectAllDirectedCycle: (graphData: GraphData, nodeIds?: string[], include?: boolean) => any,
detectAllUndirectedCycle: (graphData: GraphData, nodeIds?: string[], include?: boolean) => any,
depthFirstSearch: (graphData: GraphData, startNodeId: string, callbacks?: IAlgorithmCallbacks) => void,
dijkstra: (graphData: GraphData, source: string, directed?: boolean, weightPropertyName?: string) => { length: object, allPath: object, path: object},
findAllPath: (graphData: GraphData, start: string, end: string, directed?: boolean) => any,
findShortestPath: (graphData: GraphData, start: string, end: string, directed?: boolean, weightPropertyName?: string) => any,
floydWarshall: (graphData: GraphData, directed?: boolean) => Matrix[],
labelPropagation: (graphData: GraphData, directed?: boolean, weightPropertyName?: string, maxIteration?: number) => ClusterData,
louvain: (graphData: GraphData, directed: boolean, weightPropertyName: string, threshold: number) => ClusterData,
minimumSpanningTree: (graphData: GraphData, weight?: string, algo?: string) => EdgeConfig[],
pageRank: (graphData: GraphData, epsilon?: number, linkProb?: number) => { [key: string]: number},
getNeighbors: (nodeId: string, edges?: EdgeConfig[], type?: 'target' | 'source' | undefined) => string[],
Stack: any,
GADDI: (graphData: GraphData, pattern: GraphData, directed: boolean, k: number, length: number, nodeLabelProp: string, edgeLabelProp: string) => GraphData[],
getAdjMatrixAsync: (graphData: GraphData, directed?: boolean) => Matrix[],
connectedComponentAsync: (graphData: GraphData, directed?: boolean) => NodeConfig[][],
getDegreeAsync: (graphData: GraphData) => DegreeType,
getInDegreeAsync: (graphData: GraphData, nodeId: string) => number,
getOutDegreeAsync: (graphData: GraphData, nodeId: string) => number,
detectCycleAsync: (graphData: GraphData) => { [key: string]: string },
detectDirectedCycleAsync: (graphData: GraphData) => { [key: string]: string },
detectAllCyclesAsync: (graphData: GraphData, directed?: boolean, nodeIds?: string[], include?: boolean) => any,
detectAllDirectedCycleAsync: (graphData: GraphData, nodeIds?: string[], include?: boolean) => any,
detectAllUndirectedCycleAsync: (graphData: GraphData, nodeIds?: string[], include?: boolean) => any,
dijkstraAsync: (graphData: GraphData, source: string, directed?: boolean, weightPropertyName?: string) => { length: object, allPath: object, path: object},
findAllPathAsync: (graphData: GraphData, start: string, end: string, directed?: boolean) => any,
findShortestPathAsync: (graphData: GraphData, start: string, end: string, directed?: boolean, weightPropertyName?: string) => any,
floydWarshallAsync: (graphData: GraphData, directed?: boolean) => Matrix[],
labelPropagationAsync: (graphData: GraphData, directed?: boolean, weightPropertyName?: string, maxIteration?: number) => ClusterData,
louvainAsync: (graphData: GraphData, directed: boolean, weightPropertyName: string, threshold: number) => ClusterData,
minimumSpanningTreeAsync: (graphData: GraphData, weight?: string, algo?: string) => EdgeConfig[],
pageRankAsync: (graphData: GraphData, epsilon?: number, linkProb?: number) => { [key: string]: number},
getNeighborsAsync: (nodeId: string, edges?: EdgeConfig[], type?: 'target' | 'source' | undefined) => string[],
GADDIAsync: (graphData: GraphData, pattern: GraphData, directed: boolean, k: number, length: number, nodeLabelProp: string, edgeLabelProp: string) => GraphData[],
}
1 change: 1 addition & 0 deletions packages/graph/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const resolve = require('path').resolve;
module.exports = {
entry: {
index: './src/index.ts',
async: './src/asyncIndex.ts'
},
output: {
filename: '[name].min.js',
Expand Down

0 comments on commit adf905b

Please sign in to comment.