make EqualStringSlice to generic EqualSliceValues (#2179)

just a fly-by refactoring
This commit is contained in:
6543
2023-08-09 09:00:12 +02:00
committed by GitHub
parent b7af77685e
commit ada3659eb7
7 changed files with 60 additions and 57 deletions

View File

@@ -34,29 +34,3 @@ func DedupStrings(src []string) []string {
return dst
}
// EqualStringSlice compare two string slices if they have equal values independent of how they are sorted
func EqualStringSlice(l1, l2 []string) bool {
if len(l1) != len(l2) {
return false
}
m1 := sliceToCountMap(l1)
m2 := sliceToCountMap(l2)
for k, v := range m1 {
if m2[k] != v {
return false
}
}
return true
}
func sliceToCountMap(list []string) map[string]int {
m := make(map[string]int)
for i := range list {
m[list[i]]++
}
return m
}