blob: 95f6c7afd744691f6dcc5cc93fef0c34522fdc65 (
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
|
package benchmark
/** Builder of a [[KeySeq]]
*
* @tparam K the type of the keys
*/
trait KeySeqBuilder[K] {
/** Return a [[KeySeq]] having at least the given size. */
def build(size: Int): KeySeq[K]
}
object KeySeqBuilder {
/** Builder of a sequence of `Int` keys.
* Simply maps the sequence index to itself.
*/
implicit object IntKeySeqBuilder extends KeySeqBuilder[Int] {
def build(_size: Int) = new KeySeq[Int] {
def apply(idx: Int) = idx
def size = _size
}
}
/** Builder of a sequence of `AnyRef` keys. */
implicit object AnyRefKeySeqBuilder extends KeySeqBuilder[AnyRef] {
def build(_size: Int) = new KeySeq[AnyRef] {
private[this] val arr = new Array[AnyRef](size)
for (i <- 0 until size) arr(i) = new AnyRef()
def apply(idx: Int) = arr(idx)
def size = _size
}
}
}
|