|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package dag
-
- import (
- "gitlink.org.cn/cloudream/common/pkgs/ioswitch/exec"
- "gitlink.org.cn/cloudream/common/utils/lo2"
- )
-
- type Var interface {
- GetVarID() exec.VarID
- }
-
- type StreamVar struct {
- VarID exec.VarID
- Src Node
- Dst DstList
- }
-
- func (v *StreamVar) GetVarID() exec.VarID {
- return v.VarID
- }
-
- func (v *StreamVar) IndexAtSrc() int {
- return v.Src.OutputStreams().IndexOf(v)
- }
-
- func (v *StreamVar) To(to Node, slotIdx int) {
- v.Dst.Add(to)
- to.InputStreams().Slots.Set(slotIdx, v)
- }
-
- func (v *StreamVar) ToSlot(slot StreamInputSlot) {
- v.Dst.Add(slot.Node)
- slot.Node.InputStreams().Slots.Set(slot.Index, v)
- }
-
- func (v *StreamVar) NotTo(node Node) {
- v.Dst.Remove(node)
- node.InputStreams().Slots.Clear(v)
- }
-
- func (v *StreamVar) ClearAllDst() {
- for _, n := range v.Dst {
- n.InputStreams().Slots.Clear(v)
- }
- v.Dst = nil
- }
-
- type ValueVar struct {
- VarID exec.VarID
- Src Node
- Dst DstList
- }
-
- func (v *ValueVar) GetVarID() exec.VarID {
- return v.VarID
- }
-
- func (v *ValueVar) IndexAtSrc() int {
- return v.Src.InputValues().IndexOf(v)
- }
-
- func (v *ValueVar) To(to Node, slotIdx int) {
- v.Dst.Add(to)
- to.InputValues().Slots.Set(slotIdx, v)
- }
-
- func (v *ValueVar) NotTo(node Node) {
- v.Dst.Remove(node)
- node.InputValues().Slots.Clear(v)
- }
-
- func (v *ValueVar) ClearAllDst() {
- for _, n := range v.Dst {
- n.InputValues().Slots.Clear(v)
- }
- v.Dst = nil
- }
-
- type DstList []Node
-
- func (s *DstList) Len() int {
- return len(*s)
- }
-
- func (s *DstList) Get(idx int) Node {
- return (*s)[idx]
- }
-
- func (s *DstList) Add(n Node) int {
- (*s) = append((*s), n)
- return len(*s) - 1
- }
-
- func (s *DstList) Remove(n Node) {
- for i, e := range *s {
- if e == n {
- (*s) = lo2.RemoveAt((*s), i)
- return
- }
- }
- }
-
- func (s *DstList) RemoveAt(idx int) {
- lo2.RemoveAt((*s), idx)
- }
-
- func (s *DstList) Resize(size int) {
- if s.Len() < size {
- (*s) = append((*s), make([]Node, size-s.Len())...)
- } else if s.Len() > size {
- (*s) = (*s)[:size]
- }
- }
-
- func (s *DstList) RawArray() []Node {
- return *s
- }
|