Optimize list intersection
This commit is contained in:
parent
cd80733367
commit
6b3d803456
5
util.nix
5
util.nix
@ -20,10 +20,7 @@ let
|
|||||||
[(take cnt l)] ++ chunksOf cnt (drop cnt l)
|
[(take cnt l)] ++ chunksOf cnt (drop cnt l)
|
||||||
else [];
|
else [];
|
||||||
# same as intersectLists but takes an array of lists to intersect instead of just two
|
# same as intersectLists but takes an array of lists to intersect instead of just two
|
||||||
intersectManyLists = l:
|
intersectManyLists = ll: foldr intersectLists (head ll) ll;
|
||||||
if length l == 0 then []
|
|
||||||
else if length l == 1 then head l
|
|
||||||
else intersectLists (head l) (intersectManyLists (tail l));
|
|
||||||
# converts a boolean to a int (c style)
|
# converts a boolean to a int (c style)
|
||||||
boolToInt = b: if b then 1 else 0;
|
boolToInt = b: if b then 1 else 0;
|
||||||
# drops the last element of a list
|
# drops the last element of a list
|
||||||
|
Loading…
x
Reference in New Issue
Block a user