mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-19 21:39:26 +00:00
refactor: remove a couple of report set Remove() functions
They were unused and their naming was inconsistent with similar operations (that are called Delete()).
This commit is contained in:
@@ -21,11 +21,6 @@ func (a IDList) Add(ids ...string) IDList {
|
||||
return IDList(StringSet(a).Add(ids...))
|
||||
}
|
||||
|
||||
// Remove is the only correct way to remove IDs from an IDList.
|
||||
func (a IDList) Remove(ids ...string) IDList {
|
||||
return IDList(StringSet(a).Remove(ids...))
|
||||
}
|
||||
|
||||
// Copy returns a copy of the IDList.
|
||||
func (a IDList) Copy() IDList {
|
||||
return IDList(StringSet(a).Copy())
|
||||
|
||||
@@ -67,21 +67,6 @@ func (s StringSet) Add(strs ...string) StringSet {
|
||||
return s
|
||||
}
|
||||
|
||||
// Remove removes the strings from the StringSet. Remove is the only valid way
|
||||
// to shrink a StringSet. Remove returns the StringSet to enable chaining.
|
||||
func (s StringSet) Remove(strs ...string) StringSet {
|
||||
for _, str := range strs {
|
||||
i := sort.Search(len(s), func(i int) bool { return s[i] >= str })
|
||||
if i >= len(s) || s[i] != str {
|
||||
// The list does not have the element.
|
||||
continue
|
||||
}
|
||||
// has the element, remove it.
|
||||
s = append(s[:i], s[i+1:]...)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Merge combines the two StringSets and returns a new result.
|
||||
func (s StringSet) Merge(other StringSet) StringSet {
|
||||
switch {
|
||||
|
||||
@@ -45,27 +45,6 @@ func TestStringSetAdd(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSetRemove(t *testing.T) {
|
||||
for _, testcase := range []struct {
|
||||
input report.StringSet
|
||||
strs []string
|
||||
want report.StringSet
|
||||
}{
|
||||
{input: report.StringSet(nil), strs: []string{}, want: report.StringSet(nil)},
|
||||
{input: report.MakeStringSet(), strs: []string{}, want: report.MakeStringSet()},
|
||||
{input: report.MakeStringSet("a"), strs: []string{}, want: report.MakeStringSet("a")},
|
||||
{input: report.MakeStringSet(), strs: []string{"a"}, want: report.MakeStringSet()},
|
||||
{input: report.MakeStringSet("a"), strs: []string{"a"}, want: report.StringSet{}},
|
||||
{input: report.MakeStringSet("b"), strs: []string{"a", "b"}, want: report.StringSet{}},
|
||||
{input: report.MakeStringSet("a"), strs: []string{"c", "b"}, want: report.MakeStringSet("a")},
|
||||
{input: report.MakeStringSet("a", "c"), strs: []string{"b", "b", "b"}, want: report.MakeStringSet("a", "c")},
|
||||
} {
|
||||
if want, have := testcase.want, testcase.input.Remove(testcase.strs...); !reflect.DeepEqual(want, have) {
|
||||
t.Errorf("%v - %v: want %#v, have %#v", testcase.input, testcase.strs, want, have)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSetMerge(t *testing.T) {
|
||||
for _, testcase := range []struct {
|
||||
input report.StringSet
|
||||
|
||||
Reference in New Issue
Block a user