Fastest way to delete non-contiguous lines in list field
Richard Gaskin
ambassador at fourthworld.com
Tue Jul 1 01:55:00 EDT 2003
Jan Schenkel wrote:
>> Hi all,
>>
>> What's the fastest way to delete non-contiguous
>> lines in a list field? These
>> lines would be listed in the "hilitedLines".
...
> Your problem would be that you have to either keep
> track of the lines you have already deleted, or go
> from the bottom to the top to avoid this but then you
> can't use a 'repeat for each' construct, unless...
> Try the following :
>
> put the text of fld "Foobar" into tText
> put the hilitedLines of fld "Foobar" into tLineNumbers
> sort items of tLineNumbers numeric descending
> repeat for each item tLineNumber in tLineNumbers
> delete line tLineNumber of tText
> end repeat
> set the text of field "Foobar" to tText
I think "sort" may be an expensive operation:
on mouseUp
put 10000 into n -- iterations
put fld 1 into tOrigList
put the hilitedLines of fld 1 into tSelLines
--
-- Test 1:
put the millisecs into t
repeat n
--
put tOrigList into tList
sort items of tSelLines numeric descending
repeat for each item tLine in tSelLines
delete line tLine of tList
end repeat
--
end repeat
put the millisecs - t into t1
--
-- Test 2:
put the millisecs into t
repeat n
--
put tOrigList into tList
repeat for each item tLine in tSelLines
put "ARBITRARY_DELETE_FLAG" into line tLine of tList
end repeat
replace "ARBITRARY_DELETE_FLAG"&cr with empty in tList
--
end repeat
put the millisecs - t into t2
--
put t1 && t2 &&round( (t2/t1)*100) &"%"
end mouseUp
I don't know why the latter is as quick as it is, but here it seems about
40% faster than the one relying on "sort".
--
Richard Gaskin
Fourth World Media Corporation
Developer of WebMerge 2.2: Publish any database on any site
___________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
Tel: 323-225-3717 AIM: FourthWorldInc
More information about the use-livecode
mailing list