From 28b0defd3224e9d7b6267569cb1e57a3af853fba Mon Sep 17 00:00:00 2001 From: Timofei Larkin Date: Thu, 15 Aug 2024 13:30:45 +0400 Subject: [PATCH] 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. --- pkg/set/set.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 pkg/set/set.go 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 +}