mergeSortTemp

Merge sort, allowing caller to provide a temp variable. This allows recycling instead of repeated allocations. If D is data, T is temp, and U is a ulong* for calculating bubble sort distance, this can be called as mergeSortTemp(D, D, D, T, T, T, U) or mergeSortTemp(D, D, D, T, T, T) where each D has a T of corresponding type.

T[0]
mergeSortTemp
(
alias compFun = "a < b"
T...
)
()
if (
T.length != 0
)
in { assert (data.length > 0); size_t len = data[0].length; foreach (array; data[1 .. $]) { static if (!is(typeof(array) == ulong*)) assert (array.length == len); } }

Examples

1 int[] foo = [3, 1, 2, 4, 5].dup;
2 int[] temp = new uint[5];
3 mergeSortTemp!("a < b")(foo, temp);
4 assert(foo == [1, 2, 3, 4, 5]); // The contents of temp will be undefined.
5 foo = [3, 1, 2, 4, 5].dup;
6 real bar = [3.14L, 15.9, 26.5, 35.8, 97.9];
7 real temp2 = new real[5];
8 mergeSortTemp(foo, bar, temp, temp2);
9 assert(foo == [1, 2, 3, 4, 5]);
10 assert(bar == [15.9L, 26.5, 3.14, 35.8, 97.9]);
11 // The contents of both temp and temp2 will be undefined.

Meta