| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- package modules
-
- /*
- Sub정보들을 관리할 list
- */
-
- type topicList struct {
- head *topicNode
- tail *topicNode
- size int
- }
-
- type topicNode struct {
- topic []int64 // Encrypt된 topic
- next *topicNode
- prev *topicNode
- list valueList
- }
-
- type valueList struct {
- head *valueNode
- tail *valueNode
- size int
- }
-
- type valueNode struct {
- val []int64 // Encrypt된 value
- next *valueNode
- prev *valueNode
-
- // single //
- single2sub_s []int // (val < x) sub#
- single2sub_es []int // (val <= x) sub#
- single2sub_b []int // (val > x) sub#
- single2sub_eb []int // (val >= x) sub#
- single2sub_e []int // (val == x) sub#
-
- // range //
- range2sub_s []int // (val < x and ...) sub#
- range2sub_es []int // (val <= x and ...) sub#
- range2sub_b []int // (val > x and ...) sub#
- range2sub_eb []int // (val >= x and ...) sub#
- }
-
- // ### To delete slice Array
- func remove(ary []int, i int) []int {
- return append(ary[:i], ary[i+1:]...)
- }
-
- func findSub(ary []int, sub int) int {
- for i := 0; i < len(ary); i++ {
- if ary[i] == sub {
- return i
- }
- }
- return -1
- }
-
- func (l *topicList) addTopicNode(topic []int64){
- newNode := &topicNode{topic, nil, nil, valueList{}}
- if l.head == nil{
- l.head = newNode
- l.tail = l.head
- } else{
- newNode.prev = l.tail
- l.tail.next = newNode
- l.tail = newNode
- }
- l.size++
- }
-
- func (n *valueNode) isEmpty() bool {
- empty := true
- if len(n.single2sub_s) != 0 {
- empty = false
- }
- if len(n.single2sub_es) != 0 {
- empty = false
- }
- if len(n.single2sub_b) != 0 {
- empty = false
- }
- if len(n.single2sub_eb) != 0 {
- empty = false
- }
- if len(n.single2sub_e) != 0 {
- empty = false
- }
- if len(n.range2sub_s) != 0 {
- empty = false
- }
- if len(n.range2sub_es) != 0 {
- empty = false
- }
- if len(n.range2sub_b) != 0 {
- empty = false
- }
- if len(n.range2sub_eb) != 0 {
- empty = false
- }
- return empty
- }
-
- // 노드의 operator리스트에 sub#을 in
- func (l *valueNode) insertSub(op string, sub int, issingle bool) {
- if issingle == true {
- switch op {
- case "<":
- l.single2sub_s = append(l.single2sub_s, sub)
- case "<=":
- l.single2sub_es = append(l.single2sub_es, sub)
- case ">":
- l.single2sub_b = append(l.single2sub_b, sub)
- case ">=":
- l.single2sub_eb = append(l.single2sub_eb, sub)
- case "==":
- l.single2sub_e = append(l.single2sub_e, sub)
- }
- } else {
- switch op {
- case "<":
- l.range2sub_s = append(l.range2sub_s, sub)
- case "<=":
- l.range2sub_es = append(l.range2sub_es, sub)
- case ">":
- l.range2sub_b = append(l.range2sub_b, sub)
- case ">=":
- l.range2sub_eb = append(l.range2sub_eb, sub)
- }
- }
- }
-
- func (l *valueList) addValueNode(value []int64) {
- newValNode := &valueNode{value, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil}
- if l.head == nil{
- l.head = newValNode
- l.tail = l.head
- } else{
- newValNode.prev = l.tail
- l.tail.next = newValNode
- l.tail = newValNode
- }
- l.size++
- }
-
- func (l *topicList) getTopicNodePos(topic []int64) *topicNode {
- topicPtr := l.head
- for topicPtr != nil {
- if len(topicPtr.topic) == 0{
- topicPtr = topicPtr.next
- continue
- }
- // * compare 완성된다면 다시보기
- if l.CompareTopic(topicPtr.topic, topic) == 0 {
- return topicPtr
- }
- topicPtr = topicPtr.next
- }
- return nil
- }
-
- func (l *topicList)CompareTopic(topic1 []int64, topic2 []int64) int {
- // 길이 같은지 체크
- if len(topic1) != len(topic2) {
- return -1
- }
- for i := 0; i < len(topic2); i++ {
- if topic1[i] != topic2[i] {
- return -1
- }
- }
- return 0
- }
-
- func (l *valueList) getValueNodePos(value []int64, isAlpha bool) *valueNode {
- valPtr := l.head
- for valPtr != nil {
- if len(valPtr.val) == 0{
- valPtr = valPtr.next
- continue
- }
- if isAlpha{
- if CompareAlpha(value, valPtr.val) == 0{
- return valPtr
- }
- } else{
- if CompareDigit(value[0], valPtr.val[0]) == 0{
- return valPtr
- }
- }
- valPtr = valPtr.next
- }
- return nil
- }
-
-
- func CompareDigit(value1 int64, value2 int64) int {
- if value1 < value2 {
- return 1
- } else if value1 > value2 {
- return -1
- }
- return 0
- }
-
- func CompareAlpha(value1 []int64, value2 []int64) int {
- // 길이 같은지 체크
- if len(value1) != len(value2) {
- return -1
- }
- for i := 0; i < len(value2); i++ {
- if value1[i] != value2[i] {
- return -1
- }
- }
- return 0
- }
|