[Sc-devel] [approve] Optimising median calc
James Harkins
jamshark70 at gmail.com
Sun Oct 14 12:03:56 PDT 2007
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.create.ucsb.edu/pipermail/sc-devel/attachments/20071014/b31520d6/attachment.htm
More information about the Sc-devel
mailing list