From 768b1ecfb6b0e1dfbf22a47c6c81e0dc63e3c2ef Mon Sep 17 00:00:00 2001 From: "Ian K. Coolidge" Date: Mon, 19 Dec 2022 16:26:59 +0000 Subject: [PATCH] cpuset: hide 'Filter' API FilterNot is only used in this file, and is trivially converted to a 'filter' call site by inverting the predicate. Filter is only used in this file, so don't export it. --- pkg/kubelet/cm/cpuset/cpuset.go | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/pkg/kubelet/cm/cpuset/cpuset.go b/pkg/kubelet/cm/cpuset/cpuset.go index dc047fd42a6..4c25e53bf57 100644 --- a/pkg/kubelet/cm/cpuset/cpuset.go +++ b/pkg/kubelet/cm/cpuset/cpuset.go @@ -95,9 +95,9 @@ func (s CPUSet) Equals(s2 CPUSet) bool { return reflect.DeepEqual(s.elems, s2.elems) } -// Filter returns a new CPU set that contains all of the elements from this +// filter returns a new CPU set that contains all of the elements from this // set that match the supplied predicate, without mutating the source set. -func (s CPUSet) Filter(predicate func(int) bool) CPUSet { +func (s CPUSet) filter(predicate func(int) bool) CPUSet { b := NewBuilder() for cpu := range s.elems { if predicate(cpu) { @@ -107,19 +107,6 @@ func (s CPUSet) Filter(predicate func(int) bool) CPUSet { return b.Result() } -// FilterNot returns a new CPU set that contains all of the elements from this -// set that do not match the supplied predicate, without mutating the source -// set. -func (s CPUSet) FilterNot(predicate func(int) bool) CPUSet { - b := NewBuilder() - for cpu := range s.elems { - if !predicate(cpu) { - b.Add(cpu) - } - } - return b.Result() -} - // IsSubsetOf returns true if the supplied set contains all the elements func (s CPUSet) IsSubsetOf(s2 CPUSet) bool { result := true @@ -152,14 +139,14 @@ func (s CPUSet) Union(s2 ...CPUSet) CPUSet { // that are present in both this set and the supplied set, without mutating // either source set. func (s CPUSet) Intersection(s2 CPUSet) CPUSet { - return s.Filter(func(cpu int) bool { return s2.Contains(cpu) }) + return s.filter(func(cpu int) bool { return s2.Contains(cpu) }) } // Difference returns a new CPU set that contains all of the elements that // are present in this set and not the supplied set, without mutating either // source set. func (s CPUSet) Difference(s2 CPUSet) CPUSet { - return s.FilterNot(func(cpu int) bool { return s2.Contains(cpu) }) + return s.filter(func(cpu int) bool { return !s2.Contains(cpu) }) } // List returns a slice of integers that contains all elements from