Skip to content
Snippets Groups Projects
Commit c6023bee authored by Ankur Dave's avatar Ankur Dave
Browse files

Fix infinite loop in GraphGenerators.generateRandomEdges

The loop occurred when numEdges < numVertices. This commit fixes it by
allowing generateRandomEdges to generate a multigraph.
parent 84d6af80
No related branches found
No related tags found
No related merge requests found
......@@ -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) }
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment