algorithm icon indicating copy to clipboard operation
algorithm copied to clipboard

规范化API与异步算法嵌入Worker URL

Open zuiidea opened this issue 3 years ago • 0 comments

  1. 规范化API,目前API有算法21个,异步算法19个,数据结构1个。算法 API 调用方式统一传入一个对象参数,同步算法至少有 graphData属性,异步算法可传workerScriptURL属性。以 getOutDegree 为例:
const result = getOutDegree({
  graphData,
  nodeId,
})

getOutDegreeAsync({
  graphData,
  nodeId,
  workerScriptURL,
}).then(result => {
   console.log(result)
})

目前支持API如下表:

序号 算法名 异步算法
1 getAdjMatrix getAdjMatrixAsync
2 breadthFirstSearch --
3 connectedComponent connectedComponentAsync
4 getDegree getDegreeAsync
5 getInDegree getInDegreeAsync
6 getOutDegree getOutDegreeAsync
7 detectCycle/detectDirectedCycle detectCycleAsync/detectDirectedCycleAsync
8 detectAllCycles detectAllCyclesAsync
9 detectAllDirectedCycle detectAllDirectedCycleAsync
10 detectAllUndirectedCycle detectAllUndirectedCycleAsync
11 depthFirstSearch --
12 dijkstra dijkstraAsync
13 findAllPath findAllPathAsync
14 findShortestPath findShortestPathAsync
15 floydWarshall floydWarshallAsync
16 labelPropagation labelPropagationAsync
17 louvain louvainAsync
18 minimumSpanningTree minimumSpanningTreeAsync
19 pageRank pageRankAsync
20 getNeighbors getNeighborsAsync
21 GADDI GADDIAsync
22 数据结构:Stack  
  1. 支持 TreeShaking,使用 CRA 实际测试了一下,单页面文件使用 louvainlouvainAsync 时,大小为5.91k,仅使用lovainAsync时,大小为1.05k。
  2. 异步算法采用嵌入Worker文件URL的方式,以减小输出文件大小,参考 G6 Layout。纯同步算法文件输出地址为:https://unpkg.com/@antv/algorithm@latest/dist/algorithm.min.js
  3. 优化 Webworker PostMessage 可能处理错误的问题,采用创建 Webworker 时注入唯一messageID保证消息不会互串,https://github.com/antvis/algorithm/issues/25
  4. 补全算法 TS 类型和 JSDoc。
  5. 分离同步算法API和异步算法API。
/** 包含同步和异步算法API */
import { louvainAsync, louvain } from '@antv/algorithm';
/** 仅包含异步算法API */
import { pageRankAsync } from '@antv/algorithm/es/asyncIndex';
/** 仅包含同步算法API */
import { pageRank } from '@antv/algorithm/es/syncIndex';

zuiidea avatar Jun 08 '21 09:06 zuiidea