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