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 vectorp
that putsv[p]
in sorted order.ssortperm!(ix, v)
– Modify vectorix
so thatv[ix]
is in sorted order.ssortperm!(v)
– Sortv
and return the permutation vectorp
that was used to putv
in sorted order.ssortperm!!(ix, v)
– Sortv
and modify the vectorix
, so that it contains the permutation which was used to putv
in 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
dims
keyword is used? - Include option to use different sorting algorithms?