Sorting an array
Sean Kelly
sean at f4.ca
Tue Feb 6 01:40:40 PST 2007
Oskar Linde wrote:
> Michiel wrote:
>> When I use array.sort, which sorting algorithm does D use? Can the
>> programmer
>> overwrite the implementation of this function?
>
> Just write a library replacement[1]. The only difference is that it will
> have to be called as:
>
> array.sort() instead of array.sort
>
> The advantages are several. It will be faster than the built in sort and
> you will have the possibility of making it support custom ordering
> predicates and more. IMHO, the built in .sort and .reverse properties(?)
> should be removed as identical in syntax and infinitely more flexible
> library implementations are possible.
For what it's worth, Tango contains a sort routine in tango.core.Array.
In the brief testing I've done performs roughly the same as the
built-in sort routine. It's a modified version of quicksort, and I
found that using insertion sort for small ranges (as the built-in sort
does) had no measurable effect on performance so I didn't bother with
the additional complexity.
Sean
More information about the Digitalmars-d
mailing list