lib.lists.unique: Switch from recursive function to using a fold
This improves performance by ~30-40% for smaller test cases and makes larger cases where my laptop would OOM pass in seconds.
This commit is contained in:
parent
8d8532cd32
commit
85605c8a29
@ -640,13 +640,7 @@ rec {
|
|||||||
unique [ 3 2 3 4 ]
|
unique [ 3 2 3 4 ]
|
||||||
=> [ 3 2 4 ]
|
=> [ 3 2 4 ]
|
||||||
*/
|
*/
|
||||||
unique = list:
|
unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) [];
|
||||||
if list == [] then
|
|
||||||
[]
|
|
||||||
else
|
|
||||||
let
|
|
||||||
x = head list;
|
|
||||||
in [x] ++ unique (remove x list);
|
|
||||||
|
|
||||||
/* Intersects list 'e' and another list. O(nm) complexity.
|
/* Intersects list 'e' and another list. O(nm) complexity.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user