From c6dc9678a89a7692307f9c6e2c360cf71c48daed Mon Sep 17 00:00:00 2001 From: Dongjoon Hyun Date: Mon, 2 May 2016 00:57:02 -0700 Subject: [PATCH 1/2] [SPARK-15057][GRAPHX] Use enum Quadrant in GraphGenerators --- .../spark/graphx/util/GraphGenerators.scala | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) 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 80c6b6838faf5..534f79d40f01f 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 @@ -29,6 +29,12 @@ import org.apache.spark.rdd.RDD /** A collection of graph generating functions. */ object GraphGenerators extends Logging { + object Quadrant extends Enumeration { + type Quadrant = Value + val QUADRANT_A, QUADRANT_B, QUADRANT_C, QUADRANT_D = Value + } + import Quadrant._ + val RMATa = 0.45 val RMATb = 0.15 val RMATd = 0.25 @@ -201,16 +207,15 @@ object GraphGenerators extends Logging { } else { val newT = math.round(t.toFloat/2.0).toInt pickQuadrant(RMATa, RMATb, RMATc, RMATd) match { - case 0 => chooseCell(x, y, newT) - case 1 => chooseCell(x + newT, y, newT) - case 2 => chooseCell(x, y + newT, newT) - case 3 => chooseCell(x + newT, y + newT, newT) + case QUADRANT_A => chooseCell(x, y, newT) + case QUADRANT_B => chooseCell(x + newT, y, newT) + case QUADRANT_C => chooseCell(x, y + newT, newT) + case QUADRANT_D => chooseCell(x + newT, y + newT, newT) } } } - // TODO(crankshaw) turn result into an enum (or case class for pattern matching} - private def pickQuadrant(a: Double, b: Double, c: Double, d: Double): Int = { + private def pickQuadrant(a: Double, b: Double, c: Double, d: Double): Quadrant = { if (a + b + c + d != 1.0) { throw new IllegalArgumentException("R-MAT probability parameters sum to " + (a + b + c + d) + ", should sum to 1.0") @@ -218,10 +223,10 @@ object GraphGenerators extends Logging { val rand = new Random() val result = rand.nextDouble() result match { - case x if x < a => 0 // 0 corresponds to quadrant a - case x if (x >= a && x < a + b) => 1 // 1 corresponds to b - case x if (x >= a + b && x < a + b + c) => 2 // 2 corresponds to c - case _ => 3 // 3 corresponds to d + case x if x < a => QUADRANT_A + case x if (x >= a && x < a + b) => QUADRANT_B + case x if (x >= a + b && x < a + b + c) => QUADRANT_C + case _ => QUADRANT_D } } From dd9b008d44e91e7cdeca114a88c23e009e5f0366 Mon Sep 17 00:00:00 2001 From: Dongjoon Hyun Date: Mon, 2 May 2016 12:15:24 -0700 Subject: [PATCH 2/2] Remove only TODO comment. --- .../spark/graphx/util/GraphGenerators.scala | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) 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 534f79d40f01f..4da1ecb2a9af3 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 @@ -29,12 +29,6 @@ import org.apache.spark.rdd.RDD /** A collection of graph generating functions. */ object GraphGenerators extends Logging { - object Quadrant extends Enumeration { - type Quadrant = Value - val QUADRANT_A, QUADRANT_B, QUADRANT_C, QUADRANT_D = Value - } - import Quadrant._ - val RMATa = 0.45 val RMATb = 0.15 val RMATd = 0.25 @@ -207,15 +201,15 @@ object GraphGenerators extends Logging { } else { val newT = math.round(t.toFloat/2.0).toInt pickQuadrant(RMATa, RMATb, RMATc, RMATd) match { - case QUADRANT_A => chooseCell(x, y, newT) - case QUADRANT_B => chooseCell(x + newT, y, newT) - case QUADRANT_C => chooseCell(x, y + newT, newT) - case QUADRANT_D => chooseCell(x + newT, y + newT, newT) + case 0 => chooseCell(x, y, newT) + case 1 => chooseCell(x + newT, y, newT) + case 2 => chooseCell(x, y + newT, newT) + case 3 => chooseCell(x + newT, y + newT, newT) } } } - private def pickQuadrant(a: Double, b: Double, c: Double, d: Double): Quadrant = { + private def pickQuadrant(a: Double, b: Double, c: Double, d: Double): Int = { if (a + b + c + d != 1.0) { throw new IllegalArgumentException("R-MAT probability parameters sum to " + (a + b + c + d) + ", should sum to 1.0") @@ -223,10 +217,10 @@ object GraphGenerators extends Logging { val rand = new Random() val result = rand.nextDouble() result match { - case x if x < a => QUADRANT_A - case x if (x >= a && x < a + b) => QUADRANT_B - case x if (x >= a + b && x < a + b + c) => QUADRANT_C - case _ => QUADRANT_D + case x if x < a => 0 // 0 corresponds to quadrant a + case x if (x >= a && x < a + b) => 1 // 1 corresponds to b + case x if (x >= a + b && x < a + b + c) => 2 // 2 corresponds to c + case _ => 3 // 3 corresponds to d } }