searching List of Lists OR binary searches on BIG lists

Hi All,

I ran into a stack overload issue while reading a large text file and found the solution of reading paragraphs of that file to eliminate the issue.

Before, I was holding all that data in one list called theReport which I’d then do binary searches on to find relative data. I can no longer do this since theReport is now a list of lists.

i came up with some code to un-nest the lists but its somewhat slow.

My question is this, is it faster to set up an itterative repeat loop to search for an item in a list of lists or should I continue un-nesting the list to do the binary search.

here is what my code looks like:


set thereport to paragraphs of (read file (ListToRead as text))
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}

repeat with i from 1 to count of thereport
	set item i of thereport to every text item of item i of thereport
end repeat
set AppleScript's text item delimiters to ASTID

set textitems to number of items in thereport


-- this segment of code un-nests the list and puts them back into csv data for the binary search
set csvdata to {}
set counter to 1
repeat textitems times
	set counter2 to 1
	set repitems to number of items in item counter of thereport
	repeat repitems times
		set end of csvdata to item counter2 of item counter of thereport
		set counter2 to counter2 + 1
	end repeat
	set counter to counter + 1
end repeat

thanks for all the help
-Alex

Hello.

It would be interesting to see how you performed you binary search with the original approach of using a single list.

Best Regards

McUsr

Any time I need to speed something up I look into using Script Objects. You can often get amazing speed gains using them. Here’s a post explaining what they are…
http://macscripter.net/viewtopic.php?id=20705

Hi.

It’s difficult to advise on the best way to do a search without knowing what information’s required from the search ” eg. Does an item exist? What line is it in? What other items are associated with it? etc.

With regard to the specific problem of getting a flat list of items from a text where the items are separated from each other either by commas or by line endings, and where there are no complications such as items containing quoted commas or line endings, a fast and simple method would be this:


set thereport to paragraphs of (read file (ListToRead as text))
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
-- Rejoin the lines with commas instead of line endings, then split at every comma in the text.
set csvdata to text items of (thereport as text)
set AppleScript's text item delimiters to ASTID