Add util method HasIntersection(...)
Introduces a util method `HasIntersection(...)`, which returns true if
the two input lists have non-empty intersection.
Test: m nothing --no-skip-soong-tests
Bug: 338660802
Change-Id: I861a60e1973c92a773c127dfc595ad7514d7972f
diff --git a/android/util.go b/android/util.go
index e21e66b..3c0af2f 100644
--- a/android/util.go
+++ b/android/util.go
@@ -201,6 +201,12 @@
return listsDiffer, diff1, diff2
}
+// 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))
+}
+
// Returns true if the given string s is prefixed with any string in the given prefix list.
func HasAnyPrefix(s string, prefixList []string) bool {
for _, prefix := range prefixList {