Bläddra i källkod

[fin] add_subcription

* 단위테스트는 아직 x
secure
extra1563 4 år sedan
förälder
incheckning
dd8dc11fc8
1 ändrade filer med 76 tillägg och 46 borttagningar
  1. 76
    46
      modules/subscription.go

+ 76
- 46
modules/subscription.go Visa fil

@@ -6,7 +6,6 @@ import (
6 6
 )
7 7
 
8 8
 type sub_manager struct {
9
-
10 9
 	// NameList의 노드들이 각각의 list를 갖음
11 10
 	list NameList
12 11
 
@@ -25,7 +24,7 @@ func (manager *sub_manager) add_subscription(msg MsgUnit) error {
25 24
 	value := msg.(*SubscriptionMsg).value
26 25
 	subnumber := 0
27 26
 
28
-	fmt.Println("name = ", name, " value = ", value) // for debuging
27
+	fmt.Println("name = ", name, " value = ", value) // for debugging
29 28
 
30 29
 	// * 1. 들어온 Msg -> sub#, sub# -> Msg로 매핑
31 30
 	if len(manager.emptylist) == 0 {
@@ -41,67 +40,95 @@ func (manager *sub_manager) add_subscription(msg MsgUnit) error {
41 40
 		subnumber = subidx
42 41
 	}
43 42
 
44
-	// * 2. value가 연산식인지 확인
45
-	isformula := check_Subtype(value)
46
-
47
-	// * 3. Sub 추가
48
-	nameidx := manager.list.head
43
+	// * 2. Sub 추가
44
+	nameptr := manager.list.head
49 45
 	findOk := false
50 46
 
51
-	// * namelist에서 name찾고, 없으면 추가
52
-	for nameidx != nil {
47
+	//namelist에서 name찾고, 없으면 추가
48
+	for nameptr != nil {
53 49
 		// *  compare함수 구현되기 전 임시로 끼어넣은 것 (이 부분은 secure.go 완성되면 다시 확인)
54
-		if compare(nameidx.name, name) == 1 {
50
+		if compare(nameptr.name, name) == 1 {
55 51
 			findOk = true
56 52
 			break
57 53
 		}
58
-		nameidx = nameidx.next
54
+		nameptr = nameptr.next
59 55
 	}
60 56
 
61
-	newNode := &NameNode{name, nil, List{}}
62 57
 	if findOk == false {
58
+		newNode := &NameNode{name, nil, List{}}
63 59
 		manager.list.tail.next = newNode
64 60
 		manager.list.tail = newNode
65 61
 		manager.list.size++
66
-		nameidx = manager.list.tail
62
+		nameptr = manager.list.tail
67 63
 	}
68 64
 
69
-	// * list[name]에 value추가
70
-	if isformula == false { // 단순 매칭이라면
71
-		valptr := nameidx.list.head
72
-
65
+	// *  ---  가정  ---
66
+	// *  데이터의 value형식은 아래의 두 개 꼴로만 들어온다고 가정
67
+	// *  	(1). {enc(val), op}  == 부등식
68
+	// *       -> (ex)  {2, '<'} , { "baseball", == }
69
+	// *  	(2). {부등식, '&&', 부등식}  or {부등식, '||', 부등식}
70
+	// *       -> (ex1)  {2, '<=', '&&', 3 , '>'}   ==  {2 <= x < 3}
71
+	// *          (ex2)  {12, '<', '||', 5 , '>'}   ==  {12 < x || x < 5}
72
+	// *  -------------
73
+
74
+	// list[name]에 value추가
75
+	if len(value) == 2 { // 단일 식이라면 (single)
76
+		valptr := nameptr.list.head
73 77
 		for valptr != nil {
74 78
 			// * 이 부분도 compare함수 구현하면 다시봐야함
75
-			if compare(valptr.val, conv(value)) == 1{ // value와 같은 val을 갖는 노드가 존재한다면
76
-				valptr.single2sub_e = append(valptr.single2sub_e, subnumber)
77
-				return nil // 제대로 insert된 것
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
78 82
 			}
79
-			valptr=valptr.next
83
+			valptr = valptr.next
80 84
 		}
81
-		
85
+
82 86
 		// value와 일치하는 노드가 x -> 추가
83
-		newValNode := & Node{conv(value)}
84
-		newValNode.single2sub_e = append(newValNode.single2sub_e, subnumber)  
85
-		nameidx.list.tail.next = newValNode
86
-		nameidx.list.tail = newValNode
87
-		nameidx.list.size++
88
-	} else{ // 연산식이라면
89
-			
90
-	}
87
+		nameptr.list.add_ValueNode(value[0], value[1], subnumber, true)
91 88
 
92
-	return nil
93
-}
89
+		return nil // add_subscription ok
90
+	} else {
94 91
 
92
+		// rangesub check
93
+		manager.israngesub[subnumber] = true
95 94
 
96
-// * string형태로 암호화 되어있는 value -> int64[]로 변환(임시) 
97
-func conv(val string) []int64{
98
-	var ret := [] int64
99
-	return ret
100
-}
95
+		// '&&' , '||'로 묶여 있는 복합식에 대하여
96
+		logical_operator := value[2]
101 97
 
102
-// * 암호화된 두 value 비교함수 (임시)
103
-func compare(v1 []int64, v2 []int64) int {
104
-	return 1
98
+		// find(namelist[name].list.val == value)인 노드
99
+		valptr1 := nameptr.list.getPos(conv(value[0]))
100
+		valptr2 := nameptr.list.getPos(conv(value[3]))
101
+
102
+		if logical_operator == "&&" { // '&&'로 묶여있다면
103
+			if valptr1 != nil && valptr2 != nil { // val1, val2를 갖는 노드가 둘 다 존재
104
+				valptr1.insert_Sub(value[1], subnumber, false)
105
+				valptr2.insert_Sub(value[4], subnumber, false)
106
+			}
107
+			if valptr1 == nil {
108
+				nameptr.list.add_ValueNode(value[0], value[1], subnumber, false)
109
+			}
110
+			if valptr2 == nil {
111
+				nameptr.list.add_ValueNode(value[3], value[4], subnumber, false)
112
+			}
113
+
114
+		} else {
115
+
116
+			// '||'로 묶여 있다면 두 식 모두 single로 처리가능
117
+
118
+			if valptr1 != nil && valptr2 != nil { // val1, val2를 갖는 노드가 둘 다 존재
119
+				valptr1.insert_Sub(value[1], subnumber, true)
120
+				valptr2.insert_Sub(value[4], subnumber, true)
121
+			}
122
+			if valptr1 == nil {
123
+				nameptr.list.add_ValueNode(value[0], value[1], subnumber, true)
124
+			}
125
+			if valptr2 == nil {
126
+				nameptr.list.add_ValueNode(value[3], value[4], subnumber, true)
127
+			}
128
+		}
129
+		return nil
130
+	}
131
+	return errors.New("Can't add_subscription")
105 132
 }
106 133
 
107 134
 //	* ### To delete sub#
@@ -110,10 +137,13 @@ func (manager *sub_manager) delete(subnumber int) error {
110 137
 	return s
111 138
 }
112 139
 
113
-func check_Subtype(value []string) bool {
114
-	if len(value) == 1 {
115
-		return false
116
-	} else {
117
-		return true
118
-	}
140
+// * string형태로 암호화 되어있는 value -> int64[]로 변환(임시)
141
+func conv(val string) []int64 {
142
+	ret := make([]int64, len(val))
143
+	return ret
119 144
 }
145
+
146
+// * 암호화된 두 value 비교함수 (임시)
147
+func compare(v1 []int64, v2 []int64) int {
148
+	return 1
149
+}

Laddar…
Avbryt
Spara