m_sort Module

module~~m_sort~~UsesGraph module~m_sort m_sort module~variablekind variableKind module~variablekind->module~m_sort iso_fortran_env iso_fortran_env iso_fortran_env->module~variablekind
Help

Module containing in-place and indirect routines to sort an array of numbers.

Uses an introspective sort on a set of number. See this http://www.geeksforgeeks.org/know-your-sorting-algorithm-set-2-introsort-cs-sorting-weapon/ for more information

To begin, a quicksort with a median of three pivot is used until the size of the array is less than 16. At this point, an insertion sort is used to reduce cache overhead and tail recursion. Unfortunately, a quicksort is not ideal for sorted/almost sorted arrays or arrays with duplicate values. Therefore if the number of iterations exceededs a threshold, a heapsort is used instead. This provides a robust sorting algorithm that is still very fast for almost sorted arrays.

In this implementation, the quicksort and heapsort are unstable sorts. A stable merge sort is therefore provided as an alternative but it has an order(N) memory overhead.

Often, the numbers wish to be maintained in their given order, so with an O(N) memory overhead we can sort an integer array instead by calling argsort()

See sort and argSort for more information.

Used By

module~~m_sort~~UsedByGraph module~m_sort m_sort module~idynamicarray_class iDynamicArray_Class module~m_sort->module~idynamicarray_class program~scaletest_coretran scaleTest_coretran module~m_sort->program~scaletest_coretran module~iddynamicarray_class idDynamicArray_Class module~m_sort->module~iddynamicarray_class module~m_tests m_tests module~m_sort->module~m_tests module~ddynamicarray_class dDynamicArray_Class module~m_sort->module~ddynamicarray_class module~rdynamicarray_class rDynamicArray_Class module~m_sort->module~rdynamicarray_class module~m_maths m_maths module~m_sort->module~m_maths module~idynamicarray_class->module~m_tests module~m_kdtree m_KdTree module~idynamicarray_class->module~m_kdtree module~dargdynamicarray_class dArgDynamicArray_Class module~idynamicarray_class->module~dargdynamicarray_class module~iargdynamicarray_class iArgDynamicArray_Class module~idynamicarray_class->module~iargdynamicarray_class module~rargdynamicarray_class rArgDynamicArray_Class module~idynamicarray_class->module~rargdynamicarray_class module~idargdynamicarray_class idArgDynamicArray_Class module~idynamicarray_class->module~idargdynamicarray_class module~iddynamicarray_class->module~m_tests module~iddynamicarray_class->module~idargdynamicarray_class program~test_coretran test_coretran module~m_tests->program~test_coretran module~ddynamicarray_class->module~m_tests module~ddynamicarray_class->module~dargdynamicarray_class module~rdynamicarray_class->module~m_tests module~rdynamicarray_class->module~rargdynamicarray_class module~m_maths->program~scaletest_coretran module~m_maths->module~m_tests module~m_maths->module~m_kdtree module~m_kdtree->program~scaletest_coretran module~m_kdtree->module~m_tests module~dargdynamicarray_class->module~m_tests module~dargdynamicarray_class->module~m_kdtree module~iargdynamicarray_class->module~m_tests module~rargdynamicarray_class->module~m_tests module~idargdynamicarray_class->module~m_tests
Help


Interfaces

public interface sort

Use an in-place introspection sort on an array of numbers

  • public subroutine sort_i1D(this, stable)

    Interfaced with sort

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i32) :: this(:)
    logical, optional :: stable
  • public subroutine sort_id1D(this, stable)

    Interfaced with sort

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i64) :: this(:)
    logical, optional :: stable
  • public subroutine sort_r1D(this, stable)

    Interfaced with sort

    Arguments

    Type IntentOptional AttributesName
    real(kind=r32) :: this(:)
    logical, optional :: stable
  • public subroutine sort_d1D(this, stable)

    Interfaced with sort

    Arguments

    Type IntentOptional AttributesName
    real(kind=r64) :: this(:)
    logical, optional :: stable

