extra1563 4 лет назад
Родитель
Сommit
225dbb3658
1 измененных файлов: 47 добавлений и 68 удалений
  1. 47
    68
      src/broker/modules/list.go

+ 47
- 68
src/broker/modules/list.go Просмотреть файл

@@ -1,8 +1,6 @@
1 1
 package modules
2 2
 
3
-/*
4
-	Sub정보들을 관리할 list
5
-*/
3
+/* List to manage Sub information */
6 4
 
7 5
 type topicList struct {
8 6
 	head *topicNode
@@ -11,7 +9,7 @@ type topicList struct {
11 9
 }
12 10
 
13 11
 type topicNode struct {
14
-	topic []int64 // Encrypt topic
12
+	topic []int64 // Encrypted topic
15 13
 	next  *topicNode
16 14
 	prev  *topicNode
17 15
 	list  valueList
@@ -24,29 +22,30 @@ type valueList struct {
24 22
 }
25 23
 
26 24
 type valueNode struct {
27
-	val  []int64 // Encrypt된 value
25
+	val  []int64 // Encrypted topic
28 26
 	next *valueNode
29 27
 	prev *valueNode
30 28
 
31 29
 	// single //
32
-	single2sub_s  []int // (val < x) sub#
33
-	single2sub_es []int // (val <= x) sub#
34
-	single2sub_b  []int // (val > x) sub#
35
-	single2sub_eb []int // (val >= x) sub#
36
-	single2sub_e  []int // (val == x) sub#
30
+	single2sub_s  []int // (sub_val < pub_val) sub#s
31
+	single2sub_es []int // (sub_val <= pub_val) sub#s
32
+	single2sub_b  []int // (sub_val > pub_val) sub#s
33
+	single2sub_eb []int // (sub_val >= pub_val) sub#s
34
+	single2sub_e  []int // (sub_val == pub_val) sub#s
37 35
 
38 36
 	// range //
39
-	range2sub_s  []int // (val < x and ...) sub#
40
-	range2sub_es []int // (val <= x and ...) sub#
41
-	range2sub_b  []int // (val > x and ...) sub#
42
-	range2sub_eb []int // (val >= x and ...) sub#
37
+	range2sub_s  []int // (sub_val < pub_val) sub#s
38
+	range2sub_es []int // (sub_val <= pub_val) sub#s
39
+	range2sub_b  []int // (sub_val > pub_val) sub#s
40
+	range2sub_eb []int // (sub_val >= pub_val) sub#s
43 41
 }
44 42
 
45
-// ### To delete slice Array
43
+// To delete slice Array
46 44
 func remove(ary []int, i int) []int {
47 45
 	return append(ary[:i], ary[i+1:]...)
48 46
 }
49 47
 
48
+// To find a specific sub# in a value node
50 49
 func findSub(ary []int, sub int) int {
51 50
 	for i := 0; i < len(ary); i++ {
52 51
 		if ary[i] == sub {
@@ -56,6 +55,7 @@ func findSub(ary []int, sub int) int {
56 55
 	return -1
57 56
 }
58 57
 
58
+// To add a topic node to the topic list
59 59
 func (l *topicList) addTopicNode(topic []int64){
60 60
 	newNode := &topicNode{topic, nil, nil, valueList{}}
61 61
 	if l.head == nil{
@@ -69,6 +69,7 @@ func (l *topicList) addTopicNode(topic []int64){
69 69
 	l.size++
70 70
 }
71 71
 
72
+// To check if a specific value node is empty
72 73
 func (n *valueNode) isEmpty() bool {
73 74
 	empty := true
74 75
 	if len(n.single2sub_s) != 0 {
@@ -101,35 +102,36 @@ func (n *valueNode) isEmpty() bool {
101 102
 	return empty
102 103
 }
103 104
 
104
-// 노드의 operator리스트에 sub#을 in
105
-func (l *valueNode) insertSub(op string, sub int, issingle bool) {
105
+// To insert sub# into the operator list of the value node
106
+func (n *valueNode) insertSub(op string, sub int, issingle bool) {
106 107
 	if issingle == true {
107 108
 		switch op {
108 109
 		case "<":
109
-			l.single2sub_s = append(l.single2sub_s, sub)
110
+			n.single2sub_s = append(n.single2sub_s, sub)
110 111
 		case "<=":
111
-			l.single2sub_es = append(l.single2sub_es, sub)
112
+			n.single2sub_es = append(n.single2sub_es, sub)
112 113
 		case ">":
113
-			l.single2sub_b = append(l.single2sub_b, sub)
114
+			n.single2sub_b = append(n.single2sub_b, sub)
114 115
 		case ">=":
115
-			l.single2sub_eb = append(l.single2sub_eb, sub)
116
+			n.single2sub_eb = append(n.single2sub_eb, sub)
116 117
 		case "==":
117
-			l.single2sub_e = append(l.single2sub_e, sub)
118
+			n.single2sub_e = append(n.single2sub_e, sub)
118 119
 		}
119 120
 	} else {
120 121
 		switch op {
121 122
 		case "<":
122
-			l.range2sub_s = append(l.range2sub_s, sub)
123
+			n.range2sub_s = append(n.range2sub_s, sub)
123 124
 		case "<=":
124
-			l.range2sub_es = append(l.range2sub_es, sub)
125
+			n.range2sub_es = append(n.range2sub_es, sub)
125 126
 		case ">":
126
-			l.range2sub_b = append(l.range2sub_b, sub)
127
+			n.range2sub_b = append(n.range2sub_b, sub)
127 128
 		case ">=":
128
-			l.range2sub_eb = append(l.range2sub_eb, sub)
129
+			n.range2sub_eb = append(n.range2sub_eb, sub)
129 130
 		}
130 131
 	}
131 132
 }
132 133
 
134
+// To add a value node to the value list
133 135
 func (l *valueList) addValueNode(value []int64) {
134 136
 	newValNode := &valueNode{value, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}
135 137
 	if l.head == nil{
@@ -143,6 +145,7 @@ func (l *valueList) addValueNode(value []int64) {
143 145
 	l.size++
144 146
 }
145 147
 
148
+// To get the position of a topic node with a specific topic
146 149
 func (l *topicList) getTopicNodePos(topic []int64) *topicNode {
147 150
 	topicPtr := l.head
148 151
 	for topicPtr != nil {
@@ -150,8 +153,7 @@ func (l *topicList) getTopicNodePos(topic []int64) *topicNode {
150 153
 			topicPtr = topicPtr.next
151 154
 			continue
152 155
 		}
153
-		// * compare 완성된다면 다시보기
154
-		if l.CompareTopic(topicPtr.topic, topic) == 0 {
156
+		if Compare(topicPtr.topic, topic) == 0 {
155 157
 			return topicPtr
156 158
 		}
157 159
 		topicPtr = topicPtr.next
@@ -159,59 +161,36 @@ func (l *topicList) getTopicNodePos(topic []int64) *topicNode {
159 161
 	return nil
160 162
 }
161 163
 
162
-func (l *topicList)CompareTopic(topic1 []int64, topic2 []int64) int {
163
-	// 길이 같은지 체크
164
-	if len(topic1) != len(topic2) {
165
-		return -1
166
-	}
167
-	for i := 0; i < len(topic2); i++ {
168
-		if topic1[i] != topic2[i] {
169
-			return -1
170
-		}
171
-	}
172
-	return 0
173
-}
174
-
175
-func (l *valueList) getValueNodePos(value []int64, isAlpha bool) *valueNode {
164
+// To get the position of a value node with a specific value
165
+func (l *valueList) getValueNodePos(value []int64) *valueNode {
176 166
 	valPtr := l.head
177 167
 	for valPtr != nil {
178 168
 		if len(valPtr.val) == 0{
179 169
 			valPtr = valPtr.next
180 170
 			continue
181 171
 		}
182
-		if isAlpha{
183
-			if CompareAlpha(value, valPtr.val) == 0{
184
-				return valPtr
185
-			}
186
-		} else{
187
-			if CompareDigit(value[0], valPtr.val[0]) == 0{
188
-				return valPtr
189
-			}
172
+		if Compare(value, valPtr.val) == 0 {
173
+			return valPtr
190 174
 		}
191 175
 		valPtr = valPtr.next
192 176
 	}
193 177
 	return nil
194 178
 }
195 179
 
196
-
197
-func CompareDigit(value1 int64, value2 int64) int {
198
-	if value1 < value2 {
180
+// Compare ->  To compare (topics, values) in a node
181
+func Compare(a []int64, b []int64) int {
182
+	if len(a) < len(b) {
199 183
 		return 1
200
-	} else if value1 > value2 {
184
+	} else if len(a) > len(b){
201 185
 		return -1
202
-	}
203
-	return 0
204
-}
205
-
206
-func CompareAlpha(value1 []int64, value2 []int64) int {
207
-	// 길이 같은지 체크
208
-	if len(value1) != len(value2) {
209
-		return -1
210
-	}
211
-	for i := 0; i < len(value2); i++ {
212
-		if value1[i] != value2[i] {
213
-			return -1
186
+	} 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
+			}
214 193
 		}
194
+		return 0
215 195
 	}
216
-	return 0
217
-}
196
+}

Загрузка…
Отмена
Сохранить