The SimultaneousSortperm package provides functions that mimic sortperm and sortperm!, but achieve better performance for large input sizes by simultaneously sorting the data and index vector.
First the data is sorted using the unstable Pattern-Defeating-Quicksort algorithm while simultaneously moving the corresponding indices.
In a second pass, all subarrays with equal data elements are sorted according to their indices to ensure stability.
The following functions are exported:
ssortperm(v)– Return a permutation vectorpthat putsv[p]in sorted order.ssortperm!(ix, v)– Modify vectorixso thatv[ix]is in sorted order.ssortperm!(v)– Sortvand return the permutation vectorpthat was used to putvin sorted order.ssortperm!!(ix, v)– Sortvand modify the vectorix, so that it contains the permutation which was used to putvin sorted order.
More benchmark results can be found here.
- Use pattern-defeating-quicksort from SortingAlgorithms when PR is merged.
- Contribute to Base / SortingAlgorithms
- Improve optimization for very small inputs.
- Use allocating optimizations when
dimskeyword is used? - Include option to use different sorting algorithms?