Merge pull request #144072 from polykernel/lib-lists-mutuallyexclusive-optimization

This commit is contained in:
Ben Siraphob 2021-11-02 02:46:27 -05:00 committed by GitHub
commit 481afad265
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -642,7 +642,7 @@ rec {
unique [ 3 2 3 4 ] unique [ 3 2 3 4 ]
=> [ 3 2 4 ] => [ 3 2 4 ]
*/ */
unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) []; unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) [];
/* Intersects list 'e' and another list. O(nm) complexity. /* Intersects list 'e' and another list. O(nm) complexity.
@ -663,9 +663,6 @@ rec {
/* Test if two lists have no common element. /* Test if two lists have no common element.
It should be slightly more efficient than (intersectLists a b == []) It should be slightly more efficient than (intersectLists a b == [])
*/ */
mutuallyExclusive = a: b: mutuallyExclusive = a: b: length a == 0 || !(any (x: elem x a) b);
(builtins.length a) == 0 ||
(!(builtins.elem (builtins.head a) b) &&
mutuallyExclusive (builtins.tail a) b);
} }