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 2.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package dag
  2. import (
  3. "gitlink.org.cn/cloudream/common/utils/lo2"
  4. "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/ioswitch/exec"
  5. )
  6. type Var interface {
  7. GetVarID() exec.VarID
  8. }
  9. type StreamVar struct {
  10. VarID exec.VarID
  11. Src Node
  12. Dst DstList
  13. }
  14. func (v *StreamVar) GetVarID() exec.VarID {
  15. return v.VarID
  16. }
  17. func (v *StreamVar) IndexAtSrc() int {
  18. return v.Src.OutputStreams().IndexOf(v)
  19. }
  20. func (v *StreamVar) To(to Node, slotIdx int) {
  21. v.Dst.Add(to)
  22. to.InputStreams().Slots.Set(slotIdx, v)
  23. }
  24. func (v *StreamVar) ToSlot(slot StreamInputSlot) {
  25. v.Dst.Add(slot.Node)
  26. slot.Node.InputStreams().Slots.Set(slot.Index, v)
  27. }
  28. func (v *StreamVar) NotTo(node Node) {
  29. v.Dst.Remove(node)
  30. node.InputStreams().Slots.Clear(v)
  31. }
  32. func (v *StreamVar) ClearAllDst() {
  33. for _, n := range v.Dst {
  34. n.InputStreams().Slots.Clear(v)
  35. }
  36. v.Dst = nil
  37. }
  38. type ValueVar struct {
  39. VarID exec.VarID
  40. Src Node
  41. Dst DstList
  42. }
  43. func (v *ValueVar) GetVarID() exec.VarID {
  44. return v.VarID
  45. }
  46. func (v *ValueVar) IndexAtSrc() int {
  47. return v.Src.InputValues().IndexOf(v)
  48. }
  49. func (v *ValueVar) To(to Node, slotIdx int) {
  50. v.Dst.Add(to)
  51. to.InputValues().Slots.Set(slotIdx, v)
  52. }
  53. func (v *ValueVar) ToSlot(slot ValueInputSlot) {
  54. v.Dst.Add(slot.Node)
  55. slot.Node.InputValues().Slots.Set(slot.Index, v)
  56. }
  57. func (v *ValueVar) NotTo(node Node) {
  58. v.Dst.Remove(node)
  59. node.InputValues().Slots.Clear(v)
  60. }
  61. func (v *ValueVar) ClearAllDst() {
  62. for _, n := range v.Dst {
  63. n.InputValues().Slots.Clear(v)
  64. }
  65. v.Dst = nil
  66. }
  67. type DstList []Node
  68. func (s *DstList) Len() int {
  69. return len(*s)
  70. }
  71. func (s *DstList) Get(idx int) Node {
  72. return (*s)[idx]
  73. }
  74. func (s *DstList) Add(n Node) int {
  75. *s = append(*s, n)
  76. return len(*s) - 1
  77. }
  78. func (s *DstList) Remove(n Node) {
  79. for i, e := range *s {
  80. if e == n {
  81. *s = lo2.RemoveAt(*s, i)
  82. return
  83. }
  84. }
  85. }
  86. func (s *DstList) RemoveAt(idx int) {
  87. lo2.RemoveAt(*s, idx)
  88. }
  89. func (s *DstList) Resize(size int) {
  90. if s.Len() < size {
  91. *s = append(*s, make([]Node, size-s.Len())...)
  92. } else if s.Len() > size {
  93. *s = (*s)[:size]
  94. }
  95. }
  96. func (s *DstList) RawArray() []Node {
  97. return *s
  98. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。