You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

var.go 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package dag
  2. import (
  3. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/exec"
  4. "gitlink.org.cn/cloudream/common/utils/lo2"
  5. )
  6. type EndPoint struct {
  7. Node Node
  8. SlotIndex int // 所连接的Node的Output或Input数组的索引
  9. }
  10. type EndPointSlots []EndPoint
  11. func (s *EndPointSlots) Len() int {
  12. return len(*s)
  13. }
  14. func (s *EndPointSlots) Get(idx int) *EndPoint {
  15. return &(*s)[idx]
  16. }
  17. func (s *EndPointSlots) Add(ed EndPoint) int {
  18. (*s) = append((*s), ed)
  19. return len(*s) - 1
  20. }
  21. func (s *EndPointSlots) Remove(ed EndPoint) {
  22. for i, e := range *s {
  23. if e == ed {
  24. (*s) = lo2.RemoveAt((*s), i)
  25. return
  26. }
  27. }
  28. }
  29. func (s *EndPointSlots) RemoveAt(idx int) {
  30. lo2.RemoveAt((*s), idx)
  31. }
  32. func (s *EndPointSlots) Resize(size int) {
  33. if s.Len() < size {
  34. (*s) = append((*s), make([]EndPoint, size-s.Len())...)
  35. } else if s.Len() > size {
  36. (*s) = (*s)[:size]
  37. }
  38. }
  39. func (s *EndPointSlots) RawArray() []EndPoint {
  40. return *s
  41. }
  42. type Var struct {
  43. VarID exec.VarID
  44. from EndPoint
  45. to EndPointSlots
  46. }
  47. func (v *Var) From() *EndPoint {
  48. return &v.from
  49. }
  50. func (v *Var) To() *EndPointSlots {
  51. return &v.to
  52. }
  53. func (v *Var) ValueTo(to Node, slotIdx int) {
  54. v.To().Add(EndPoint{Node: to, SlotIndex: slotIdx})
  55. to.InputValues().Set(slotIdx, v)
  56. }
  57. func (v *Var) ValueNotTo(node Node, slotIdx int) {
  58. v.to.Remove(EndPoint{Node: node, SlotIndex: slotIdx})
  59. node.InputValues().Set(slotIdx, nil)
  60. }
  61. func (v *Var) StreamTo(to Node, slotIdx int) {
  62. v.To().Add(EndPoint{Node: to, SlotIndex: slotIdx})
  63. to.InputStreams().Set(slotIdx, v)
  64. }
  65. func (v *Var) StreamNotTo(node Node, slotIdx int) {
  66. v.to.Remove(EndPoint{Node: node, SlotIndex: slotIdx})
  67. node.InputStreams().Set(slotIdx, nil)
  68. }
  69. func (v *Var) NoInputAllValue() {
  70. for _, ed := range v.to {
  71. ed.Node.InputValues().Set(ed.SlotIndex, nil)
  72. }
  73. v.to = nil
  74. }
  75. func (v *Var) NoInputAllStream() {
  76. for _, ed := range v.to {
  77. ed.Node.InputStreams().Set(ed.SlotIndex, nil)
  78. }
  79. v.to = nil
  80. }