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 }