Another algo for faster sorting

Andrea Fontana via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 8 00:28:38 PDT 2016


On Thursday, 7 April 2016 at 18:15:32 UTC, tsbockman wrote:
> I don't think that the simple "counting sort" you demonstrated 
> in the other thread is particularly useful to have in Phobos, 
> by itself:
>     - It doesn't scale well at all to higher-entropy element 
> types, like `int` or `string`.

I mean to replace sort() on phobos if T == byte || T == ...

>     - It only works on value types, not reference types.

Ditto

>     - It's so trivial to implement, that anyone who really 
> needs it can write it themselves.

Ok, but it's not a good reason to keep an inefficient sort() on 
phobos. I would use algorithms in phobos without thinking if I 
have to reimplement them or not. If not we should implement

... sort(T)(T[]) if (T == byte) assert(0, "hey this is a bad 
implementation but is trivial to implement the right one"); :)

Moreover: many algorithms are generic in phobos and in D 
ecosystem, and it could happen that byte's sort (or even bool) 
isn't used directly, but instead inside other algorithms. Let's 
say we need to write a burrows-wheeler transform for bzip2 and we 
need to sort byte... Won't you use the default sort function for 
it?

Andrea





More information about the Digitalmars-d mailing list