From f11e3cfc1d6cfe02fa2478d81f2bf5009d5ba85f Mon Sep 17 00:00:00 2001 From: Patrick Jakubowski Date: Tue, 24 Sep 2024 15:33:52 -0700 Subject: [PATCH] internal/mapset: remove some unused methods on MapSet Signed-off-by: Patrick Jakubowski --- internal/mapset/mapset.go | 24 +++-------------- internal/mapset/mapset_test.go | 49 ---------------------------------- 2 files changed, 4 insertions(+), 69 deletions(-) diff --git a/internal/mapset/mapset.go b/internal/mapset/mapset.go index 879a1b3..31feea6 100644 --- a/internal/mapset/mapset.go +++ b/internal/mapset/mapset.go @@ -32,10 +32,12 @@ func Make[T comparable](args ...int) *MapSet[T] { return &MapSet[T]{m: make(map[T]struct{}, size)} } -// FromSlice creates a MapSet of size len(items) and calls AddSlice(items) on it. +// FromSlice creates a MapSet of size len(items) and calls Add for each of the items to it. func FromSlice[T comparable](items []T) *MapSet[T] { h := Make[T](len(items)) - h.AddSlice(items) + for _, i := range items { + h.Add(i) + } return h } @@ -50,15 +52,6 @@ func (h *MapSet[T]) Add(item T) bool { return !exists } -// AddSlice adds a slice of items to the set, returning true if any new items were added to the set. -func (h *MapSet[T]) AddSlice(items []T) bool { - modified := false - for _, i := range items { - modified = h.Add(i) || modified - } - return modified -} - // Remove an item from the Set. Returns true if the item existed in the set. func (h *MapSet[T]) Remove(item T) bool { _, exists := h.m[item] @@ -66,15 +59,6 @@ func (h *MapSet[T]) Remove(item T) bool { return exists } -// RemoveSlice removes a slice of items from the set, returning true if any items existed in the set. -func (h *MapSet[T]) RemoveSlice(items []T) bool { - modified := false - for _, i := range items { - modified = h.Remove(i) || modified - } - return modified -} - // Contains returns whether the item exists in the set func (h MapSet[T]) Contains(item T) bool { _, exists := h.m[item] diff --git a/internal/mapset/mapset_test.go b/internal/mapset/mapset_test.go index acbe57d..34088db 100644 --- a/internal/mapset/mapset_test.go +++ b/internal/mapset/mapset_test.go @@ -35,34 +35,6 @@ func TestHashSet(t *testing.T) { testutil.Equals(t, s.Add(1), false) }) - t.Run("add slice", func(t *testing.T) { - s := Make[int]() - s.AddSlice([]int{1, 2}) - testutil.Equals(t, s.Contains(1), true) - testutil.Equals(t, s.Contains(2), true) - hashSetMustNotContain(t, s, 3) - }) - - t.Run("add same slice", func(t *testing.T) { - s := Make[int]() - testutil.Equals(t, s.AddSlice([]int{1, 2}), true) - testutil.Equals(t, s.AddSlice([]int{1, 2}), false) - }) - - t.Run("add disjoint slices", func(t *testing.T) { - s := Make[int]() - testutil.Equals(t, s.AddSlice([]int{1, 2}), true) - testutil.Equals(t, s.AddSlice([]int{3, 4}), true) - testutil.Equals(t, s.AddSlice([]int{1, 2, 3, 4}), false) - }) - - t.Run("add overlapping slices", func(t *testing.T) { - s := Make[int]() - testutil.Equals(t, s.AddSlice([]int{1, 2}), true) - testutil.Equals(t, s.AddSlice([]int{2, 3}), true) - testutil.Equals(t, s.AddSlice([]int{1, 3}), false) - }) - t.Run("remove nonexistent", func(t *testing.T) { s := Make[int]() testutil.Equals(t, s.Remove(1), false) @@ -81,27 +53,6 @@ func TestHashSet(t *testing.T) { testutil.FatalIf(t, s.Contains(1), "set unexpectedly contained item") }) - t.Run("remove slice", func(t *testing.T) { - s := Make[int]() - s.AddSlice([]int{1, 2, 3}) - s.RemoveSlice([]int{1, 2}) - hashSetMustNotContain(t, s, 1) - hashSetMustNotContain(t, s, 2) - testutil.Equals(t, s.Contains(3), true) - }) - - t.Run("remove non-existent slice", func(t *testing.T) { - s := Make[int]() - testutil.Equals(t, s.RemoveSlice([]int{1, 2}), false) - }) - - t.Run("remove overlapping slice", func(t *testing.T) { - s := Make[int]() - s.Add(1) - testutil.Equals(t, s.RemoveSlice([]int{1, 2}), true) - testutil.Equals(t, s.RemoveSlice([]int{1, 2}), false) - }) - t.Run("new from slice", func(t *testing.T) { s := FromSlice([]int{1, 2, 2, 3}) testutil.Equals(t, s.Len(), 3)