5 Comments Already

commenter
Justin Case Said,
July 9th, 2008 @9:09 am  

Using Linq, would this be what you would call too easy?

myListOfStrings.Distinct();

;)

commenter
Aaron Said,
July 9th, 2008 @8:15 pm  

Creative — yet I have my doubts that it would be efficient for a large list.

commenter
OJ Said,
July 18th, 2008 @1:15 am  

The lack of constraints make this problem really simple.

F#:

let strings = [ "put"; "strings"; "here"; ...... ]
let noDups = strings |> Set.of_list |> Set.to_list

Sorted ;)

commenter
Aaron Said,
July 18th, 2008 @7:13 am  

@OJ — I don’t know F# — how does it do it’s dirty work? I’m not sure how efficient it would be for a large list? Most functions are optimized for small to medium list. I probably should have emphasized larger than I had … :) as my intention was that the function needed to be lightning fast…

commenter
OJ Said,
July 23rd, 2008 @7:18 pm  

Aaron,

The Set functionality in F# is really quick. Behind the scenes it uses a tree to filter out duplicates, so for each item it adds/filters it’d cost O(logN)? Converting back to a list is obviously O(n).

For massive lists it wouldn’t be that fantastic, but you’ll find that the implementation is surprisingly quick as F#’s guts have been optimised quite well.

Cheers.

Related Post

Please Leave Your Comments Below

Please Note: All comments are moderated, so it may take some time before your comment appears.