Procházet zdrojové kódy

[revise] rename & revise func

master
extra1563 před 4 roky
rodič
revize
8503f9656d
1 změnil soubory, kde provedl 105 přidání a 25 odebrání
  1. 105
    25
      src/broker/modules/list.go

+ 105
- 25
src/broker/modules/list.go Zobrazit soubor

@@ -4,29 +4,29 @@ package modules
4 4
 	Sub정보들을 관리할 list
5 5
 */
6 6
 
7
-type NameList struct {
8
-	head *NameNode
9
-	tail *NameNode
7
+type topicList struct {
8
+	head *topicNode
9
+	tail *topicNode
10 10
 	size int
11 11
 }
12 12
 
13
-type NameNode struct {
13
+type topicNode struct {
14 14
 	topic []int64 // Encrypt된 topic
15
-	next  *NameNode
16
-	prev  *NameNode
17
-	list  List
15
+	next  *topicNode
16
+	prev  *topicNode
17
+	list  valueList
18 18
 }
19 19
 
20
-type List struct {
21
-	head *Node
22
-	tail *Node
20
+type valueList struct {
21
+	head *valueNode
22
+	tail *valueNode
23 23
 	size int
24 24
 }
25 25
 
26
-type Node struct {
26
+type valueNode struct {
27 27
 	val  []int64 // Encrypt된 value
28
-	next *Node
29
-	prev *Node
28
+	next *valueNode
29
+	prev *valueNode
30 30
 
31 31
 	// single //
32 32
 	single2sub_s  []int // (val < x) sub#
@@ -56,7 +56,20 @@ func findSub(ary []int, sub int) int {
56 56
 	return -1
57 57
 }
58 58
 
59
-func (n *Node) isempty() bool {
59
+func (l *topicList) addTopicNode(topic []int64){
60
+	newNode := &topicNode{topic, nil, nil, valueList{}}
61
+	if l.head == nil{
62
+		l.head = newNode
63
+		l.tail = l.head
64
+	} else{
65
+		newNode.prev = l.tail
66
+		l.tail.next = newNode
67
+		l.tail = newNode
68
+	}
69
+	l.size++
70
+}
71
+
72
+func (n *valueNode) isEmpty() bool {
60 73
 	empty := true
61 74
 	if len(n.single2sub_s) != 0 {
62 75
 		empty = false
@@ -89,7 +102,7 @@ func (n *Node) isempty() bool {
89 102
 }
90 103
 
91 104
 // 노드의 operator리스트에 sub#을 in
92
-func (l *Node) insert_Sub(op string, sub int, issingle bool) {
105
+func (l *valueNode) insertSub(op string, sub int, issingle bool) {
93 106
 	if issingle == true {
94 107
 		switch op {
95 108
 		case "<":
@@ -117,21 +130,88 @@ func (l *Node) insert_Sub(op string, sub int, issingle bool) {
117 130
 	}
118 131
 }
119 132
 
120
-func (l *List) add_ValueNode(value []int64) {
121
-	newValNode := &Node{value, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}
122
-	l.tail.next = newValNode
123
-	l.tail = newValNode
133
+func (l *valueList) addValueNode(value []int64) {
134
+	newValNode := &valueNode{value, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}
135
+	if l.head == nil{
136
+		l.head = newValNode
137
+		l.tail = l.head
138
+	} else{
139
+		newValNode.prev = l.tail
140
+		l.tail.next = newValNode
141
+		l.tail = newValNode
142
+	}
124 143
 	l.size++
125 144
 }
126 145
 
127
-func (l *List) getPos(value []int64) *Node {
128
-	valptr := l.head
129
-	for valptr != nil {
146
+func (l *topicList) getTopicNodePos(topic []int64) *topicNode {
147
+	topicPtr := l.head
148
+	for topicPtr != nil {
149
+		if len(topicPtr.topic) == 0{
150
+			topicPtr = topicPtr.next
151
+			continue
152
+		}
130 153
 		// * compare 완성된다면 다시보기
131
-		if compare(valptr.val, value) == 0 { // value와 같은 val을 갖는 노드가 존재한다면
132
-			return valptr
154
+		if l.CompareTopic(topicPtr.topic, topic) == 0 {
155
+			return topicPtr
133 156
 		}
134
-		valptr = valptr.next
157
+		topicPtr = topicPtr.next
135 158
 	}
136 159
 	return nil
137 160
 }
161
+
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 {
176
+	valPtr := l.head
177
+	for valPtr != nil {
178
+		if len(valPtr.val) == 0{
179
+			valPtr = valPtr.next
180
+			continue
181
+		}
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
+			}
190
+		}
191
+		valPtr = valPtr.next
192
+	}
193
+	return nil
194
+}
195
+
196
+
197
+func CompareDigit(value1 int64, value2 int64) int {
198
+	if value1 < value2 {
199
+		return 1
200
+	} else if value1 > value2 {
201
+		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
214
+		}
215
+	}
216
+	return 0
217
+}

Načítá se…
Zrušit
Uložit