Skip to content

Commit

Permalink
Add a helper set library to facilitate implementation of the new heal…
Browse files Browse the repository at this point in the history
…th 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.
  • Loading branch information
lllamnyp authored Aug 15, 2024
1 parent bb350c3 commit 28b0def
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 28b0def

Please sign in to comment.