RadixSort module

reorder

procedure · 1 overloadSource

Rearranges a dynamic array into sorted order, using the ranks of the last sort of that array.

A new array is built with the same allocator, the old storage is freed and input points to the new one, so earlier pointers into it are stale. The array must be the one that was sorted: a different count, or ranks that are not valid, fail an assert.

ExampleOpen in playground ↗
values: [..] u64;
array_add(*values, 30, 10, 20);

sorter: RadixSort;
sort(*sorter, values);
reorder(*values, sorter);
assert(values[0] == 10 && values[1] == 20 && values[2] == 30);

free_resources(*sorter);
array_free(values);
reorder :: (input: *[..] $T, radix: RadixSort)

Parameters

input: *[..] $T
radix: RadixSort

See also