[erlang-questions] Sets from list then to list?
Hynek Vychodil
vychodil.hynek@REDACTED
Mon Apr 7 11:04:15 CEST 2008
Result = ordsets:to_list(ordsets:from_list([ {A,B} || {_X,_Y,A,_Z,B} <-
MyList]))
Up to some size it should be faster than sets and than lists:sort
Other possible way is:
Result = ordsets:to_list(
lists:foldl(
fun(S, {_X,_Y,A,_Z,B})-> ordsets:add_element(S, {A, B});
(S, _ )-> S
end,
ordsets:new(),
MyList
)
)
Benchmark it for your purpose.
On Mon, Apr 7, 2008 at 10:19 AM, Alexander Lamb
<alexander.lamb@REDACTED> wrote:
> Hello (list:-)
>
> Using list comprehension, I am building a list of tuples that I want
> unique and sorted.
>
> Is this a correct way of doing it:
>
> Result = sets:to_list(sets:from_list([ {A,B} || {_X,_Y,A,_Z,B} <-
> MyList]))
>
> Then sort the Result.
>
> The alternative would be to use one of the lists functions to copy
> elements into a new list and testing first at each insert if the
> element is already present.
>
> What is best?
>
> Thanks,
>
> Alex
> --
> Alexander Lamb
> Founding Associate
> RODANOTECH Sàrl
>
> 4 ch. de la Tour de Champel
> 1206 Geneva
> Switzerland
>
> Tel: 022 347 77 37
> Fax: 022 347 77 38
>
> http://www.rodanotech.ch
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
--
--Hynek (Pichi) Vychodil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080407/32718e16/attachment.htm>
More information about the erlang-questions
mailing list