Skip to content

Commit

Permalink
Create a helper set library
Browse files Browse the repository at this point in the history
A set library is useful for several healthcheck operations, such as verifying that several etcd members share a single unique cluster ID.
  • Loading branch information
lllamnyp committed Aug 12, 2024
1 parent bb350c3 commit 83bb4a7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/set/set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package set

type Set[E comparable] map[E]struct{}

func New[E comparable](vals ...E) Set[E] {
s := Set[E]{}
for _, v := range vals {
s[v] = struct{}{}
}
return s
}

func (s Set[E]) Add(vals ...E) {
for _, v := range vals {
s[v] = struct{}{}
}
}

func (s Set[E]) Equals(other Set[E]) bool {
if len(s) != len(other) {
return false
}
for k := range s {
if _, has := other[k]; !has {
return false
}
}
return true
}

0 comments on commit 83bb4a7

Please sign in to comment.