keeping keys of an array in the order they came in?

Alex Tweedly alex at tweedly.org
Sat Aug 19 10:57:53 EDT 2017


Hmmm - you haven't mentioned how much data you're working with.
Using lineoffset() to check for duplicated keys will make you 
(relatively) slow on large data sets, since it is O(n**2).

Since you know that item 2 is not empty, you must also know that the 
whole line is not empty :-),
so you can simply check for that.

put empty into Array
repeat for each line tLine in tData
   put item 2 of tLine into tKey
   if tKey = EMPTY then next repeat
   if tArray[tKey] is EMPTY then
      put tLine & CR after tArray[tKey]   -- or would 'into' be even 
faster than 'after' ??
   end if
end repeat

Alex.

On 19/08/2017 15:23, Klaus major-k via use-livecode wrote:
> Little addition, thanks hermann:
>
>> Am 19.08.2017 um 15:44 schrieb Klaus major-k via use-livecode <use-livecode at lists.runrev.com>:
>>
>> Hi Mike,
>>
>> I added a little IF THEN clause to avoid doublettes in the ney key, too,
>> and now it does what I need, thanks again!
>>
>>> Am 19.08.2017 um 15:12 schrieb Klaus major-k via use-livecode <use-livecode at lists.runrev.com>:
>>>> put empty into tArray
> ## To avoid surpises with LINEOFFSET:
> set the wholematches to TRUE
>
>>>> repeat for each line tLine in tData
>>>> put item 2 of tLine into tKey
>>>> if tKey = EMPTY then next repeat
>>>> put tLine & CR after tArray[tKey]
> ## So this will work as exspected:
>> if lineoffset(tKey,tArray["keylist"]) = 0 then
>> put tKey & CR after tArray["keylist"]
>> end if
>>
>>>> ## put tKey & cr after tarray['myKeyList']
>>>> end repeat
> Best
>
> Klaus
>
> --
> Klaus Major
> http://www.major-k.de
> klaus at major-k.de
>
>
> _______________________________________________
> 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