How to use an array to solve the following...

Kay C Lan lan.kc.macmail at gmail.com
Tue Feb 21 09:06:04 EST 2012


On Tue, Feb 21, 2012 at 4:29 PM, Glen Bojsza <gbojsza at gmail.com> wrote:

>
> For example a user wants an starting xs value of 10 and an ending xs value
> of 40 I think that if the keys are sequential (the keys being the first
> column - xs) then it would be a fast solution using arrays since you should
> be able to determine the starting line and ending line of the array without
> needing to cycle through every line and then just produce a new array /
> list. Again, is this a good use for an array?
>

Looking at your example more closely it could be possible to achieve some
extremely fast results with arrays. But as always, if speed is really
important to you you'd need to do some comparitive tests. As I think I've
demonstrated it's not too hard to whip up a couple of test script to time
solutions.

Some determining factors.

In a previous post you indicated that there would be 10 ?t columns. When
you are doing your search are you after all data from every column? Then
setting up flat data and doing repeat for each line will probably be the
fastest. Alternatively you could create an array with the xs as the key and
the entire line as the data.

You indicate that your searches would be of sequential lines. If that is
ALWAYS true, then repeat for each line will be very fast, if there is any
possibility that the searches will not be of sequential lines, then some
overhead will be introduced. Even so repeat for each line will still be
fast. Conversely, it would be quite easy to create a list of every xs
values from, in your example 10 to 40 and do a repeat for each to extract
the data from an array. If there was a possibility that you didn't require
the whole line of data, but just an ht or gt value, then this would not
carry any overhead with an array search.

On average you could get quicker results with an array but they are only
small differences, and if your queries are less than 10s of thousands, then
the amounts are so small they are probably unnoticeable.



More information about the use-livecode mailing list