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

BNig bernd.niggemann at uni-wh.de
Mon Oct 12 19:05:33 EDT 2015


hh wrote
> [@Bernd: here a PONG to your PING.]
> 
> Obviously each list member has to be inspected once for the comparison.
> And each "smaller than"-member has to be inspected once again to find
> the maximum. There is no other way, this is a math fact.
> 
> Here is my solution, that seems to be pretty fast.
> 
> -- v is a real num, L is a list of real comma-delimites nums
> -- if L has NO member < v then return MINVAL (=your setting)
> -- Empty members are treated as 0 (doesn't harm, if all x>0)
> -- Pre-sorting of L gives no advantage.
> 
> function greatestMemberSmallerThan v,L
>    put -10^15 into z[true] --> because max(empty)=0
>    repeat for each item x in L
>       -- if x is empty then next repeat --> here not necessary
>       put comma & x after z[x<v]
>    end repeat
>    return max( z[true] )
> end greatestMemberSmallerThan

Hermann, you know that math is my weak spot (among others) but whatever math
says in my code I don't touch every member of the list, in my case the
sorting has "touched" ever member and I can safely do my "binary search"
type of thing. Missing values are no problem but empty items would.

did you benchmark my snippet and yours say on a list of 100000 items?

Kind regards
Bernd




--
View this message in context: http://runtime-revolution.278305.n4.nabble.com/function-for-greatest-object-in-list-less-than-or-equal-to-a-value-tp4697221p4697311.html
Sent from the Revolution - User mailing list archive at Nabble.com.




More information about the use-livecode mailing list