diff options
Diffstat (limited to 'android/util.go')
-rw-r--r-- | android/util.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/android/util.go b/android/util.go index 30d8ec6b3..8591cc63e 100644 --- a/android/util.go +++ b/android/util.go @@ -213,21 +213,23 @@ func PrettyConcat(list []string, quote bool, lastSep string) string { } // ListSetDifference checks if the two lists contain the same elements. It returns -// a boolean which is true if there is a difference, and then returns lists of elements +// a boolean which is true if there is a difference, and then returns lists of unique elements // that are in l1 but not l2, and l2 but not l1. func ListSetDifference[T comparable](l1, l2 []T) (bool, []T, []T) { listsDiffer := false + l1 = firstUnique(l1) + l2 = firstUnique(l2) diff1 := []T{} diff2 := []T{} m1 := setFromList(l1) m2 := setFromList(l2) - for t := range m1 { + for _, t := range l1 { if _, ok := m2[t]; !ok { diff1 = append(diff1, t) listsDiffer = true } } - for t := range m2 { + for _, t := range l2 { if _, ok := m1[t]; !ok { diff2 = append(diff2, t) listsDiffer = true @@ -238,8 +240,13 @@ func ListSetDifference[T comparable](l1, l2 []T) (bool, []T, []T) { // Returns true if the two lists have common elements. func HasIntersection[T comparable](l1, l2 []T) bool { - _, a, b := ListSetDifference(l1, l2) - return len(a)+len(b) < len(setFromList(l1))+len(setFromList(l2)) + m1 := setFromList(l1) + for _, x := range l2 { + if _, ok := m1[x]; ok { + return true + } + } + return false } // Returns true if the given string s is prefixed with any string in the given prefix list. |