Filtering Columnar Data
Gregory Lypny
gregory.lypny at videotron.ca
Tue Jul 17 16:26:56 EDT 2007
Hello Josh,
Here's the final version of the function. Thanks to everyone for
their suggestions. I know there are other features and better error-
checking that can be added. Maybe later. It can extract roughly 75
records from 700 in 1 tick on an Intel-based iMac.
Regards,
Gregory
function filteredByColumn theData,theColNum,theSearchString,isWithout
-- This function filters tab-delimited data by column
-- By default the filter extracts lines containing the search
string. Make isWithout = "without" to extract lines without it.
-- Possible mods: options to make "begins with" or "contains"
searches
if theColNum is an integer
then
set the itemDelimiter to tab
if isWithout is empty
then
sort lines of theData by (item theColNum of each is not
theSearchString) -- Brings lines with theSearchString to the top
repeat for each line thisLine in theData
if item theColNum of thisLine is theSearchString
then
put thisLine & return after filteredData
else
exit repeat
end if
end repeat
else
sort lines of theData by (item theColNum of each is
theSearchString) -- Brings lines without theSearchString to the top
repeat for each line thisLine in theData
if item theColNum of thisLine is not theSearchString
then
put thisLine & return after filteredData
else
exit repeat
end if
end repeat
end if
delete the last character of filteredData
return filteredData
else
return "The column number must be an integer."
end if
end filteredByColumn
On Mon, Jul 16, 2007, at 7:49 PM, Josh Mellicker responded:
> On Jul 16, 2007, at 2:04 PM, Gregory Lypny wrote:
>
>> I tested the function below, which is much like Josh's, and it
>> filters more than 300 lines in 1 tick; the same code as a message
>> handler rather than a function takes 5 ticks; and the filter
>> command on the same data takes 39 ticks.
>
>
> Wow, I thought that handler was fast, but never tested/compared it.
>
> I wonder if sorting the lines by columnNum, then exiting on the first
> non-matching line would be faster or slower?
>
More information about the use-livecode
mailing list