function for greatest object in list less than or equal to a value

Geoff Canyon gcanyon at gmail.com
Mon Oct 12 19:24:09 EDT 2015


function greatestLessThan pList,V
   sort items of pList descending numeric
   sort items of pList by each >= V
   return item 1 of pList
end greatestLessThan

100,000 items, two sorts, and consistently returns in under 0.075 seconds
on my Mac:

on mouseUp
   repeat 100000
      put random(10000000),"" after L
   end repeat
   put the long seconds into T
   get greatestLessThan(L,5000000)
   put (the long seconds - T) && it into fld 3
end mouseUp

1,000,000 items generally returns in about .95 seconds
10,000,000 items came back in 10.5 seconds, so against my intuition, this
things seems to scale fairly linearly.



More information about the use-livecode mailing list