-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathset.go
More file actions
48 lines (38 loc) · 723 Bytes
/
set.go
File metadata and controls
48 lines (38 loc) · 723 Bytes
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
package main
func newSet() set {
return make(set)
}
type set map[interface{}]struct{}
func (set *set) Add(i interface{}) bool {
_, found := (*set)[i]
(*set)[i] = struct{}{}
return !found
}
func (set *set) Contains(i ...interface{}) bool {
for _, val := range i {
if _, ok := (*set)[val]; !ok {
return false
}
}
return true
}
func (set *set) Iter() <-chan interface{} {
ch := make(chan interface{})
go func() {
for elem := range *set {
ch <- elem
}
close(ch)
}()
return ch
}
func (set *set) Size() int {
return len(*set)
}
func (set *set) ToSliceString() []string {
keys := make([]string, 0, set.Size())
for elem := range *set {
keys = append(keys, elem.(string))
}
return keys
}