-
Notifications
You must be signed in to change notification settings - Fork 5
/
mapstringBool.go
63 lines (54 loc) · 1.08 KB
/
mapstringBool.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
package udwMap
import (
"github.com/tachyon-protocol/udw/udwSort"
)
func MapStringBoolToSortedSlice(m map[string]bool) []string {
output := make([]string, len(m))
i := 0
for s := range m {
output[i] = s
i++
}
udwSort.SortString(output)
return output
}
func StringListToMapStringBool(sList []string) map[string]bool {
m := make(map[string]bool, len(sList))
for _, s := range sList {
m[s] = true
}
return m
}
func StringListNoRepeat(sList []string) []string {
if len(sList) <= 1 {
return sList
}
if len(sList) <= 20 {
output := make([]string, 1, len(sList))
output[0] = sList[0]
for i := 1; i < len(sList); i++ {
hasFound := false
for j := 0; j < i; j++ {
if sList[i] == sList[j] {
hasFound = true
break
}
}
if hasFound == false {
output = append(output, sList[i])
}
}
return output
} else {
m := make(map[string]struct{}, len(sList))
output := make([]string, 0, len(sList))
for _, s := range sList {
_, ok := m[s]
if ok == false {
output = append(output, s)
m[s] = struct{}{}
}
}
return output
}
}