mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-03 22:45:13 +08:00
优化执行结点
This commit is contained in:
@@ -11,8 +11,8 @@ func TestExecMgr(t *testing.T) {
|
||||
t.Fatalf("init failed,err:%v", err)
|
||||
}
|
||||
|
||||
graphTest1 := bp.Create("testMath")
|
||||
err = graphTest1.Do(EntranceID_IntParam, 1, 2, 3)
|
||||
graphTest1 := bp.Create("testSwitch")
|
||||
err = graphTest1.Do(EntranceID_IntParam, 2, 1, 3)
|
||||
if err != nil {
|
||||
t.Fatalf("Do EntranceID_IntParam failed,err:%v", err)
|
||||
}
|
||||
|
||||
@@ -478,6 +478,15 @@ func (en *BaseExecNode) GetOutPortArrayLen(index int) Port_Int {
|
||||
}
|
||||
|
||||
func (en *BaseExecNode) DoNext(index int) error {
|
||||
// 记录之前的上下文,执行完后需要恢复
|
||||
preExContext := en.ExecContext
|
||||
preExecNode := en.execNode
|
||||
|
||||
defer func() {
|
||||
en.ExecContext = preExContext
|
||||
en.execNode = preExecNode
|
||||
}()
|
||||
|
||||
// -1 表示中断运行
|
||||
if index == -1 {
|
||||
return nil
|
||||
|
||||
@@ -11,8 +11,10 @@ func init() {
|
||||
RegExecNode(&MulInt{})
|
||||
RegExecNode(&DivInt{})
|
||||
RegExecNode(&ModInt{})
|
||||
RegExecNode(&RandNumber{})
|
||||
}
|
||||
|
||||
// AddInt 加(int)
|
||||
type AddInt struct {
|
||||
BaseExecNode
|
||||
}
|
||||
@@ -51,6 +53,7 @@ func (em *AddInt) Exec() (int, error) {
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
// SubInt 减(int)
|
||||
type SubInt struct {
|
||||
BaseExecNode
|
||||
}
|
||||
@@ -102,6 +105,7 @@ func (em *SubInt) Exec() (int, error) {
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
// MulInt 乘(int)
|
||||
type MulInt struct {
|
||||
BaseExecNode
|
||||
}
|
||||
@@ -140,6 +144,7 @@ func (em *MulInt) Exec() (int, error) {
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
// DivInt 除(int)
|
||||
type DivInt struct {
|
||||
BaseExecNode
|
||||
}
|
||||
@@ -198,6 +203,7 @@ func (em *DivInt) Exec() (int, error) {
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
// ModInt 取模(int)
|
||||
type ModInt struct {
|
||||
BaseExecNode
|
||||
}
|
||||
@@ -239,6 +245,7 @@ func (em *ModInt) Exec() (int, error) {
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
// RandNumber 范围随机[0,99]
|
||||
type RandNumber struct {
|
||||
BaseExecNode
|
||||
}
|
||||
|
||||
@@ -89,19 +89,19 @@ func (en *execNode) exec(gr *Graph) (int, error) {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
inPort, outPort := node.GetPorts()
|
||||
debugString := "inPort:"
|
||||
for i := 0; i < len(inPort); i++ {
|
||||
debugString += fmt.Sprintf("%+v,", inPort[i])
|
||||
}
|
||||
debugString += " outPort:"
|
||||
for i := 0; i < len(outPort); i++ {
|
||||
debugString += fmt.Sprintf("%+v,", outPort[i])
|
||||
}
|
||||
//defer func() {
|
||||
inPort, outPort := node.GetPorts()
|
||||
debugString := "inPort:"
|
||||
for i := 0; i < len(inPort); i++ {
|
||||
debugString += fmt.Sprintf("%+v,", inPort[i])
|
||||
}
|
||||
debugString += " outPort:"
|
||||
for i := 0; i < len(outPort); i++ {
|
||||
debugString += fmt.Sprintf("%+v,", outPort[i])
|
||||
}
|
||||
|
||||
fmt.Printf("exec node %s,%s\n", en.execNode.GetName(), debugString)
|
||||
}()
|
||||
fmt.Printf("exec node %s,%s\n", en.execNode.GetName(), debugString)
|
||||
//}()
|
||||
|
||||
return e.Exec()
|
||||
}
|
||||
|
||||
@@ -21,6 +21,13 @@ func init() {
|
||||
RegExecNode(&GetArrayInt{})
|
||||
RegExecNode(&GetArrayString{})
|
||||
RegExecNode(&GetArrayLen{})
|
||||
|
||||
RegExecNode(&BoolIf{})
|
||||
RegExecNode(&GreaterThanInteger{})
|
||||
RegExecNode(&LessThanInteger{})
|
||||
RegExecNode(&EqualInteger{})
|
||||
RegExecNode(&RangeCompare{})
|
||||
RegExecNode(&Probability{})
|
||||
}
|
||||
|
||||
type Entrance_ArrayParam struct {
|
||||
@@ -226,6 +233,7 @@ func (em *GetArrayLen) Exec() (int, error) {
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
// BoolIf 布尔判断
|
||||
type BoolIf struct {
|
||||
BaseExecNode
|
||||
}
|
||||
@@ -252,6 +260,7 @@ func (em *BoolIf) Exec() (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// GreaterThanInteger 大于(整型) >
|
||||
type GreaterThanInteger struct {
|
||||
BaseExecNode
|
||||
}
|
||||
@@ -302,6 +311,7 @@ func (em *GreaterThanInteger) Exec() (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// LessThanInteger 小于(整型) <
|
||||
type LessThanInteger struct {
|
||||
BaseExecNode
|
||||
}
|
||||
@@ -352,6 +362,7 @@ func (em *LessThanInteger) Exec() (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// EqualInteger 等于(整型)==
|
||||
type EqualInteger struct {
|
||||
BaseExecNode
|
||||
}
|
||||
@@ -387,6 +398,7 @@ func (em *EqualInteger) Exec() (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// RangeCompare 范围比较<=
|
||||
type RangeCompare struct {
|
||||
BaseExecNode
|
||||
}
|
||||
@@ -421,6 +433,7 @@ func (em *RangeCompare) Exec() (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// Probability 概率判断(万分比)
|
||||
type Probability struct {
|
||||
BaseExecNode
|
||||
}
|
||||
@@ -430,7 +443,6 @@ func (em *Probability) GetName() string {
|
||||
}
|
||||
|
||||
func (em *Probability) Exec() (int, error) {
|
||||
|
||||
inPortProbability := em.GetInPort(1)
|
||||
if inPortProbability == nil {
|
||||
return -1, fmt.Errorf("GreaterThanInteger inParam 1 not found")
|
||||
|
||||
Reference in New Issue
Block a user