Algorithm time...

Dick Kriesel dick.kriesel at mail.com
Tue Dec 11 20:44:01 EST 2012


On Dec 9, 2012, at 4:31 PM, Glen Bojsza wrote:

> That's it!!
> 
> 500,000 points in 419 milliseconds.
> 
> This scales perfectly for what I need.
> 
> thanks Dick.
> 

You're welcome, Glen.  So now I've tried optimizing for speed and legibility.  Would you check the timing for your data, please, and report again?
Invoke it like this:
    digest tLines, tGroupSize, tResult

Any questions?

-- Dick

<postScript>
command digest @pLines, pGroupSize, @rResult
   local tLineNumber, tArray, tMin, tMax
   repeat for each line tLine in pLines
      -- note:  create tArray[ <item 2> ] = <item 1 for the first occurrence of item 2 in the group>
      if item 2 of tLine is not among the keys of tArray then
         put item 1 of tLine into tArray[ item 2 of tLine ]
      end if
      add 1 to tLineNumber
      if tLineNumber is pGroupSize then
         put item 1 of the extents of tArray into tMin
         put item 2 of the extents of tArray into tMax
         put tArray[ tMin ] & tab & tMin & cr & tArray[ tMax ] & tab & tMax & cr after rResult
         put empty into tArray
         put 0 into tLineNumber
      end if
   end repeat
end digest
</postScript>



More information about the use-livecode mailing list