sort_nth_index Interface

interface
public module subroutine sort_nth_index(keys, n, nth, idx)

Arguments

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

the keys, in precedence order.

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

rows.

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

1-based rank wanted.

integer(kind=int64), intent(out) :: idx

1-based row index at that rank.

Description

The row a full sort would place at 1-based rank nth, by quickselect.

Deterministic because the comparator is a total order: there is exactly one row at that rank, so this and a full sort cannot disagree. idx is 0 for an out-of-range rank, which every caller has already rejected.