|
|
@@ -55,6 +55,41 @@ func findSub(ary []int, sub int) int {
|
|
55
|
55
|
return -1
|
|
56
|
56
|
}
|
|
57
|
57
|
|
|
|
58
|
+
|
|
|
59
|
+// Compare -> To compare (topics, values) in a node
|
|
|
60
|
+func Compare(a []int64, b []int64) int {
|
|
|
61
|
+ if len(a) < len(b) {
|
|
|
62
|
+ return 1
|
|
|
63
|
+ } else if len(a) > len(b) {
|
|
|
64
|
+ return -1
|
|
|
65
|
+ } else {
|
|
|
66
|
+ for i := 0; i < len(a); i++ {
|
|
|
67
|
+ if a[i] < b[i] {
|
|
|
68
|
+ return 1
|
|
|
69
|
+ } else if a[i] > b[i] {
|
|
|
70
|
+ return -1
|
|
|
71
|
+ }
|
|
|
72
|
+ }
|
|
|
73
|
+ return 0
|
|
|
74
|
+ }
|
|
|
75
|
+}
|
|
|
76
|
+
|
|
|
77
|
+// To get the position of a Topic node with a specific Topic
|
|
|
78
|
+func (l *topicList) getTopicNodePos(topic []int64) *topicNode {
|
|
|
79
|
+ topicPtr := l.head
|
|
|
80
|
+ for topicPtr != nil {
|
|
|
81
|
+ if len(topicPtr.topic) == 0 {
|
|
|
82
|
+ topicPtr = topicPtr.next
|
|
|
83
|
+ continue
|
|
|
84
|
+ }
|
|
|
85
|
+ if Compare(topicPtr.topic, topic) == 0 {
|
|
|
86
|
+ return topicPtr
|
|
|
87
|
+ }
|
|
|
88
|
+ topicPtr = topicPtr.next
|
|
|
89
|
+ }
|
|
|
90
|
+ return nil
|
|
|
91
|
+}
|
|
|
92
|
+
|
|
58
|
93
|
// To add a Topic node to the Topic list
|
|
59
|
94
|
func (l *topicList) addTopicNode(topic []int64) {
|
|
60
|
95
|
newNode := &topicNode{topic, nil, nil, valueList{}}
|
|
|
@@ -69,67 +104,6 @@ func (l *topicList) addTopicNode(topic []int64) {
|
|
69
|
104
|
l.size++
|
|
70
|
105
|
}
|
|
71
|
106
|
|
|
72
|
|
-// To check if a specific Value node is empty
|
|
73
|
|
-func (n *valueNode) isEmpty() bool {
|
|
74
|
|
- empty := true
|
|
75
|
|
- if len(n.single2sub_s) != 0 {
|
|
76
|
|
- empty = false
|
|
77
|
|
- }
|
|
78
|
|
- if len(n.single2sub_es) != 0 {
|
|
79
|
|
- empty = false
|
|
80
|
|
- }
|
|
81
|
|
- if len(n.single2sub_b) != 0 {
|
|
82
|
|
- empty = false
|
|
83
|
|
- }
|
|
84
|
|
- if len(n.single2sub_eb) != 0 {
|
|
85
|
|
- empty = false
|
|
86
|
|
- }
|
|
87
|
|
- if len(n.single2sub_e) != 0 {
|
|
88
|
|
- empty = false
|
|
89
|
|
- }
|
|
90
|
|
- if len(n.range2sub_s) != 0 {
|
|
91
|
|
- empty = false
|
|
92
|
|
- }
|
|
93
|
|
- if len(n.range2sub_es) != 0 {
|
|
94
|
|
- empty = false
|
|
95
|
|
- }
|
|
96
|
|
- if len(n.range2sub_b) != 0 {
|
|
97
|
|
- empty = false
|
|
98
|
|
- }
|
|
99
|
|
- if len(n.range2sub_eb) != 0 {
|
|
100
|
|
- empty = false
|
|
101
|
|
- }
|
|
102
|
|
- return empty
|
|
103
|
|
-}
|
|
104
|
|
-
|
|
105
|
|
-// To insert sub# into the Operator list of the Value node
|
|
106
|
|
-func (n *valueNode) insertSub(op string, sub int, issingle bool) {
|
|
107
|
|
- if issingle == true {
|
|
108
|
|
- switch op {
|
|
109
|
|
- case "<":
|
|
110
|
|
- n.single2sub_s = append(n.single2sub_s, sub)
|
|
111
|
|
- case "<=":
|
|
112
|
|
- n.single2sub_es = append(n.single2sub_es, sub)
|
|
113
|
|
- case ">":
|
|
114
|
|
- n.single2sub_b = append(n.single2sub_b, sub)
|
|
115
|
|
- case ">=":
|
|
116
|
|
- n.single2sub_eb = append(n.single2sub_eb, sub)
|
|
117
|
|
- case "==":
|
|
118
|
|
- n.single2sub_e = append(n.single2sub_e, sub)
|
|
119
|
|
- }
|
|
120
|
|
- } else {
|
|
121
|
|
- switch op {
|
|
122
|
|
- case "<":
|
|
123
|
|
- n.range2sub_s = append(n.range2sub_s, sub)
|
|
124
|
|
- case "<=":
|
|
125
|
|
- n.range2sub_es = append(n.range2sub_es, sub)
|
|
126
|
|
- case ">":
|
|
127
|
|
- n.range2sub_b = append(n.range2sub_b, sub)
|
|
128
|
|
- case ">=":
|
|
129
|
|
- n.range2sub_eb = append(n.range2sub_eb, sub)
|
|
130
|
|
- }
|
|
131
|
|
- }
|
|
132
|
|
-}
|
|
133
|
107
|
|
|
134
|
108
|
// To add a Value node to the Value list
|
|
135
|
109
|
func (l *valueList) addValueNode(value []int64) {
|
|
|
@@ -145,22 +119,6 @@ func (l *valueList) addValueNode(value []int64) {
|
|
145
|
119
|
l.size++
|
|
146
|
120
|
}
|
|
147
|
121
|
|
|
148
|
|
-// To get the position of a Topic node with a specific Topic
|
|
149
|
|
-func (l *topicList) getTopicNodePos(topic []int64) *topicNode {
|
|
150
|
|
- topicPtr := l.head
|
|
151
|
|
- for topicPtr != nil {
|
|
152
|
|
- if len(topicPtr.topic) == 0 {
|
|
153
|
|
- topicPtr = topicPtr.next
|
|
154
|
|
- continue
|
|
155
|
|
- }
|
|
156
|
|
- if Compare(topicPtr.topic, topic) == 0 {
|
|
157
|
|
- return topicPtr
|
|
158
|
|
- }
|
|
159
|
|
- topicPtr = topicPtr.next
|
|
160
|
|
- }
|
|
161
|
|
- return nil
|
|
162
|
|
-}
|
|
163
|
|
-
|
|
164
|
122
|
// To get the position of a Value node with a specific Value
|
|
165
|
123
|
func (l *valueList) getValueNodePos(value []int64) *valueNode {
|
|
166
|
124
|
valPtr := l.head
|
|
|
@@ -177,20 +135,100 @@ func (l *valueList) getValueNodePos(value []int64) *valueNode {
|
|
177
|
135
|
return nil
|
|
178
|
136
|
}
|
|
179
|
137
|
|
|
180
|
|
-// Compare -> To compare (topics, values) in a node
|
|
181
|
|
-func Compare(a []int64, b []int64) int {
|
|
182
|
|
- if len(a) < len(b) {
|
|
183
|
|
- return 1
|
|
184
|
|
- } else if len(a) > len(b) {
|
|
185
|
|
- return -1
|
|
|
138
|
+// To insert sub# into the Operator list of the Value node
|
|
|
139
|
+func (node *valueNode) insertSub(op string, sub int, issingle bool) {
|
|
|
140
|
+ if issingle == true {
|
|
|
141
|
+ switch op {
|
|
|
142
|
+ case "<":
|
|
|
143
|
+ node.single2sub_s = append(node.single2sub_s, sub)
|
|
|
144
|
+ case "<=":
|
|
|
145
|
+ node.single2sub_es = append(node.single2sub_es, sub)
|
|
|
146
|
+ case ">":
|
|
|
147
|
+ node.single2sub_b = append(node.single2sub_b, sub)
|
|
|
148
|
+ case ">=":
|
|
|
149
|
+ node.single2sub_eb = append(node.single2sub_eb, sub)
|
|
|
150
|
+ case "==":
|
|
|
151
|
+ node.single2sub_e = append(node.single2sub_e, sub)
|
|
|
152
|
+ }
|
|
186
|
153
|
} else {
|
|
187
|
|
- for i := 0; i < len(a); i++ {
|
|
188
|
|
- if a[i] < b[i] {
|
|
189
|
|
- return 1
|
|
190
|
|
- } else if a[i] > b[i] {
|
|
191
|
|
- return -1
|
|
192
|
|
- }
|
|
|
154
|
+ switch op {
|
|
|
155
|
+ case "<":
|
|
|
156
|
+ node.range2sub_s = append(node.range2sub_s, sub)
|
|
|
157
|
+ case "<=":
|
|
|
158
|
+ node.range2sub_es = append(node.range2sub_es, sub)
|
|
|
159
|
+ case ">":
|
|
|
160
|
+ node.range2sub_b = append(node.range2sub_b, sub)
|
|
|
161
|
+ case ">=":
|
|
|
162
|
+ node.range2sub_eb = append(node.range2sub_eb, sub)
|
|
|
163
|
+ }
|
|
|
164
|
+ }
|
|
|
165
|
+}
|
|
|
166
|
+
|
|
|
167
|
+// op와 같은 node내의 operator리스트에서 sub가 있다면 리턴
|
|
|
168
|
+func (node *valueNode) findOperatorList(op string, sub int, issingle bool) int {
|
|
|
169
|
+ ret := -1
|
|
|
170
|
+ if issingle == true {
|
|
|
171
|
+ switch op {
|
|
|
172
|
+ case "<":
|
|
|
173
|
+ ret = findSub(node.single2sub_s, sub)
|
|
|
174
|
+ case "<=":
|
|
|
175
|
+ ret = findSub(node.single2sub_es, sub)
|
|
|
176
|
+ case ">":
|
|
|
177
|
+ ret = findSub(node.single2sub_b, sub)
|
|
|
178
|
+ case ">=":
|
|
|
179
|
+ ret = findSub(node.single2sub_eb, sub)
|
|
|
180
|
+ case "==":
|
|
|
181
|
+ ret = findSub(node.single2sub_e, sub)
|
|
|
182
|
+ }
|
|
|
183
|
+ } else {
|
|
|
184
|
+ switch op {
|
|
|
185
|
+ case "<":
|
|
|
186
|
+ ret = findSub(node.range2sub_s, sub)
|
|
|
187
|
+ case "<=":
|
|
|
188
|
+ ret = findSub(node.range2sub_es, sub)
|
|
|
189
|
+ case ">":
|
|
|
190
|
+ ret = findSub(node.range2sub_b, sub)
|
|
|
191
|
+ case ">=":
|
|
|
192
|
+ ret = findSub(node.range2sub_eb, sub)
|
|
193
|
193
|
}
|
|
|
194
|
+ }
|
|
|
195
|
+ if ret < 0{
|
|
194
|
196
|
return 0
|
|
|
197
|
+ } else{
|
|
|
198
|
+ return 1
|
|
195
|
199
|
}
|
|
196
|
200
|
}
|
|
|
201
|
+
|
|
|
202
|
+
|
|
|
203
|
+// To check if a specific Value node is empty
|
|
|
204
|
+func (node *valueNode) isEmpty() bool {
|
|
|
205
|
+ empty := true
|
|
|
206
|
+ if len(node.single2sub_s) != 0 {
|
|
|
207
|
+ empty = false
|
|
|
208
|
+ }
|
|
|
209
|
+ if len(node.single2sub_es) != 0 {
|
|
|
210
|
+ empty = false
|
|
|
211
|
+ }
|
|
|
212
|
+ if len(node.single2sub_b) != 0 {
|
|
|
213
|
+ empty = false
|
|
|
214
|
+ }
|
|
|
215
|
+ if len(node.single2sub_eb) != 0 {
|
|
|
216
|
+ empty = false
|
|
|
217
|
+ }
|
|
|
218
|
+ if len(node.single2sub_e) != 0 {
|
|
|
219
|
+ empty = false
|
|
|
220
|
+ }
|
|
|
221
|
+ if len(node.range2sub_s) != 0 {
|
|
|
222
|
+ empty = false
|
|
|
223
|
+ }
|
|
|
224
|
+ if len(node.range2sub_es) != 0 {
|
|
|
225
|
+ empty = false
|
|
|
226
|
+ }
|
|
|
227
|
+ if len(node.range2sub_b) != 0 {
|
|
|
228
|
+ empty = false
|
|
|
229
|
+ }
|
|
|
230
|
+ if len(node.range2sub_eb) != 0 {
|
|
|
231
|
+ empty = false
|
|
|
232
|
+ }
|
|
|
233
|
+ return empty
|
|
|
234
|
+}
|