mirror of
https://github.com/weaveworks/scope.git
synced 2026-02-14 18:09:59 +00:00
Add function to subtract an entry from an IDList
This commit is contained in:
@@ -36,3 +36,8 @@ func (a IDList) Contains(id string) bool {
|
||||
func (a IDList) Intersection(b IDList) IDList {
|
||||
return IDList(StringSet(a).Intersection(StringSet(b)))
|
||||
}
|
||||
|
||||
// Minus returns the set with id removed
|
||||
func (a IDList) Minus(id string) IDList {
|
||||
return IDList(StringSet(a).Minus(id))
|
||||
}
|
||||
|
||||
@@ -50,6 +50,15 @@ func (s StringSet) Intersection(b StringSet) StringSet {
|
||||
return result
|
||||
}
|
||||
|
||||
// Minus returns the set with str removed
|
||||
func (s StringSet) Minus(str string) StringSet {
|
||||
i := sort.Search(len(s), func(i int) bool { return s[i] >= str })
|
||||
if i < len(s) && s[i] == str {
|
||||
return append(s[:i], s[i+1:]...)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Equal returns true if a and b have the same contents
|
||||
func (s StringSet) Equal(b StringSet) bool {
|
||||
if len(s) != len(b) {
|
||||
|
||||
Reference in New Issue
Block a user