public interface inssor
NAME
sort_special(3f) - [M_orderpack:SORT] Sorts array into ascending order
(Insertion sort, generally for small or nearly sorted
arrays)
SYNOPSIS
Subroutine Sort_Special (INOUTVALS)
${TYPE} (kind=${KIND}), Intent (InOut) :: INOUTVALS(:)
Where ${TYPE}(kind=${KIND}) may be
o Real(kind=real32)
o Real(kind=real64)
o Integer(kind=int32)
o Character(kind=selected_char_kind("DEFAULT"),len=*)
DESCRIPTION
Sorts INOUTVALS() into ascending order (Insertion sort).
If certain requirements are met and performance is important this
procedure can be far faster, but SORT(3f) and ranking routines
RANK(3f) and RANK_BASIC(3f) are recommended for the general case.
This subroutine uses an Insertion sort. It does not use any work array
and is faster when INOUTVALS() is of very small size (< 20), or already
almost sorted; but worst case behavior can be triggered by commonly
encountered data order (e.g. initially inverse sorted). Therefore,
in many cases the Quick-sort or Merge-sort method is faster.
OPTIONS
EXAMPLES
Sample program:
program demo_sort_special
! sort an array using insertion sort
use,intrinsic :: iso_fortran_env, only : int32, real32, real64
use M_orderpack, only : sort_special
implicit none
! an insertion sort is very efficient for very small arrays
! but generally slower than methods like quick-sort and merge-sort.
integer,parameter :: isz=2000
real(kind=real64) :: dd(isz), hi, low
! make an array of random values
call random_seed()
call random_number(dd)
dd=dd*1000000.0-500000.0
low= minval(dd)
hi = maxval(dd)
! sort the data
call sort_special(dd)
! cursory checks
if(any(dd(1:isz-1) .gt. dd(2:isz)))stop 'ERROR: array not sorted'
write(*,*)'check min:',dd(1).eq.low
write(*,*)'check max:',dd(isz).eq.hi
write(*,*)'PASSED: random array is now sorted'
end program demo_sort_special
Results:
check min: T
check max: T
PASSED: random array is now sorted
AUTHOR
Michel Olagnon - Apr. 2000
MAINTAINER
LICENSE
Module Procedures
private subroutine real64_inssor(INOUTVALS)
Arguments
Type |
Intent | Optional | Attributes |
|
Name |
|
real(kind=real64),
|
intent(inout), |
|
Dimension (:)
|
:: |
INOUTVALS |
|
private subroutine real32_inssor(INOUTVALS)
Arguments
Type |
Intent | Optional | Attributes |
|
Name |
|
real(kind=real32),
|
intent(inout), |
|
Dimension (:)
|
:: |
INOUTVALS |
|
private subroutine int32_inssor(INOUTVALS)
Arguments
Type |
Intent | Optional | Attributes |
|
Name |
|
integer(kind=int32),
|
intent(inout), |
|
Dimension (:)
|
:: |
INOUTVALS |
|
private subroutine f_char_inssor(INOUTVALS)
Arguments
Type |
Intent | Optional | Attributes |
|
Name |
|
character(kind=f_char, len=*),
|
intent(inout), |
|
Dimension (:)
|
:: |
INOUTVALS |
|