Skip to content

Commit

Permalink
perf: 减少无用判断
Browse files Browse the repository at this point in the history
这里是一个连通图,所以 right 的长度一定先到 0
  • Loading branch information
muzea committed Apr 9, 2019
1 parent e632c3d commit d50cab0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ function checkUnlink(constraint, edge) {
* 3. 从 right 中挑选一个点 r 从 left 中挑选一个点 l
* 4. 检查 l r 是否符合 unlink 约束
* 不符合则重新执行 3
* 符合则把边 (l, r)加到返回值里面 同时把点r从right移动到left
* 符合则把边 (l, r) 加到返回值里面 同时把点 r 从 right 移动到 left
* 若此时 right 的长度为 0 则 执行 5 否则 执行 3
* 5. 从 left 中挑选两个点组成一个边 检查 (node1, node2) 是否符合 unlink 约束
* 符合则增加一个边 (l, r) 重新执行 5 直到 选出来的边满足 edgeNumber
* 符合则增加一个边 (node1, node2) 重新执行 5 直到 选出来的边满足 edgeNumber
* 不符合则重新执行 5
*
* validity unlink 目前只在加边的时候校验
Expand Down Expand Up @@ -103,7 +103,7 @@ function getRandomSubGraph(nodeList, edgeNumber, staticConstraint) {
}
shuffleArray(right);
let whileCount = 0;
while (neededEdgeCount > ret.length && right.length && whileCount < 233) {
while (right.length && whileCount < 233) {
whileCount += 1;
/**
* step 3-4.
Expand Down

0 comments on commit d50cab0

Please sign in to comment.