Skip to content

Commit 28b0def

Browse files
authored
Add a helper set library to facilitate implementation of the new health check procedure (#252)
This is the first PR in a series of [stacked PRs](https://www.stacking.dev/), aimed ultimately at implementing the features described in #181 and #207. The next PR in the stack can be found at #259.
1 parent bb350c3 commit 28b0def

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pkg/set/set.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package set
2+
3+
type Set[E comparable] map[E]struct{}
4+
5+
func New[E comparable](vals ...E) Set[E] {
6+
s := Set[E]{}
7+
for _, v := range vals {
8+
s[v] = struct{}{}
9+
}
10+
return s
11+
}
12+
13+
func (s Set[E]) Add(vals ...E) {
14+
for _, v := range vals {
15+
s[v] = struct{}{}
16+
}
17+
}
18+
19+
func (s Set[E]) Equals(other Set[E]) bool {
20+
if len(s) != len(other) {
21+
return false
22+
}
23+
for k := range s {
24+
if _, has := other[k]; !has {
25+
return false
26+
}
27+
}
28+
return true
29+
}

0 commit comments

Comments
 (0)