From d98da38562ec79360b58eed87eced3a506f1ff6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20H=C3=B6gberg?= Date: Mon, 15 Oct 2018 18:17:12 +0200 Subject: Optimize operator '--' and yield on large inputs The removal set now uses a red-black tree instead of an array on large inputs, decreasing runtime complexity from `n*n` to `n*log(n)`. It will also exit early when there are no more items left in the removal set, drastically improving performance and memory use when the items to be removed are present near the head of the list. This got a lot more complicated than before as the overhead of always using a red-black tree was unacceptable when either of the inputs were small, but this compromise has okay-to-decent performance regardless of input size. Co-authored-by: Dmytro Lytovchenko --- lib/stdlib/doc/src/lists.xml | 6 ------ 1 file changed, 6 deletions(-) (limited to 'lib/stdlib/doc') diff --git a/lib/stdlib/doc/src/lists.xml b/lib/stdlib/doc/src/lists.xml index 89ba5238b5..4a4c170bba 100644 --- a/lib/stdlib/doc/src/lists.xml +++ b/lib/stdlib/doc/src/lists.xml @@ -708,12 +708,6 @@ splitwith(Pred, List) -> > lists:subtract("123212", "212"). "312".

lists:subtract(A, B) is equivalent to A -- B.

-

The complexity of lists:subtract(A, B) is proportional - to length(A)*length(B), meaning that it will be very slow if - both A and B are long lists. - (Using ordered lists and - ordsets:subtract/2 - is a much better choice if both lists are long.)

-- cgit v1.2.3