hybridSort

Perform either radix or standard sort depending on ElementType of Range.

hybridSort
(
alias less = "a < b"
Range
)
(
Range r
)
if (
isRandomAccessRange!Range
)

Examples

1 import std.meta : AliasSeq;
2 const n = 10_000;
3 foreach (ix, T; AliasSeq!(byte, short))
4 {
5     import std.container : Array;
6     import std.algorithm : isSorted, swap;
7     import nxt.random_ex : randInPlace;
8 
9     auto a = Array!T();
10     a.length = n;
11 
12     randInPlace(a[]);
13 
14     auto b = a.dup;
15 
16     hybridSort(a[]);
17     assert(a[].isSorted);
18 
19     import std.algorithm.sorting : sort;
20     sort(b[]);
21     assert(b[].isSorted);
22 
23     assert(a == b);
24 
25     swap(a, b);
26 }

Meta