Project Moscato Team Messaging Middleware Implemetation Message Middleware by Golang Operate as Secure, Effectively
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

list.go 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. package modules
  2. /*
  3. Sub정보들을 관리할 list
  4. */
  5. type topicList struct {
  6. head *topicNode
  7. tail *topicNode
  8. size int
  9. }
  10. type topicNode struct {
  11. topic []int64 // Encrypt된 topic
  12. next *topicNode
  13. prev *topicNode
  14. list valueList
  15. }
  16. type valueList struct {
  17. head *valueNode
  18. tail *valueNode
  19. size int
  20. }
  21. type valueNode struct {
  22. val []int64 // Encrypt된 value
  23. next *valueNode
  24. prev *valueNode
  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 (l *topicList) addTopicNode(topic []int64){
  50. newNode := &topicNode{topic, nil, nil, valueList{}}
  51. if l.head == nil{
  52. l.head = newNode
  53. l.tail = l.head
  54. } else{
  55. newNode.prev = l.tail
  56. l.tail.next = newNode
  57. l.tail = newNode
  58. }
  59. l.size++
  60. }
  61. func (n *valueNode) isEmpty() bool {
  62. empty := true
  63. if len(n.single2sub_s) != 0 {
  64. empty = false
  65. }
  66. if len(n.single2sub_es) != 0 {
  67. empty = false
  68. }
  69. if len(n.single2sub_b) != 0 {
  70. empty = false
  71. }
  72. if len(n.single2sub_eb) != 0 {
  73. empty = false
  74. }
  75. if len(n.single2sub_e) != 0 {
  76. empty = false
  77. }
  78. if len(n.range2sub_s) != 0 {
  79. empty = false
  80. }
  81. if len(n.range2sub_es) != 0 {
  82. empty = false
  83. }
  84. if len(n.range2sub_b) != 0 {
  85. empty = false
  86. }
  87. if len(n.range2sub_eb) != 0 {
  88. empty = false
  89. }
  90. return empty
  91. }
  92. // 노드의 operator리스트에 sub#을 in
  93. func (l *valueNode) insertSub(op string, sub int, issingle bool) {
  94. if issingle == true {
  95. switch op {
  96. case "<":
  97. l.single2sub_s = append(l.single2sub_s, sub)
  98. case "<=":
  99. l.single2sub_es = append(l.single2sub_es, sub)
  100. case ">":
  101. l.single2sub_b = append(l.single2sub_b, sub)
  102. case ">=":
  103. l.single2sub_eb = append(l.single2sub_eb, sub)
  104. case "==":
  105. l.single2sub_e = append(l.single2sub_e, sub)
  106. }
  107. } else {
  108. switch op {
  109. case "<":
  110. l.range2sub_s = append(l.range2sub_s, sub)
  111. case "<=":
  112. l.range2sub_es = append(l.range2sub_es, sub)
  113. case ">":
  114. l.range2sub_b = append(l.range2sub_b, sub)
  115. case ">=":
  116. l.range2sub_eb = append(l.range2sub_eb, sub)
  117. }
  118. }
  119. }
  120. func (l *valueList) addValueNode(value []int64) {
  121. newValNode := &valueNode{value, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}
  122. if l.head == nil{
  123. l.head = newValNode
  124. l.tail = l.head
  125. } else{
  126. newValNode.prev = l.tail
  127. l.tail.next = newValNode
  128. l.tail = newValNode
  129. }
  130. l.size++
  131. }
  132. func (l *topicList) getTopicNodePos(topic []int64) *topicNode {
  133. topicPtr := l.head
  134. for topicPtr != nil {
  135. if len(topicPtr.topic) == 0{
  136. topicPtr = topicPtr.next
  137. continue
  138. }
  139. // * compare 완성된다면 다시보기
  140. if l.CompareTopic(topicPtr.topic, topic) == 0 {
  141. return topicPtr
  142. }
  143. topicPtr = topicPtr.next
  144. }
  145. return nil
  146. }
  147. func (l *topicList)CompareTopic(topic1 []int64, topic2 []int64) int {
  148. // 길이 같은지 체크
  149. if len(topic1) != len(topic2) {
  150. return -1
  151. }
  152. for i := 0; i < len(topic2); i++ {
  153. if topic1[i] != topic2[i] {
  154. return -1
  155. }
  156. }
  157. return 0
  158. }
  159. func (l *valueList) getValueNodePos(value []int64, isAlpha bool) *valueNode {
  160. valPtr := l.head
  161. for valPtr != nil {
  162. if len(valPtr.val) == 0{
  163. valPtr = valPtr.next
  164. continue
  165. }
  166. if isAlpha{
  167. if CompareAlpha(value, valPtr.val) == 0{
  168. return valPtr
  169. }
  170. } else{
  171. if CompareDigit(value[0], valPtr.val[0]) == 0{
  172. return valPtr
  173. }
  174. }
  175. valPtr = valPtr.next
  176. }
  177. return nil
  178. }
  179. func CompareDigit(value1 int64, value2 int64) int {
  180. if value1 < value2 {
  181. return 1
  182. } else if value1 > value2 {
  183. return -1
  184. }
  185. return 0
  186. }
  187. func CompareAlpha(value1 []int64, value2 []int64) int {
  188. // 길이 같은지 체크
  189. if len(value1) != len(value2) {
  190. return -1
  191. }
  192. for i := 0; i < len(value2); i++ {
  193. if value1[i] != value2[i] {
  194. return -1
  195. }
  196. }
  197. return 0
  198. }