blob: 4bd693a9338b1f695beb7b8a0b1fa4d81b64ad2f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
package scala.collection.parallel.benchmarks.generic
trait Operators[T] {
def reducer: (T, T) => T
def mediumreducer: (T, T) => T
def filterer: T => Boolean
def mapper: T => T
def mapper2: T => T = error("unsupported")
def heavymapper: T => T
def taker: T => Boolean
def eachFun: T => Unit
def sequence(sz: Int): Seq[T] = error("unsupported")
}
trait IntOperators extends Operators[Int] {
val reducer: (Int, Int) => Int = _ + _
val mediumreducer: (Int, Int) => Int = (a: Int, b: Int) => {
val result = if (b == 0) a else {
mediumreducer.apply(b, a - b * (a / b))
}
result + 1000
}
val filterer: Int => Boolean = _ % 2 == 0
val mapper: Int => Int = _ * 2
val heavymapper: Int => Int = (n: Int) => {
var i = -10
var sum = 0
while (i < 0) {
sum += -i
i += 1
}
n + sum
}
val taker: Int => Boolean = _ < 10000
val eachFun: Int => Unit = { n =>
n % 2 == 0
}
}
|