-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.go
82 lines (68 loc) · 1.21 KB
/
entry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package pangolin
import (
"encoding/json"
"sort"
"strings"
)
type Entry struct {
KV
Type ValueType
Tags []string
}
type ValueType int
type KV struct {
Key int64
Value interface{}
}
const (
UnknownType ValueType = iota
IntType
FloatType
StringType
TypeCount
)
func (e *Entry) Size() uint64 {
switch e.Type {
case IntType, FloatType:
return 8
case StringType:
return uint64(len(e.Value.(string)) * 8)
default:
data, _ := json.Marshal(e.Value)
return uint64(len(data) * 8)
}
}
func (e *Entry) Index() string {
indexBuilder := &strings.Builder{}
sort.Strings(e.Tags)
for i, tag := range e.Tags {
indexBuilder.WriteString(tag)
if i != len(e.Tags)-1 {
indexBuilder.WriteRune(',')
}
}
return indexBuilder.String()
}
type QueryFilter struct {
Type ValueType
Tags []string
}
func (f *QueryFilter) Index() string {
indexBuilder := &strings.Builder{}
sort.Strings(f.Tags)
for i, tag := range f.Tags {
indexBuilder.WriteString(tag)
if i != len(f.Tags)-1 {
indexBuilder.WriteRune(',')
}
}
return indexBuilder.String()
}
func ContainTags(index string, tags []string) bool {
for _, tag := range tags {
if !strings.Contains(index, tag) {
return false
}
}
return true
}