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.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package dag
  2. import "gitlink.org.cn/cloudream/common/utils/lo2"
  3. type EndPoint[NP any, VP any] struct {
  4. Node *Node[NP, VP]
  5. SlotIndex int // 所连接的Node的Output或Input数组的索引
  6. }
  7. type StreamVar[NP any, VP any] struct {
  8. ID int
  9. From EndPoint[NP, VP]
  10. Toes []EndPoint[NP, VP]
  11. Props VP
  12. }
  13. func (v *StreamVar[NP, VP]) To(to *Node[NP, VP], slotIdx int) int {
  14. v.Toes = append(v.Toes, EndPoint[NP, VP]{Node: to, SlotIndex: slotIdx})
  15. to.InputStreams[slotIdx] = v
  16. return len(v.Toes) - 1
  17. }
  18. // func (v *StreamVar[NP, VP]) NotTo(toIdx int) EndPoint[NP, VP] {
  19. // ed := v.Toes[toIdx]
  20. // lo2.RemoveAt(v.Toes, toIdx)
  21. // ed.Node.InputStreams[ed.SlotIndex] = nil
  22. // return ed
  23. // }
  24. func (v *StreamVar[NP, VP]) NotTo(node *Node[NP, VP]) (EndPoint[NP, VP], bool) {
  25. for i, ed := range v.Toes {
  26. if ed.Node == node {
  27. v.Toes = lo2.RemoveAt(v.Toes, i)
  28. ed.Node.InputStreams[ed.SlotIndex] = nil
  29. return ed, true
  30. }
  31. }
  32. return EndPoint[NP, VP]{}, false
  33. }
  34. func (v *StreamVar[NP, VP]) NotToWhere(pred func(to EndPoint[NP, VP]) bool) []EndPoint[NP, VP] {
  35. var newToes []EndPoint[NP, VP]
  36. var rmed []EndPoint[NP, VP]
  37. for _, ed := range v.Toes {
  38. if pred(ed) {
  39. ed.Node.InputStreams[ed.SlotIndex] = nil
  40. rmed = append(rmed, ed)
  41. } else {
  42. newToes = append(newToes, ed)
  43. }
  44. }
  45. v.Toes = newToes
  46. return rmed
  47. }
  48. func (v *StreamVar[NP, VP]) NotToAll() []EndPoint[NP, VP] {
  49. for _, ed := range v.Toes {
  50. ed.Node.InputStreams[ed.SlotIndex] = nil
  51. }
  52. toes := v.Toes
  53. v.Toes = nil
  54. return toes
  55. }
  56. func NodeNewOutputStream[NP any, VP any](node *Node[NP, VP], props VP) *StreamVar[NP, VP] {
  57. str := &StreamVar[NP, VP]{
  58. ID: node.Graph.genVarID(),
  59. From: EndPoint[NP, VP]{Node: node, SlotIndex: len(node.OutputStreams)},
  60. Props: props,
  61. }
  62. node.OutputStreams = append(node.OutputStreams, str)
  63. return str
  64. }
  65. func NodeDeclareInputStream[NP any, VP any](node *Node[NP, VP], cnt int) {
  66. node.InputStreams = make([]*StreamVar[NP, VP], cnt)
  67. }
  68. type ValueVarType int
  69. const (
  70. StringValueVar ValueVarType = iota
  71. SignalValueVar
  72. )
  73. type ValueVar[NP any, VP any] struct {
  74. ID int
  75. From EndPoint[NP, VP]
  76. Toes []EndPoint[NP, VP]
  77. Props VP
  78. }
  79. func (v *ValueVar[NP, VP]) To(to *Node[NP, VP], slotIdx int) int {
  80. v.Toes = append(v.Toes, EndPoint[NP, VP]{Node: to, SlotIndex: slotIdx})
  81. to.InputValues[slotIdx] = v
  82. return len(v.Toes) - 1
  83. }
  84. func NodeNewOutputValue[NP any, VP any](node *Node[NP, VP], props VP) *ValueVar[NP, VP] {
  85. val := &ValueVar[NP, VP]{
  86. ID: node.Graph.genVarID(),
  87. From: EndPoint[NP, VP]{Node: node, SlotIndex: len(node.OutputStreams)},
  88. Props: props,
  89. }
  90. node.OutputValues = append(node.OutputValues, val)
  91. return val
  92. }
  93. func NodeDeclareInputValue[NP any, VP any](node *Node[NP, VP], cnt int) {
  94. node.InputValues = make([]*ValueVar[NP, VP], cnt)
  95. }

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