You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by pw...@apache.org on 2014/01/14 08:00:02 UTC

[38/50] git commit: Fix infinite loop in GraphGenerators.generateRandomEdges

Fix infinite loop in GraphGenerators.generateRandomEdges

The loop occurred when numEdges < numVertices. This commit fixes it by
allowing generateRandomEdges to generate a multigraph.


Project: http://git-wip-us.apache.org/repos/asf/incubator-spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-spark/commit/c6023bee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-spark/tree/c6023bee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-spark/diff/c6023bee

Branch: refs/heads/master
Commit: c6023bee60cee06b3dd31bb8253da6e07862c13d
Parents: 84d6af8
Author: Ankur Dave <an...@gmail.com>
Authored: Mon Jan 13 21:00:25 2014 -0800
Committer: Ankur Dave <an...@gmail.com>
Committed: Mon Jan 13 21:02:37 2014 -0800

----------------------------------------------------------------------
 .../org/apache/spark/graphx/util/GraphGenerators.scala      | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-spark/blob/c6023bee/graphx/src/main/scala/org/apache/spark/graphx/util/GraphGenerators.scala
----------------------------------------------------------------------
diff --git a/graphx/src/main/scala/org/apache/spark/graphx/util/GraphGenerators.scala b/graphx/src/main/scala/org/apache/spark/graphx/util/GraphGenerators.scala
index dbea233..57422ce 100644
--- a/graphx/src/main/scala/org/apache/spark/graphx/util/GraphGenerators.scala
+++ b/graphx/src/main/scala/org/apache/spark/graphx/util/GraphGenerators.scala
@@ -44,14 +44,7 @@ object GraphGenerators {
 
   def generateRandomEdges(src: Int, numEdges: Int, maxVertexID: Int): Array[Edge[Int]] = {
     val rand = new Random()
-    var dsts: Set[Int] = Set()
-    while (dsts.size < numEdges) {
-      val nextDst = rand.nextInt(maxVertexID)
-      if (nextDst != src) {
-        dsts += nextDst
-      }
-    }
-    dsts.map(dst => Edge[Int](src, dst, 1)).toArray
+    Array.fill(maxVertexID) { Edge[Int](src, rand.nextInt(maxVertexID), 1) }
   }
 
   /**