Skip to content

Commit 03fd5b6

Browse files
committed
Added ThresholdCombiner
1 parent 4aa133b commit 03fd5b6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

combine.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,24 @@ func (c *SubstituteCombiner) Eval2(x, y float64) float64 {
268268
}
269269
return c.Src2.Eval2(x, y)
270270
}
271+
272+
// ThresholdCombiner selects between two sources based on whether src3 exceeds A.
273+
type ThresholdCombiner struct {
274+
Name string
275+
Src1 Field
276+
Src2 Field
277+
Src3 Field
278+
A float64
279+
}
280+
281+
func NewThresholdCombiner(src1, src2, src3 Field, a float64) *ThresholdCombiner {
282+
return &ThresholdCombiner{"ThresholdCombiner", src1, src2, src3, a}
283+
}
284+
285+
// Eval2 implements the Field interface.
286+
func (c *ThresholdCombiner) Eval2(x, y float64) float64 {
287+
if c.Src3.Eval2(x, y) < c.A {
288+
return c.Src1.Eval2(x, y)
289+
}
290+
return c.Src2.Eval2(x, y)
291+
}

0 commit comments

Comments
 (0)