-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfunc_steerc.go
47 lines (41 loc) · 875 Bytes
/
func_steerc.go
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
package fgbase
import ()
// SteercRdy is ready func for FuncSteerc
func SteercRdy(n *Node) bool {
a := n.Srcs[0]
if a.SrcRdy(n) {
if ZeroTest(a.Val) {
return n.Dsts[0].DstRdy(n)
}
i := 0
if Int(a.Val) < 0 {
i = len(n.Dsts) - 1
} else {
i = min(Int(a.Val), len(n.Dsts)-1)
}
return n.Dsts[i].DstRdy(n)
}
return false
}
// SteercRdy is fire func for FuncSteerc
func SteercFire(n *Node) error {
a := n.Srcs[0]
av := a.SrcGet()
if ZeroTest(av) {
n.Dsts[0].DstPut(av)
} else {
i := 0
if Int(a.Val) < 0 {
i = len(n.Dsts) - 1
} else {
i = min(Int(a.Val), len(n.Dsts)-1)
}
n.Dsts[i].DstPut(av)
}
return nil
}
// FuncSteerc steers a condition one of two ways (if a==0 { x = a } else { y = a }).
func FuncSteerc(a, x, y Edge) Node {
node := MakeNode("steerc", []*Edge{&a}, []*Edge{&x, &y}, SteercRdy, SteercFire)
return node
}