Sorting an array

Bill Baxter dnewsgroup at billbaxter.com
Mon Feb 5 16:32:27 PST 2007


Jarrett Billingsley wrote:
> "Michiel" <nomail at hotmail.com> wrote in message 
> news:eq8bim$2gou$1 at digitaldaemon.com...
>> When I use array.sort, which sorting algorithm does D use? Can the 
>> programmer
>> overwrite the implementation of this function?
>>
>> Thanks!
> 
> DMD at least uses quicksort.  You can find the actual source for it in 
> /dmd/src/phobos/internal/qsort2.d.  You can see that it just calls the C 
> stdlib qsort() function.
> 
> If you want to use a different algorithm, you'd have to change this file and 
> recompile phobos.  A daunting task.. 
> 
> 

I thought it used a quicksort with insertion sort for the smallest arrays.
In fact such a beast seems to be in dmd/src/phobos/internal/qsort.d.
Are you sure arrays use the qsort2.d implementation?

--bb



More information about the Digitalmars-d mailing list