mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-04-28 11:55:51 +00:00
55 lines
936 B
Go
55 lines
936 B
Go
package utils
|
|
|
|
func Contains(slice []string, containsValue string) bool {
|
|
for _, sliceValue := range slice {
|
|
if sliceValue == containsValue {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func Unique(slice []string) []string {
|
|
keys := make(map[string]bool)
|
|
var list []string
|
|
|
|
for _, entry := range slice {
|
|
if _, value := keys[entry]; !value {
|
|
keys[entry] = true
|
|
list = append(list, entry)
|
|
}
|
|
}
|
|
|
|
return list
|
|
}
|
|
|
|
func EqualStringSlices(slice1 []string, slice2 []string) bool {
|
|
if len(slice1) != len(slice2) {
|
|
return false
|
|
}
|
|
|
|
for _, v := range slice1 {
|
|
if !Contains(slice2, v) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// Diff returns the elements in `a` that aren't in `b`.
|
|
func Diff(a, b []string) []string {
|
|
mb := make(map[string]struct{}, len(b))
|
|
for _, x := range b {
|
|
mb[x] = struct{}{}
|
|
}
|
|
var diff []string
|
|
for _, x := range a {
|
|
if _, found := mb[x]; !found {
|
|
diff = append(diff, x)
|
|
}
|
|
}
|
|
return diff
|
|
}
|