Module osl_sort

module osl_sort

    ! Uses
    use osl_core, wp => osl_wp

    ! Interfaces
    public interface osl_quicksort

    ! Subroutines and functions
    private subroutine osl_quicksort_vwp(v)
    private subroutine osl_quicksort_vi(v)
    private subroutine osl_quicksort_generic(n, compare, swap, ctx)
    public subroutine osl_shellsort(v)

end module osl_sort

Description of Interfaces

osl_quicksort

public interface osl_quicksort
    module procedure osl_quicksort_vwp
    module procedure osl_quicksort_vi
    module procedure osl_quicksort_generic
end interface osl_quicksort

Description of Subroutines and Functions

osl_quicksort_vwp

private subroutine osl_quicksort_vwp(v)
    real (kind=wp), dimension(:), intent(inout) :: v
    ! Calls: osl_swap
end subroutine osl_quicksort_vwp

Sort an array of real numbers in ascending order. This is an implementation of the Quicksort algorithm of C.A.R. Hoare (1961).

References

  • Hoare, C. A. R. (1961). Quicksort: Algorithm 64. Communications of the ACM 4, 321-322.

osl_quicksort_vi

private subroutine osl_quicksort_vi(v)
    integer, dimension(:), intent(inout) :: v
    ! Calls: osl_swap
end subroutine osl_quicksort_vi

Sort an array of integers in ascending order. This is an implementation of the Quicksort algorithm of C.A.R. Hoare (1961).

References

  • Hoare, C. A. R. (1961). Quicksort: Algorithm 64. Communications of the ACM 4, 321-322.

osl_quicksort_generic

private subroutine osl_quicksort_generic(n, compare, swap, ctx)
    integer, intent(in) :: n
    interface compare
        function compare(i, j, ctx)
            integer, intent(in) :: i
            integer, intent(in) :: j
            integer, optional, dimension(:), intent(in) :: ctx
            integer :: compare
        end function compare
    end interface compare
    interface swap
        subroutine swap(i, j, ctx)
            integer, intent(in) :: i
            integer, intent(in) :: j
            integer, optional, dimension(:), intent(in) :: ctx
        end subroutine swap
    end interface swap
    integer, dimension(:), intent(in) :: ctx
    ! Calls: qsort, swap
end subroutine osl_quicksort_generic

Sort a generic collection of N objects using the quicksort algorithm with the generic COMPARE and SWAP routines and the provided context CTX.

osl_shellsort

public subroutine osl_shellsort(v)
    real (kind=wp), dimension(:), intent(inout) :: v
end subroutine osl_shellsort

Sort an array V of real numbers in ascending order using the algorithm of Shell (1959).

References

  • Shell, D. L. (1959). A high-speed sorting procedure. Communications of the ACM 2, 30-32.