Quellcode durchsuchen

[add] subscription, list [revise] matching

* matching.go -> list.go, subscription으로 분리

* 단일 value에 대한 add_subscription 구현
secure
extra1563 vor 4 Jahren
Ursprung
Commit
79fa87b6f5
3 geänderte Dateien mit 188 neuen und 0 gelöschten Zeilen
  1. 48
    0
      list.go
  2. 21
    0
      matching.go
  3. 119
    0
      subscription.go

+ 48
- 0
list.go Datei anzeigen

@@ -0,0 +1,48 @@
1
+package modules
2
+
3
+/*
4
+	Sub정보들을 관리할 list
5
+*/
6
+
7
+type NameList struct {
8
+	head *NameNode
9
+	tail *NameNode
10
+	size int
11
+}
12
+
13
+type NameNode struct {
14
+	name []int64 // Encrypt된 name
15
+	next *NameNode
16
+
17
+	list List
18
+}
19
+
20
+type List struct {
21
+	head *Node
22
+	tail *Node
23
+	size int
24
+}
25
+
26
+type Node struct {
27
+	val  []int64 // Encrypt된 value
28
+	next *Node
29
+
30
+	// single //
31
+	single2sub_s  []int // (val < x) sub#
32
+	single2sub_es []int // (val <= x) sub#
33
+	single2sub_b  []int // (val > x) sub#
34
+	single2sub_eb []int // (val >= x) sub#
35
+	single2sub_e  []int // (val == x) sub#
36
+
37
+	// range //
38
+	range2sub_s  []int // (val < x and ...) sub#
39
+	range2sub_es []int // (val <= x and ...) sub#
40
+	range2sub_b  []int // (val > x and ...) sub#
41
+	range2sub_eb []int // (val >= x and ...) sub#
42
+}
43
+
44
+// ### To delete slice Array
45
+func remove(s []int, i int) []int {
46
+	s[i] = s[len(s)-1]
47
+	return s[:len(s)-1]
48
+}

+ 21
- 0
matching.go Datei anzeigen

@@ -0,0 +1,21 @@
1
+package modules
2
+
3
+import (
4
+	_ "errors"
5
+	_ "fmt"
6
+)
7
+
8
+type match_manager struct {
9
+}
10
+
11
+func (match_mng *match_manager) matching(queue *MsgQueue) error {
12
+	msg := queue.pop(true)
13
+
14
+	//Implement here ~~
15
+	subscription := msg.(*PublishMsg).subscription
16
+	content := msg.(*PublishMsg).content
17
+
18
+	println(subscription, content)
19
+
20
+	return nil
21
+}

+ 119
- 0
subscription.go Datei anzeigen

@@ -0,0 +1,119 @@
1
+package modules
2
+
3
+import (
4
+	"errors"
5
+	"fmt"
6
+)
7
+
8
+type sub_manager struct {
9
+
10
+	// NameList의 노드들이 각각의 list를 갖음
11
+	list NameList
12
+
13
+	/* sub# 관리 */
14
+	count_sub  int             // Subscription #
15
+	emptylist  []int           // To administrate sub #
16
+	num2sub    map[int]MsgUnit // num2sub[sub#] = msg
17
+	sub2num    map[MsgUnit]int // delete시에 관리를 위해
18
+	israngesub map[int]bool    // delete시에 관리를 위해
19
+}
20
+
21
+//	### To Insert sub#
22
+func (manager *sub_manager) add_subscription(msg MsgUnit) error {
23
+
24
+	name := msg.(*SubscriptionMsg).subscription
25
+	value := msg.(*SubscriptionMsg).value
26
+	subnumber := 0
27
+
28
+	fmt.Println("name = ", name, " value = ", value) // for debuging
29
+
30
+	// * 1. 들어온 Msg -> sub#, sub# -> Msg로 매핑
31
+	if len(manager.emptylist) == 0 {
32
+		manager.num2sub[manager.count_sub] = msg
33
+		manager.sub2num[msg] = manager.count_sub
34
+		subnumber = manager.count_sub
35
+		manager.count_sub++
36
+	} else {
37
+		subidx := manager.emptylist[len(manager.emptylist)-1]
38
+		manager.emptylist = manager.emptylist[:len(manager.emptylist)-1]
39
+		manager.num2sub[subidx] = msg
40
+		manager.sub2num[msg] = subidx
41
+		subnumber = subidx
42
+	}
43
+
44
+	// * 2. value가 연산식인지 확인
45
+	isformula := check_Subtype(value)
46
+
47
+	// * 3. Sub 추가
48
+	nameidx := manager.list.head
49
+	findOk := false
50
+
51
+	// * namelist에서 name찾고, 없으면 추가
52
+	for nameidx != nil {
53
+		// *  compare함수 구현되기 전 임시로 끼어넣은 것 (이 부분은 secure.go 완성되면 다시 확인)
54
+		if compare(nameidx.name, name) == 1 {
55
+			findOk = true
56
+			break
57
+		}
58
+		nameidx = nameidx.next
59
+	}
60
+
61
+	newNode := &NameNode{name, nil, List{}}
62
+	if findOk == false {
63
+		manager.list.tail.next = newNode
64
+		manager.list.tail = newNode
65
+		manager.list.size++
66
+		nameidx = manager.list.tail
67
+	}
68
+
69
+	// * list[name]에 value추가
70
+	if isformula == false { // 단순 매칭이라면
71
+		valptr := nameidx.list.head
72
+
73
+		for valptr != nil {
74
+			// * 이 부분도 compare함수 구현하면 다시봐야함
75
+			if compare(valptr.val, conv(value)) == 1{ // value와 같은 val을 갖는 노드가 존재한다면
76
+				valptr.single2sub_e = append(valptr.single2sub_e, subnumber)
77
+				return nil // 제대로 insert된 것
78
+			}
79
+			valptr=valptr.next
80
+		}
81
+		
82
+		// 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
+	}
91
+
92
+	return nil
93
+}
94
+
95
+
96
+// * string형태로 암호화 되어있는 value -> int64[]로 변환(임시) 
97
+func conv(val string) []int64{
98
+	var ret := [] int64
99
+	return ret
100
+}
101
+
102
+// * 암호화된 두 value 비교함수 (임시)
103
+func compare(v1 []int64, v2 []int64) int {
104
+	return 1
105
+}
106
+
107
+//	* ### To delete sub#
108
+func (manager *sub_manager) delete(subnumber int) error {
109
+	s := errors.New("!23")
110
+	return s
111
+}
112
+
113
+func check_Subtype(value []string) bool {
114
+	if len(value) == 1 {
115
+		return false
116
+	} else {
117
+		return true
118
+	}
119
+}

Laden…
Abbrechen
Speichern