public interface argSort

Use an indirect introspection sort on an array of numbers

  • public subroutine argSort_i1D(this, i, stable)

    Interfaced with argSort

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i32) :: this(:)

    1D array

    integer(kind=i32) :: i(:)

    Index to sort

    logical, optional :: stable

    Stable sort?

  • public subroutine argSort_id1D(this, i, stable)

    Interfaced with argSort

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i64) :: this(:)

    1D array

    integer(kind=i32) :: i(:)

    Index to sort

    logical, optional :: stable

    Stable sort?

  • public subroutine argSort_r1D(this, i, stable)

    Interfaced with argSort

    Arguments

    Type IntentOptional AttributesName
    real(kind=r32) :: this(:)

    1D array

    integer(kind=i32) :: i(:)

    Index to sort

    logical, optional :: stable

    Stable sort?

  • public subroutine argSort_d1D(this, i, stable)

    Interfaced with argSort

    Arguments

    Type IntentOptional AttributesName
    real(kind=r64) :: this(:)

    1D array

    integer(kind=i32) :: i(:)

    Index to sort

    logical, optional :: stable

    Stable sort?

public interface insertionsort

Perform an in-place insertion sort on an array

  • public subroutine insertionsort_r1D(this, iLeft, iRight)

    Interfaced with insertionsort

    Arguments

    Type IntentOptional AttributesName
    real(kind=r32) :: this(:)

    1D array

    integer(kind=i32) :: iLeft

    Left index

    integer(kind=i32) :: iRight

    Right index

  • public subroutine insertionsort_d1D(this, iLeft, iRight)

    Interfaced with insertionsort

    Arguments

    Type IntentOptional AttributesName
    real(kind=r64) :: this(:)

    1D array

    integer(kind=i32) :: iLeft

    Left index

    integer(kind=i32) :: iRight

    Right index

  • public subroutine insertionsort_i1D(this, iLeft, iRight)

    Interfaced with insertionsort

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i32) :: this(:)

    1D array

    integer(kind=i32) :: iLeft

    Left index

    integer(kind=i32) :: iRight

    Right index

  • public subroutine insertionsort_id1D(this, iLeft, iRight)

    Interfaced with insertionsort

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i64) :: this(:)

    1D array

    integer(kind=i32) :: iLeft

    Left index

    integer(kind=i32) :: iRight

    Right index

public interface argInsertionsort

Perform an indirect insertion sort on an array

  • public subroutine argInsertionsort_r1D(this, indx, iLeft, iRight)

    Interfaced with argInsertionsort

    Arguments

    Type IntentOptional AttributesName
    real(kind=r32) :: this(:)

    1D array

    integer(kind=i32) :: indx(:)

    Sort this integer key

    integer(kind=i32) :: iLeft

    Left index

    integer(kind=i32) :: iRight

    Right index

  • public subroutine argInsertionsort_d1D(this, indx, iLeft, iRight)

    Interfaced with argInsertionsort

    Arguments

    Type IntentOptional AttributesName
    real(kind=r64) :: this(:)

    1D array

    integer(kind=i32) :: indx(:)

    Sort this integer key

    integer(kind=i32) :: iLeft

    Left index

    integer(kind=i32) :: iRight

    Right index

  • public subroutine argInsertionsort_i1D(this, indx, iLeft, iRight)

    Interfaced with argInsertionsort

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i32) :: this(:)

    1D array

    integer(kind=i32) :: indx(:)

    Sort this integer key

    integer(kind=i32) :: iLeft

    Left index

    integer(kind=i32) :: iRight

    Right index

  • public subroutine argInsertionsort_id1D(this, indx, iLeft, iRight)

    Interfaced with argInsertionsort

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i64) :: this(:)

    1D array

    integer(kind=i32) :: indx(:)

    Sort this integer key

    integer(kind=i32) :: iLeft

    Left index

    integer(kind=i32) :: iRight

    Right index