blob: c8d6cb1a973782ec5fca61289cb16c02a225f18a (
plain)
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
|
package entities
import (
"strings"
)
type stringSet struct {
m map[string]struct{}
}
func NewStringSet(elem ...string) *stringSet {
s := &stringSet{}
s.m = make(map[string]struct{}, len(elem))
for _, e := range elem {
s.Add(e)
}
return s
}
func (s *stringSet) Add(elem string) {
s.m[elem] = struct{}{}
}
func (s *stringSet) Remove(elem string) {
delete(s.m, elem)
}
func (s *stringSet) Contains(elem string) bool {
_, ok := s.m[elem]
return ok
}
func (s *stringSet) Elements() []string {
keys := make([]string, len(s.m))
i := 0
for k := range s.m {
keys[i] = k
i++
}
return keys
}
func (s *stringSet) String() string {
return strings.Join(s.Elements(), ", ")
}
|