[Sc-devel] [approve] Optimising median calc

Dan Stowell danstowell at gmail.com
Tue Oct 16 14:01:18 PDT 2007


Thanks for the feedback James.

I've committed this now (SVN 6395).

Dan


2007/10/14, James Harkins <jamshark70 at gmail.com>:
>
> No objection here.
>
> I wonder if you could squeeze out a bit more performance by copying the
> array only once, on the first call but not on successive recursions. E.g.,
>
> median { |function|
>  ^this.copy.hoareMedian(function)
> }
>
> hoareMedian { |function|
>  ^if(this.size.even, {
>  [tmparray.hoareFind(this.size/ 2 - 1, function),
>  tmparray.hoareFind(this.size/ 2,     function)].mean;
>  }, {
>  tmparray.hoareFind(this.size - 1 / 2, function);
>  });
> }
>
> ?
>
> hjh
>
>
>
> On Oct 14, 2007, at 9:28 AM, Dan Stowell wrote:
>
> Hi -
>
> The method SequenceableCollection:median is "naive" - it sorts all the
> data then returns the middle value. Optimised algorithms don't bother
> to sort every element, and can be much quicker.
>
>
>
>
>
> : H. James Harkins
>
> : jamshark70 at dewdrop-world.net
>
> : http://www.dewdrop-world.net
>
> .::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:
>
>
>
>
> "Come said the Muse,
>
> Sing me a song no poet has yet chanted,
>
> Sing me the universal."  -- Whitman
>
> _______________________________________________
> Sc-devel mailing list
> Sc-devel at create.ucsb.edu
> http://www.create.ucsb.edu/mailman/listinfo/sc-devel
>
>


-- 
http://www.mcld.co.uk


More information about the Sc-devel mailing list