Fixed-Length Array Sorting
Andrea Fontana via Digitalmars-d
digitalmars-d at puremagic.com
Mon Apr 4 07:20:30 PDT 2016
On Monday, 4 April 2016 at 09:36:19 UTC, Nordlöw wrote:
> I have some C++ that does optimal sorting of 3 and 4 elements at
>
> https://github.com/nordlow/justcxx/blob/master/sortn.hpp
>
> Would anybody be interesting in getting this integrated into
>
> std.algorithm.sorting
>
> ?
But it sorts array only in a predefined way. You can't define a
sort functions.
If we need to sort bytes in an ascending/descending order I think
we should consider something like this too (it works well with
large arrays, of course):
// Sort bytes array
auto byteSort(in ubyte[] src)
{
size_t[256] buckets;
src.each!(x => buckets[x]++);
return buckets[].enumerate.map!(x =>
x.index.repeat(x.value)).join;
}
More information about the Digitalmars-d
mailing list