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