Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

zuiidea
Copy link
Contributor

@zuiidea zuiidea commented Jun 8, 2021

  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保证消息不会互串,[bug]postMessage 导致循环 #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';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant