[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-dev] sort

while testing my statistics stuff...
it turns out that sort changes the array itself:

a = [3,2,1,4];
// a.sort[2].postln;	// e.g. find second largest item, or
a.median.postln;	// calls sort also..,
a.postln;		// and now, a is [1,2,3,4]!

I find this surprising, and would assume that sort should do .copy first.

also, (on large arrays) quicksort measures faster than mergeSort;
is there some other reason why it should be mergeSort,
or can I change sort to this:

	sort { arg function;
		if (function.isNil) { function = { arg a, b; a <= b }; };

best, adc
Alberto de Campo
Bergstrasse 59/33
A-8020 Graz, Austria
e-mail : decampo@xxxxxx