sort_comparison_permutation Interface

interface
public module subroutine sort_comparison_permutation(keys, n, perm)

Arguments

Type IntentOptional Attributes Name
type(sort_key_buf), intent(in) :: keys(:)

the keys, in precedence order.

integer(kind=int64), intent(in) :: n

rows to order.

integer(kind=int64), intent(inout) :: perm(:)

receives n 1-based row indices.

Description

Fills perm with the 1-based permutation that puts rows 1..n in key order.

The serial half of the pure-Fortran engine (feature_sort.md Stage 2): an INTROSORT -- quicksort with median-of-three pivoting, a depth-limited heapsort fallback and a final insertion pass -- ordering by sort_row_less and nothing else.

It is unstable, and that is why it is correct. sort_row_less ends with a row index tiebreaker, so no two distinct rows compare equal and every correct sorting algorithm produces the SAME permutation -- the stable one. Switching this to a merge sort to "make it stable" would buy a temporary buffer and change no answer.