[script optimization challenge] Multi dimensional array filtering

Malte Brill revolution at derbrill.de
Wed Aug 5 09:16:19 EDT 2009


Hey all,

I just try to implement a life search on a datagrid. I was doing this  
with the dgtext property. However this turns out to be too slow on  
elder machines if there are many records (30k +) Now I am trying to  
instead of setting the dgtext, to work with the dgdata. This could  
speed up the whole process quite a lot, as the data would not need to  
be turned into an array again by the data grid. Problem: arrays can  
not be filtered. So what I would like to do is find the quickest  
script that simulates array filtering in n dimensions if at any rate  
possible. My clumsy first try looks like this. This only "filters" the  
second level yet, so turning this into a function for n-levels deep  
would be ideal. :)

on mouseUp
    local testarray,tprocess,test
    repeat with i=1 to 30000
       put any item of "meier,müller,john,doe" into testarray[i]["name"]
    end repeat
    answer the number of lines of the keys of testarray
    put the millisecs into test
    put the keys of testarray into tprocess
    repeat for each line theLine in tprocess
       if testarray[theline]["name"]="john" then
          delete variable testarray[theline]
       end if
    end repeat
    answer the number of lines of the keys of testarray&cr&the  
millisecs-test
end mouseUp

This runs in 31 ms on my machine (Intel MacBook first gen, 2.16 GHz).  
I would like to have this quicker if possible. Also I´d like the  
runtime on your machines, especially Macs pre Intel era.

Any thoughts highly appreciated.

All the best,

Malte


More information about the use-livecode mailing list