AW: fastes way to search an array?

Tiemo Hollmann TB toolbook at kestner.de
Fri Apr 24 05:08:18 EDT 2015


Hi Mike,
my first description wasn't very exact. Actually these are two different
cases, which occur not together. One time I need a search with "begins" and
another time with "contains".
And I decided to stay with such a standard repeat loop thru the array,
without extracting the keys before or using any extra commands like filter. 
Thanks for caring
Tiemo


-----Ursprüngliche Nachricht-----
Von: use-livecode [mailto:use-livecode-bounces at lists.runrev.com] Im Auftrag
von Mike Bonner
Gesendet: Freitag, 24. April 2015 00:39
An: How to use LiveCode
Betreff: Re: fastes way to search an array?

Did some testing out of curiosity, and WOW this is fast.


repeat for each key tKey in tArray
  if tArray[tKey] begins with tSearchString or \
     tArray[tKey] contains tSearchString then
    put tKey & return after tResults
  end if
end repeat

The only question I have is.. why search for the same thing twice?  If it
"contains" it also "begins with" so its a redundant check.  (making it
faster)  Am I missing something here?

On Thu, Apr 23, 2015 at 4:01 PM, Geoff Canyon <gcanyon at gmail.com> wrote:

> On Wed, Apr 22, 2015 at 6:22 PM, Peter Haworth <pete at lcsql.com> wrote:
>
> > Out of interest, I added a test which used combine and filter.  It 
> > took around 3 times longer than the other two tests.
> >
>
> Yeah, I didn't expect this to be competitive except under specific 
> circumstances -- if the filter command happens to be suited to the 
> (relatively complex) search performed, for example. I didn't see 3x, 
> more like 1.5x to 2x, but still, iterating is generally the way to go.
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your 
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list