-
Notifications
You must be signed in to change notification settings - Fork 10
/
set.go
46 lines (40 loc) · 1.05 KB
/
set.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
package experiments
// Set is a collection of experiments where every experiment is either a member
// or not.
type Set map[Experiment]struct{}
// NewSet constructs a new Set with the given experiments as its initial members.
func NewSet(exps ...Experiment) Set {
ret := make(Set)
for _, exp := range exps {
ret.Add(exp)
}
return ret
}
// SetUnion constructs a new Set containing the members of all of the given
// sets.
func SetUnion(sets ...Set) Set {
ret := make(Set)
for _, set := range sets {
for exp := range set {
ret.Add(exp)
}
}
return ret
}
// Add inserts the given experiment into the set.
//
// If the given experiment is already present then this is a no-op.
func (s Set) Add(exp Experiment) {
s[exp] = struct{}{}
}
// Remove takes the given experiment out of the set.
//
// If the given experiment not already present then this is a no-op.
func (s Set) Remove(exp Experiment) {
delete(s, exp)
}
// Has tests whether the given experiment is in the receiving set.
func (s Set) Has(exp Experiment) bool {
_, ok := s[exp]
return ok
}