diff --git a/pkg/set/set.go b/pkg/set/set.go new file mode 100644 index 00000000..a1b5131c --- /dev/null +++ b/pkg/set/set.go @@ -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 +}