Eliminate doubles in a long list field

Dar Scott dsc at swcp.com
Sat Jun 28 11:42:01 EDT 2003


On Saturday, June 28, 2003, at 09:56 AM, Dar Scott wrote:

> function removeDoubles theLines
>   replace LF with "|" & "x" & LF in theLines
>   split theLines using LF and "|"
>   return keys( theLines )
> end removeDoubles

Wondering about the speed of that, I made this reference function:

function removeDoubles theLines
   if theLines is empty then return empty
   sort theLines
   put line 1 of theLines into recentLine
   put recentLine into accumulatedLines
   repeat for each line l in theLines
     if l is not recentLine then
       put LF & l after accumulatedLines
       put l into recentLine
     end if
   end repeat
   return accumulatedLines
end removeDoubles

The set method is almost 3 times as fast as the above function for the 
lists I tried.

Dar
Scott




More information about the use-livecode mailing list