fastes way to search an array?

Richard Gaskin ambassador at fourthworld.com
Wed Apr 22 18:51:14 EDT 2015


Mike Bonner wrote:

> I wonder how easy it would be to add an option to arrayencode.  It already
> flattens an array nicely, but not in a searchable way. It would be cool to
> add an optional argument that still flattens, but doesn't encode.  The code
> to traverse the array is already there, with an option to leave the data
> and keys readable, it would then make an interesting batch of searchable
> text. Just glancing at an encoded array, it looks relatively
> comprehensible.

Relatively.  Lots of binary stuff there, though - it's relatively slow 
for the engine to recompose into an array, and no doubt much slower to 
attempt to do in script.

May not be much of a need, though, since traversing arrays with what we 
have is pretty fast - from my earlier email:

    go url "http://fourthworld.net/lc/array_access_speeds.livecode"


> One issue would be the unordered way arrays are stored. (making
> arrayencoded arrays come out different despite identical data, as per the
> dictionary page)

That's a function of the hashing used for any associative array.  Not 
much can be done about that for strings, though there's been some talk 
of adding numerically indexed arrays for those who need only sequential 
integers as keys and need to maintain order.

But in the meantime the sort command is pretty handy. :)

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com




More information about the use-livecode mailing list