How to get the difference between two lists?
Richard Gaskin
ambassador at fourthworld.com
Mon Apr 4 04:07:15 EDT 2005
Dick Kriesel wrote:
> On 4/3/05 7:49 PM, "Richard Gaskin" <ambassador at fourthworld.com> wrote:
>
>>With 10,000 lines in my main list and 5,000 lines in my exclude list, it
>>takes only 25 milliseconds to use this on my single-processor PBG4 1MHz:
>>
>>function ShortList pList, pExcludelist
>> repeat for each line tLine in pList
>> if tLine is not among the lines of pExcludeList then
>> put tLine & cr after tNulist
>> end if
>> end repeat
>> delete last char of tNuList
>> return tNuList
>>end ShortList
>
>
> Wow, that's fast. So I decided to compare it to an implementation of Dar's
> second suggestion, which I've been using for a long time. The test I tried
> yields times very different from Richard's. Even though my machine is a
> dual 2 GHz G5, function "Shortlist" took almost a hundred times longer than
> Richard reported. I wonder why the times are so different.
>
> But the other function ran almost 70 times faster than function "Shortlist."
Indeed it did. My earlier test was bunk -- can I use jet lag as my
excuse today? :)
Here's the latest test below -- the array version is indeed orders of
magnitude faster.
But one note from Ken raises a question -- Ken wrote:
Unfortunately this is something that will be executed in a
loop several thousand times, so even at 25ms * 2000 that
ends up being 50 seconds, which is way too long.
You've probably already consider this, but is there a way you can reduce
the number of iterations?
on mouseUp
repeat with i = 1 to 10000
put i&cr after tList
end repeat
put xList(tList) into tExcludeList
--
put the millisecs into t
get ShortList1(tList, tExcludeList)
put the millisecs - t into t1
--
put the millisecs into t
get ShortList2(tList,tExcludeList)
put the millisecs - t into t2
--
put t1 && t2
end mouseUp
function ShortList1 pList, pExcludelist
repeat for each line tLine in pList
if tLine is not among the lines of pExcludeList then
put tLine & cr after tNulist
end if
end repeat
delete last char of tNuList
return tNuList
end ShortList1
function ShortList2 pList, pExcludelist
split pList with return and tab
repeat for each line tLine in pExcludelist
delete variable pList[tLine]
end repeat
return the keys of pList
end ShortList2
function xList pList
repeat for each line tLine in pList
if tLine mod 2 = 0 then
put tLine & cr after tNulist
end if
end repeat
delete last char of tNuList
return tNuList
end xList
--
Richard Gaskin
Fourth World Media Corporation
___________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the use-livecode
mailing list