Kaynağa Gözat

[fin] add_subcription

secure
extra1563 4 yıl önce
ebeveyn
işleme
0e07810f18
1 değiştirilmiş dosya ile 8 ekleme ve 19 silme
  1. 8
    19
      modules/subscription.go

+ 8
- 19
modules/subscription.go Dosyayı Görüntüle

@@ -46,7 +46,7 @@ func (manager *sub_manager) add_subscription(msg MsgUnit) error {
46 46
 
47 47
 	//namelist에서 name찾고, 없으면 추가
48 48
 	for nameptr != nil {
49
-		// *  compare함수 구현되기 전 임시로 끼넣은 것 (이 부분은 secure.go 완성되면 다시 확인)
49
+		// *  compare함수 구현되기 전 임시로 끼넣은 것 (이 부분은 secure.go 완성되면 다시 확인)
50 50
 		if compare(nameptr.name, name) == 1 {
51 51
 			findOk = true
52 52
 			break
@@ -73,22 +73,14 @@ func (manager *sub_manager) add_subscription(msg MsgUnit) error {
73 73
 
74 74
 	// list[name]에 value추가
75 75
 	if len(value) == 2 { // 단일 식이라면 (single)
76
-		valptr := nameptr.list.head
77
-		for valptr != nil {
78
-			// * 이 부분도 compare함수 구현하면 다시봐야함
79
-			if compare(valptr.val, conv(value[0])) == 1 { // value와 같은 val을 갖는 노드가 존재한다면
80
-				valptr.insert_Sub(value[1], subnumber, true)
81
-				return nil // add_subscription ok
82
-			}
83
-			valptr = valptr.next
76
+		valptr := nameptr.list.getPos(conv(value[0]))
77
+		if valptr == nil{
78
+			nameptr.list.add_ValueNode(value[0], value[1], subnumber, true)
79
+		} else{
80
+			valptr.insert_Sub(value[1], subnumber, true)
84 81
 		}
85
-
86
-		// value와 일치하는 노드가 x -> 추가
87
-		nameptr.list.add_ValueNode(value[0], value[1], subnumber, true)
88
-
89 82
 		return nil // add_subscription ok
90 83
 	} else {
91
-
92 84
 		// rangesub check
93 85
 		manager.israngesub[subnumber] = true
94 86
 
@@ -110,11 +102,8 @@ func (manager *sub_manager) add_subscription(msg MsgUnit) error {
110 102
 			if valptr2 == nil {
111 103
 				nameptr.list.add_ValueNode(value[3], value[4], subnumber, false)
112 104
 			}
113
-
114 105
 		} else {
115
-
116 106
 			// '||'로 묶여 있다면 두 식 모두 single로 처리가능
117
-
118 107
 			if valptr1 != nil && valptr2 != nil { // val1, val2를 갖는 노드가 둘 다 존재
119 108
 				valptr1.insert_Sub(value[1], subnumber, true)
120 109
 				valptr2.insert_Sub(value[4], subnumber, true)
@@ -126,7 +115,7 @@ func (manager *sub_manager) add_subscription(msg MsgUnit) error {
126 115
 				nameptr.list.add_ValueNode(value[3], value[4], subnumber, true)
127 116
 			}
128 117
 		}
129
-		return nil
118
+		return nil // add_subscription ok
130 119
 	}
131 120
 	return errors.New("Can't add_subscription")
132 121
 }
@@ -146,4 +135,4 @@ func conv(val string) []int64 {
146 135
 // * 암호화된 두 value 비교함수 (임시)
147 136
 func compare(v1 []int64, v2 []int64) int {
148 137
 	return 1
149
-}
138
+}

Loading…
İptal
Kaydet