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.

matching.go 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package modules
  2. import (
  3. "errors"
  4. "fmt"
  5. )
  6. // Json Type의 sub Info
  7. type mytype interface{}
  8. var (
  9. list LList
  10. count_sub int // Subscription #
  11. emptylist []int // To administrate sub #
  12. num2sub = make(map[int]mytype) // num2sub[sub#] = subscription info
  13. israngesub = make(map[int]bool)
  14. )
  15. type LList struct {
  16. head *Node
  17. tail *Node
  18. size int
  19. }
  20. type Node struct {
  21. val int // Encrypt된 value
  22. next *Node
  23. // single //
  24. single2sub_s []int // val보다 작은 sub#
  25. single2sub_es []int // val보다 작거나 같은 sub#
  26. single2sub_b []int // val보다 큰 sub#
  27. single2sub_eb []int // val보다 크거나 같은 sub#
  28. single2sub_e []int // val과 같은 sub#
  29. // range //
  30. range2sub_s []int
  31. range2sub_es []int
  32. range2sub_b []int
  33. range2sub_eb []int
  34. }
  35. // ### To delete slice Array
  36. func remove(s []int, i int) []int {
  37. s[i] = s[len(s)-1]
  38. return s[:len(s)-1]
  39. }
  40. // ### To Convert Subinfo -> <value, op, sub#>
  41. // func Conv2info() mytype {
  42. // }
  43. // ### To Sort linkedList -> 다시 고쳐야함
  44. func MergeSort(head *Node, k int) *Node {
  45. if head == nil || head.next == nil {
  46. return head
  47. }
  48. cur := head
  49. nxt := head.next
  50. for nxt != nil && nxt.next != nil {
  51. cur = cur.next
  52. nxt = nxt.next.next
  53. }
  54. left := cur
  55. right := cur.next
  56. cur.next = nil
  57. left = MergeSort(left, k/2)
  58. right = MergeSort(right, k/2)
  59. fmt.Println(left, right)
  60. return Merge(left, right)
  61. }
  62. func Merge(l *Node, r *Node) *Node {
  63. if l == nil {
  64. return r
  65. }
  66. if r == nil {
  67. return l
  68. }
  69. t := new(Node)
  70. if l.val < r.val {
  71. t = l
  72. t.next = Merge(l.next, r)
  73. } else {
  74. t = r
  75. t.next = Merge(l, r.next)
  76. }
  77. return t
  78. }
  79. // ### To Insert sub#
  80. func (lk *LList) PushBack(val int) {
  81. // pseudocode
  82. // if value == val인 노드가 존재
  83. // -> node 추가 x
  84. // -> val < x에 sub# append
  85. // else
  86. // -> 끝에 노드추가
  87. // node := &Node{val: val}
  88. // if lk.head == nil {
  89. // lk.head, lk.tail = node, node
  90. // } else {
  91. // lk.tail.next = node
  92. // lk.tail = node
  93. // }
  94. // lk.size++
  95. }
  96. // ### To delete sub#
  97. func (lk *LList) delete(subnumber int) error {
  98. // pseudocode
  99. // if sub#가 num2sub에 있는지
  100. // -> 없으면 무시
  101. // else if rangesub에 있는지
  102. // if rangesub에 있으면
  103. // delete(range2sub_b, israngesub[sub#])
  104. // else 없으면
  105. // delete(all(single_node)) ...
  106. // -- 노드 자체가 사라진다면 --
  107. // for cur := &lk.head; *cur != nil; {
  108. // if (*cur).val == val {
  109. // lk.size--
  110. // *cur = (*cur).next
  111. // } else {
  112. // lk.tail = *cur
  113. // cur = &(*cur).next
  114. // }
  115. // }
  116. if num2sub[subnumber] == true {
  117. if israngesub[subnumber] == true {
  118. delete(israngesub, subnumber)
  119. ptr := lk.head
  120. for ptr != nil {
  121. for j := 0; j < len(ptr.range2sub_b); j++ {
  122. if ptr.range2sub_b[j] == subnumber {
  123. ptr.range2sub_b = remove(ptr.range2sub_b, j)
  124. return nil
  125. }
  126. }
  127. for j := 0; j < len(ptr.range2sub_eb); j++ {
  128. if ptr.range2sub_eb[j] == subnumber {
  129. ptr.range2sub_eb = remove(ptr.range2sub_eb, j)
  130. return nil
  131. }
  132. }
  133. for j := 0; j < len(ptr.range2sub_s); j++ {
  134. if ptr.range2sub_s[j] == subnumber {
  135. ptr.range2sub_s = remove(ptr.range2sub_s, j)
  136. return nil
  137. }
  138. }
  139. for j := 0; j < len(ptr.range2sub_es); j++ {
  140. if ptr.range2sub_es[j] == subnumber {
  141. ptr.range2sub_es = remove(ptr.range2sub_es, j)
  142. return nil
  143. }
  144. }
  145. }
  146. }
  147. } else {
  148. return errors.New("Don't delete this Subscription (Not exist)")
  149. }
  150. return nil
  151. }