Project Moscato Team Messaging Middleware Implemetation Message Middleware by Golang Operate as Secure, Effectively
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

list.go 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package modules
  2. /*
  3. Sub정보들을 관리할 list
  4. */
  5. type NameList struct {
  6. head *NameNode
  7. tail *NameNode
  8. size int
  9. }
  10. type NameNode struct {
  11. topic []int64 // Encrypt된 topic
  12. next *NameNode
  13. prev *NameNode
  14. list List
  15. }
  16. type List struct {
  17. head *Node
  18. tail *Node
  19. size int
  20. }
  21. type Node struct {
  22. val []int64 // Encrypt된 value
  23. next *Node
  24. prev *Node
  25. // single //
  26. single2sub_s []int // (val < x) sub#
  27. single2sub_es []int // (val <= x) sub#
  28. single2sub_b []int // (val > x) sub#
  29. single2sub_eb []int // (val >= x) sub#
  30. single2sub_e []int // (val == x) sub#
  31. // range //
  32. range2sub_s []int // (val < x and ...) sub#
  33. range2sub_es []int // (val <= x and ...) sub#
  34. range2sub_b []int // (val > x and ...) sub#
  35. range2sub_eb []int // (val >= x and ...) sub#
  36. }
  37. // ### To delete slice Array
  38. func remove(ary []int, i int) []int {
  39. return append(ary[:i], ary[i+1:]...)
  40. }
  41. func findSub(ary []int, sub int) int {
  42. for i := 0; i < len(ary); i++ {
  43. if ary[i] == sub {
  44. return i
  45. }
  46. }
  47. return -1
  48. }
  49. func (n *Node) isempty() bool {
  50. empty := true
  51. if len(n.single2sub_s) != 0 {
  52. empty = false
  53. }
  54. if len(n.single2sub_es) != 0 {
  55. empty = false
  56. }
  57. if len(n.single2sub_b) != 0 {
  58. empty = false
  59. }
  60. if len(n.single2sub_eb) != 0 {
  61. empty = false
  62. }
  63. if len(n.single2sub_e) != 0 {
  64. empty = false
  65. }
  66. if len(n.range2sub_s) != 0 {
  67. empty = false
  68. }
  69. if len(n.range2sub_es) != 0 {
  70. empty = false
  71. }
  72. if len(n.range2sub_b) != 0 {
  73. empty = false
  74. }
  75. if len(n.range2sub_eb) != 0 {
  76. empty = false
  77. }
  78. return empty
  79. }
  80. // 노드의 operator리스트에 sub#을 in
  81. func (l *Node) insert_Sub(op string, sub int, issingle bool) {
  82. if issingle == true {
  83. switch op {
  84. case "<":
  85. l.single2sub_s = append(l.single2sub_s, sub)
  86. case "<=":
  87. l.single2sub_es = append(l.single2sub_es, sub)
  88. case ">":
  89. l.single2sub_b = append(l.single2sub_b, sub)
  90. case ">=":
  91. l.single2sub_eb = append(l.single2sub_eb, sub)
  92. case "==":
  93. l.single2sub_e = append(l.single2sub_e, sub)
  94. }
  95. } else {
  96. switch op {
  97. case "<":
  98. l.range2sub_s = append(l.range2sub_s, sub)
  99. case "<=":
  100. l.range2sub_es = append(l.range2sub_es, sub)
  101. case ">":
  102. l.range2sub_b = append(l.range2sub_b, sub)
  103. case ">=":
  104. l.range2sub_eb = append(l.range2sub_eb, sub)
  105. }
  106. }
  107. }
  108. func (l *List) add_ValueNode(value []int64) {
  109. newValNode := &Node{value, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}
  110. l.tail.next = newValNode
  111. l.tail = newValNode
  112. l.size++
  113. }
  114. func (l *List) getPos(value []int64) *Node {
  115. valptr := l.head
  116. for valptr != nil {
  117. // * compare 완성된다면 다시보기
  118. if compare(valptr.val, value) == 0 { // value와 같은 val을 갖는 노드가 존재한다면
  119. return valptr
  120. }
  121. valptr = valptr.next
  122. }
  123. return nil
  124. }