Skip to content

Commit bb2ed41

Browse files
committed
modify some pointless and verbose code
1 parent 986fa5c commit bb2ed41

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

core/src/main/scala/org/apache/spark/util/random/SamplingUtils.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ private[spark] object SamplingUtils {
5656
val rand = new XORShiftRandom(seed)
5757
while (input.hasNext) {
5858
val item = input.next()
59-
val replacementIndex = l < Int.MaxValue match {
60-
case true => rand.nextInt(l.toInt)
61-
case false => rand.nextInt()
59+
val replacementIndex = if (l < Int.MaxValue) {
60+
rand.nextInt(l.toInt)
61+
} else {
62+
rand.nextLong()
6263
}
6364
if (replacementIndex < k) {
64-
reservoir(replacementIndex) = item
65+
reservoir(replacementIndex.toInt) = item
6566
}
6667
l += 1
6768
}

0 commit comments

Comments
 (0)