@@ -18,104 +18,76 @@ trait MakesKeyValueStepper[K, V, +Extra] extends Any {
18
18
def valueStepper [S <: Stepper [_]](implicit ss : StepperShape [V , S ]): S with Extra
19
19
}
20
20
21
- sealed trait StepperShape [T , S <: Stepper [_]] { def ref : Boolean }
22
- object StepperShape extends StepperShapeLowPrio {
23
- private [this ] def valueShape [T , S <: Stepper [_]]: StepperShape [T , S ] = new StepperShape [T , S ] { def ref = false }
21
+ /** Encodes the translation from an element type `T` to the corresponding Stepper type `S` */
22
+ sealed trait StepperShape [T , S <: Stepper [_]] {
23
+ /** Return the Int constant (as defined in the `StepperShape` companion object) for this `StepperShape`. */
24
+ def shape : Int
24
25
25
- // primitive
26
- implicit val IntValue = valueShape[Int , IntStepper ]
27
- implicit val LongValue = valueShape[Long , LongStepper ]
28
- implicit val DoubleValue = valueShape[Double , DoubleStepper ]
26
+ /** Create an unboxing primitive sequential Stepper from a boxed `AnyStepper`.
27
+ * This is an identity operation for reference shapes. */
28
+ def seqUnbox (st : AnyStepper [T ]): S
29
29
30
- // widening
31
- implicit val ByteValue = valueShape[Byte , IntStepper ]
32
- implicit val ShortValue = valueShape[Short , IntStepper ]
33
- implicit val CharValue = valueShape[Char , IntStepper ]
34
- implicit val FloatValue = valueShape[Float , DoubleStepper ]
30
+ /** Create an unboxing primitive parallel (i.e. `with EfficientSubstep`) Stepper from a boxed `AnyStepper`.
31
+ * This is an identity operation for reference shapes. */
32
+ def parUnbox (st : AnyStepper [T ] with EfficientSubstep ): S with EfficientSubstep
35
33
}
36
- trait StepperShapeLowPrio {
34
+ object StepperShape extends StepperShapeLowPriority {
37
35
// reference
38
- implicit def anyStepperShape [T ]: StepperShape [T , AnyStepper [T ]] = new StepperShape [T , AnyStepper [T ]] { def ref = true }
39
- }
40
-
41
- /** Superclass for `MakesStepper` implementations which support parallelization. At least the `AnyStepper` case must be
42
- * implemented, all others default to building an `AnyStepper` and putting an unboxing conversion on top. */
43
- trait MakesParStepper [T ] extends Any with MakesStepper [T , EfficientSubstep ] {
44
- def stepper [S <: Stepper [_]](implicit ss : StepperShape [T , S ]) = (ss match {
45
- case StepperShape .IntValue => new Stepper .UnboxingIntStepper (stepper(StepperShape .anyStepperShape[T ]).asInstanceOf [AnyStepper [Int ]]) with EfficientSubstep
46
- case StepperShape .LongValue => new Stepper .UnboxingLongStepper (stepper(StepperShape .anyStepperShape[T ]).asInstanceOf [AnyStepper [Long ]]) with EfficientSubstep
47
- case StepperShape .DoubleValue => new Stepper .UnboxingDoubleStepper (stepper(StepperShape .anyStepperShape[T ]).asInstanceOf [AnyStepper [Double ]]) with EfficientSubstep
48
- case StepperShape .ByteValue => new Stepper .UnboxingByteStepper (stepper(StepperShape .anyStepperShape[T ]).asInstanceOf [AnyStepper [Byte ]]) with EfficientSubstep
49
- case StepperShape .ShortValue => new Stepper .UnboxingShortStepper (stepper(StepperShape .anyStepperShape[T ]).asInstanceOf [AnyStepper [Short ]]) with EfficientSubstep
50
- case StepperShape .CharValue => new Stepper .UnboxingCharStepper (stepper(StepperShape .anyStepperShape[T ]).asInstanceOf [AnyStepper [Char ]]) with EfficientSubstep
51
- case StepperShape .FloatValue => new Stepper .UnboxingFloatStepper (stepper(StepperShape .anyStepperShape[T ]).asInstanceOf [AnyStepper [Float ]]) with EfficientSubstep
52
- case _ => throw new NotImplementedError (" AnyStepper must be handled in `stepper` implementations" )
53
- }).asInstanceOf [S with EfficientSubstep ]
54
- }
36
+ final val Reference = 0
55
37
56
- /** Superclass for `MakesStepper` implementations which do not support parallelization. At least the `AnyStepper` case must be
57
- * implemented, all others default to building an `AnyStepper` and putting an unboxing conversion on top. */
58
- trait MakesSeqStepper [T ] extends Any with MakesStepper [T , Any ] {
59
- def stepper [S <: Stepper [_]](implicit ss : StepperShape [T , S ]) = (ss match {
60
- case StepperShape .IntValue => new Stepper .UnboxingIntStepper (stepper(StepperShape .anyStepperShape[T ]).asInstanceOf [AnyStepper [Int ]])
61
- case StepperShape .LongValue => new Stepper .UnboxingLongStepper (stepper(StepperShape .anyStepperShape[T ]).asInstanceOf [AnyStepper [Long ]])
62
- case StepperShape .DoubleValue => new Stepper .UnboxingDoubleStepper (stepper(StepperShape .anyStepperShape[T ]).asInstanceOf [AnyStepper [Double ]])
63
- case StepperShape .ByteValue => new Stepper .UnboxingByteStepper (stepper(StepperShape .anyStepperShape[T ]).asInstanceOf [AnyStepper [Byte ]])
64
- case StepperShape .ShortValue => new Stepper .UnboxingShortStepper (stepper(StepperShape .anyStepperShape[T ]).asInstanceOf [AnyStepper [Short ]])
65
- case StepperShape .CharValue => new Stepper .UnboxingCharStepper (stepper(StepperShape .anyStepperShape[T ]).asInstanceOf [AnyStepper [Char ]])
66
- case StepperShape .FloatValue => new Stepper .UnboxingFloatStepper (stepper(StepperShape .anyStepperShape[T ]).asInstanceOf [AnyStepper [Float ]])
67
- case _ => throw new NotImplementedError (" AnyStepper must be handled in `stepper` implementations" )
68
- }).asInstanceOf [S ]
69
- }
38
+ // primitive
39
+ final val IntValue = 1
40
+ final val LongValue = 2
41
+ final val DoubleValue = 3
70
42
71
- /** Superclass for `MakesKeyalueStepper` implementations which support parallelization. At least the `AnyStepper` case must be
72
- * implemented, all others default to building an `AnyStepper` and putting an unboxing conversion on top. */
73
- trait MakesKeyValueParStepper [K , V ] extends Any with MakesKeyValueStepper [K , V , EfficientSubstep ] {
74
- def keyStepper [S <: Stepper [_]](implicit ss : StepperShape [K , S ]) = (ss match {
75
- case StepperShape .IntValue => new Stepper .UnboxingIntStepper (keyStepper(StepperShape .anyStepperShape[K ]).asInstanceOf [AnyStepper [Int ]]) with EfficientSubstep
76
- case StepperShape .LongValue => new Stepper .UnboxingLongStepper (keyStepper(StepperShape .anyStepperShape[K ]).asInstanceOf [AnyStepper [Long ]]) with EfficientSubstep
77
- case StepperShape .DoubleValue => new Stepper .UnboxingDoubleStepper (keyStepper(StepperShape .anyStepperShape[K ]).asInstanceOf [AnyStepper [Double ]]) with EfficientSubstep
78
- case StepperShape .ByteValue => new Stepper .UnboxingByteStepper (keyStepper(StepperShape .anyStepperShape[K ]).asInstanceOf [AnyStepper [Byte ]]) with EfficientSubstep
79
- case StepperShape .ShortValue => new Stepper .UnboxingShortStepper (keyStepper(StepperShape .anyStepperShape[K ]).asInstanceOf [AnyStepper [Short ]]) with EfficientSubstep
80
- case StepperShape .CharValue => new Stepper .UnboxingCharStepper (keyStepper(StepperShape .anyStepperShape[K ]).asInstanceOf [AnyStepper [Char ]]) with EfficientSubstep
81
- case StepperShape .FloatValue => new Stepper .UnboxingFloatStepper (keyStepper(StepperShape .anyStepperShape[K ]).asInstanceOf [AnyStepper [Float ]]) with EfficientSubstep
82
- case _ => throw new NotImplementedError (" AnyStepper case must be handled in `keyStepper` implementations" )
83
- }).asInstanceOf [S with EfficientSubstep ]
43
+ // widening
44
+ final val ByteValue = 4
45
+ final val ShortValue = 5
46
+ final val CharValue = 6
47
+ final val FloatValue = 7
84
48
85
- def valueStepper [S <: Stepper [_]](implicit ss : StepperShape [V , S ]) = (ss match {
86
- case StepperShape .IntValue => new Stepper .UnboxingIntStepper (valueStepper(StepperShape .anyStepperShape[V ]).asInstanceOf [AnyStepper [Int ]]) with EfficientSubstep
87
- case StepperShape .LongValue => new Stepper .UnboxingLongStepper (valueStepper(StepperShape .anyStepperShape[V ]).asInstanceOf [AnyStepper [Long ]]) with EfficientSubstep
88
- case StepperShape .DoubleValue => new Stepper .UnboxingDoubleStepper (valueStepper(StepperShape .anyStepperShape[V ]).asInstanceOf [AnyStepper [Double ]]) with EfficientSubstep
89
- case StepperShape .ByteValue => new Stepper .UnboxingByteStepper (valueStepper(StepperShape .anyStepperShape[V ]).asInstanceOf [AnyStepper [Byte ]]) with EfficientSubstep
90
- case StepperShape .ShortValue => new Stepper .UnboxingShortStepper (valueStepper(StepperShape .anyStepperShape[V ]).asInstanceOf [AnyStepper [Short ]]) with EfficientSubstep
91
- case StepperShape .CharValue => new Stepper .UnboxingCharStepper (valueStepper(StepperShape .anyStepperShape[V ]).asInstanceOf [AnyStepper [Char ]]) with EfficientSubstep
92
- case StepperShape .FloatValue => new Stepper .UnboxingFloatStepper (valueStepper(StepperShape .anyStepperShape[V ]).asInstanceOf [AnyStepper [Float ]]) with EfficientSubstep
93
- case _ => throw new NotImplementedError (" AnyStepper case must be handled in `valueStepper` implementations" )
94
- }).asInstanceOf [S with EfficientSubstep ]
49
+ implicit val intStepperShape : StepperShape [Int , IntStepper ] = new StepperShape [Int , IntStepper ] {
50
+ def shape = IntValue
51
+ def seqUnbox (st : AnyStepper [Int ]): IntStepper = new Stepper .UnboxingIntStepper (st)
52
+ def parUnbox (st : AnyStepper [Int ] with EfficientSubstep ): IntStepper with EfficientSubstep = new Stepper .UnboxingIntStepper (st) with EfficientSubstep
53
+ }
54
+ implicit val longStepperShape : StepperShape [Long , LongStepper ] = new StepperShape [Long , LongStepper ] {
55
+ def shape = LongValue
56
+ def seqUnbox (st : AnyStepper [Long ]): LongStepper = new Stepper .UnboxingLongStepper (st)
57
+ def parUnbox (st : AnyStepper [Long ] with EfficientSubstep ): LongStepper with EfficientSubstep = new Stepper .UnboxingLongStepper (st) with EfficientSubstep
58
+ }
59
+ implicit val doubleStepperShape : StepperShape [Double , DoubleStepper ] = new StepperShape [Double , DoubleStepper ] {
60
+ def shape = DoubleValue
61
+ def seqUnbox (st : AnyStepper [Double ]): DoubleStepper = new Stepper .UnboxingDoubleStepper (st)
62
+ def parUnbox (st : AnyStepper [Double ] with EfficientSubstep ): DoubleStepper with EfficientSubstep = new Stepper .UnboxingDoubleStepper (st) with EfficientSubstep
63
+ }
64
+ implicit val byteStepperShape : StepperShape [Byte , IntStepper ] = new StepperShape [Byte , IntStepper ] {
65
+ def shape = ByteValue
66
+ def seqUnbox (st : AnyStepper [Byte ]): IntStepper = new Stepper .UnboxingByteStepper (st)
67
+ def parUnbox (st : AnyStepper [Byte ] with EfficientSubstep ): IntStepper with EfficientSubstep = new Stepper .UnboxingByteStepper (st) with EfficientSubstep
68
+ }
69
+ implicit val shortStepperShape : StepperShape [Short , IntStepper ] = new StepperShape [Short , IntStepper ] {
70
+ def shape = ShortValue
71
+ def seqUnbox (st : AnyStepper [Short ]): IntStepper = new Stepper .UnboxingShortStepper (st)
72
+ def parUnbox (st : AnyStepper [Short ] with EfficientSubstep ): IntStepper with EfficientSubstep = new Stepper .UnboxingShortStepper (st) with EfficientSubstep
73
+ }
74
+ implicit val charStepperShape : StepperShape [Char , IntStepper ] = new StepperShape [Char , IntStepper ] {
75
+ def shape = CharValue
76
+ def seqUnbox (st : AnyStepper [Char ]): IntStepper = new Stepper .UnboxingCharStepper (st)
77
+ def parUnbox (st : AnyStepper [Char ] with EfficientSubstep ): IntStepper with EfficientSubstep = new Stepper .UnboxingCharStepper (st) with EfficientSubstep
78
+ }
79
+ implicit val floatStepperShape : StepperShape [Float , DoubleStepper ] = new StepperShape [Float , DoubleStepper ] {
80
+ def shape = FloatValue
81
+ def seqUnbox (st : AnyStepper [Float ]): DoubleStepper = new Stepper .UnboxingFloatStepper (st)
82
+ def parUnbox (st : AnyStepper [Float ] with EfficientSubstep ): DoubleStepper with EfficientSubstep = new Stepper .UnboxingFloatStepper (st) with EfficientSubstep
83
+ }
95
84
}
85
+ trait StepperShapeLowPriority {
86
+ implicit def anyStepperShape [T ] = anyStepperShapePrototype.asInstanceOf [StepperShape [T , AnyStepper [T ]]]
96
87
97
- /** Superclass for `MakesKeyalueStepper` implementations which do not support parallelization. At least the `AnyStepper` case must be
98
- * implemented, all others default to building an `AnyStepper` and putting an unboxing conversion on top. */
99
- trait MakesKeyValueSeqStepper [K , V ] extends Any with MakesKeyValueStepper [K , V , Any ] {
100
- def keyStepper [S <: Stepper [_]](implicit ss : StepperShape [K , S ]) = (ss match {
101
- case StepperShape .IntValue => new Stepper .UnboxingIntStepper (keyStepper(StepperShape .anyStepperShape[K ]).asInstanceOf [AnyStepper [Int ]])
102
- case StepperShape .LongValue => new Stepper .UnboxingLongStepper (keyStepper(StepperShape .anyStepperShape[K ]).asInstanceOf [AnyStepper [Long ]])
103
- case StepperShape .DoubleValue => new Stepper .UnboxingDoubleStepper (keyStepper(StepperShape .anyStepperShape[K ]).asInstanceOf [AnyStepper [Double ]])
104
- case StepperShape .ByteValue => new Stepper .UnboxingByteStepper (keyStepper(StepperShape .anyStepperShape[K ]).asInstanceOf [AnyStepper [Byte ]])
105
- case StepperShape .ShortValue => new Stepper .UnboxingShortStepper (keyStepper(StepperShape .anyStepperShape[K ]).asInstanceOf [AnyStepper [Short ]])
106
- case StepperShape .CharValue => new Stepper .UnboxingCharStepper (keyStepper(StepperShape .anyStepperShape[K ]).asInstanceOf [AnyStepper [Char ]])
107
- case StepperShape .FloatValue => new Stepper .UnboxingFloatStepper (keyStepper(StepperShape .anyStepperShape[K ]).asInstanceOf [AnyStepper [Float ]])
108
- case _ => throw new NotImplementedError (" AnyStepper case must be handled in `keyStepper` implementations" )
109
- }).asInstanceOf [S ]
110
-
111
- def valueStepper [S <: Stepper [_]](implicit ss : StepperShape [V , S ]) = (ss match {
112
- case StepperShape .IntValue => new Stepper .UnboxingIntStepper (valueStepper(StepperShape .anyStepperShape[V ]).asInstanceOf [AnyStepper [Int ]])
113
- case StepperShape .LongValue => new Stepper .UnboxingLongStepper (valueStepper(StepperShape .anyStepperShape[V ]).asInstanceOf [AnyStepper [Long ]])
114
- case StepperShape .DoubleValue => new Stepper .UnboxingDoubleStepper (valueStepper(StepperShape .anyStepperShape[V ]).asInstanceOf [AnyStepper [Double ]])
115
- case StepperShape .ByteValue => new Stepper .UnboxingByteStepper (valueStepper(StepperShape .anyStepperShape[V ]).asInstanceOf [AnyStepper [Byte ]])
116
- case StepperShape .ShortValue => new Stepper .UnboxingShortStepper (valueStepper(StepperShape .anyStepperShape[V ]).asInstanceOf [AnyStepper [Short ]])
117
- case StepperShape .CharValue => new Stepper .UnboxingCharStepper (valueStepper(StepperShape .anyStepperShape[V ]).asInstanceOf [AnyStepper [Char ]])
118
- case StepperShape .FloatValue => new Stepper .UnboxingFloatStepper (valueStepper(StepperShape .anyStepperShape[V ]).asInstanceOf [AnyStepper [Float ]])
119
- case _ => throw new NotImplementedError (" AnyStepper case must be handled in `valueStepper` implementations" )
120
- }).asInstanceOf [S ]
88
+ private [this ] val anyStepperShapePrototype : StepperShape [AnyRef , AnyStepper [AnyRef ]] = new StepperShape [AnyRef , AnyStepper [AnyRef ]] {
89
+ def shape = StepperShape .Reference
90
+ def seqUnbox (st : AnyStepper [AnyRef ]): AnyStepper [AnyRef ] = st
91
+ def parUnbox (st : AnyStepper [AnyRef ] with EfficientSubstep ): AnyStepper [AnyRef ] with EfficientSubstep = st
92
+ }
121
93
}
0 commit comments