-
Notifications
You must be signed in to change notification settings - Fork 29
/
number_list.go
48 lines (40 loc) · 937 Bytes
/
number_list.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
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package values
import (
"github.com/TeaOSLab/EdgeNode/internal/zero"
"github.com/iwind/TeaGo/types"
"strings"
)
type NumberList struct {
ValueMap map[float64]zero.Zero
}
func NewNumberList() *NumberList {
return &NumberList{
ValueMap: map[float64]zero.Zero{},
}
}
func ParseNumberList(v string) *NumberList {
var list = NewNumberList()
if len(v) == 0 {
return list
}
var lines = strings.Split(v, "\n")
for _, line := range lines {
line = strings.TrimSpace(line)
if len(line) == 0 {
continue
}
var values = strings.Split(line, ",")
for _, value := range values {
value = strings.TrimSpace(value)
if len(value) > 0 {
list.ValueMap[types.Float64(value)] = zero.Zero{}
}
}
}
return list
}
func (this *NumberList) Contains(f float64) bool {
_, ok := this.ValueMap[f]
return ok
}