gearpump-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From huafengw <...@git.apache.org>
Subject [GitHub] incubator-gearpump pull request #223: [GEARPUMP-349] Optimize Graph topologi...
Date Thu, 14 Sep 2017 12:45:07 GMT
Github user huafengw commented on a diff in the pull request:

    https://github.com/apache/incubator-gearpump/pull/223#discussion_r138882103
  
    --- Diff: core/src/main/scala/org/apache/gearpump/util/Graph.scala ---
    @@ -355,19 +393,7 @@ class Graph[N, E](vertexList: List[N], edgeList: List[(N, E, N)])
extends Serial
        * check whether there is a loop
        */
       def hasCycle(): Boolean = {
    -    @tailrec
    -    def detectCycle(graph: Graph[N, E]): Boolean = {
    -      if (graph.edges.isEmpty) {
    -        false
    -      } else if (graph.vertices.nonEmpty && !graph.vertices.exists(graph.inDegreeOf(_)
== 0)) {
    -        true
    -      } else {
    -        graph.removeZeroInDegree
    -        detectCycle(graph)
    -      }
    -    }
    -
    -    detectCycle(copy)
    +    tryTopologicalOrderIterator.isFailure
    --- End diff --
    
    The graph is mutable so we have to check whether the Graph is changed if caching the result.


---

Mime
View raw message