The generic subroutine implementing the LSD radix sort algorithm to return an input array with its elements sorted in order of (non-)decreasing value. Its use has the syntax:
call radix_sort( array[, work, reverse] )
with the arguments:
array: the rank 1 array to be sorted. It is an intent(inout)
argument of any of the types integer(int8), integer(int16),
integer(int32), integer(int64), real(real32), real(real64).
If both the type of array is real and at least one of the
elements is a NaN, then the ordering of the result is undefined.
Otherwise it is defined to be the original elements in
non-decreasing order. Especially, -0.0 is lesser than 0.0.
work (optional): shall be a rank 1 array of the same type as
array, and shall have at least size(array) elements. It is an
intent(inout) argument to be used as buffer. Its value on return is
undefined. If it is not present, radix_sort will allocate a
buffer for use, and deallocate it before return. If you do several
similar radix_sorts, reusing the work array is a good parctice.
This argument is not present for int8_radix_sort because it use
counting sort, so no buffer is needed.
reverse (optional): shall be a scalar of type default logical. It
is an intent(in) argument. If present with a value of .true. then
array will be sorted in order of non-increasing values in stable
order. Otherwise index will sort array in order of non-decreasing
values in stable order.
...
! Read random data from a file
call read_file( 'dummy_file', array )
! Sort the random data
call radix_sort( array )
...
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private, | parameter | :: | radix_bits | = | 8 | |
| integer(kind=int32), | private, | parameter | :: | radix_bits_i32 | = | 8_int32 | |
| integer(kind=int64), | private, | parameter | :: | radix_bits_i64 | = | 8_int64 | |
| integer, | private, | parameter | :: | radix_mask | = | 255 | |
| integer(kind=int32), | private, | parameter | :: | radix_mask_i32 | = | 255_int32 | |
| integer(kind=int64), | private, | parameter | :: | radix_mask_i64 | = | 255_int64 |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int_index), | intent(in) | :: | N | |||
| integer(kind=int32), | intent(inout), | dimension(N) | :: | arr | ||
| integer(kind=int32), | intent(inout), | dimension(N) | :: | buf |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int_index), | intent(in) | :: | N | |||
| integer(kind=int64), | intent(inout), | dimension(N) | :: | arr | ||
| integer(kind=int64), | intent(inout), | dimension(N) | :: | buffer |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(inout), | dimension(:), target | :: | array | ||
| real(kind=dp), | intent(inout), | optional, | dimension(:), target | :: | work | |
| logical, | intent(in), | optional | :: | reverse |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int32), | intent(inout), | dimension(:) | :: | array | ||
| integer(kind=int32), | intent(inout), | optional, | dimension(:), target | :: | work | |
| logical, | intent(in), | optional | :: | reverse |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int64), | intent(inout), | dimension(:) | :: | array | ||
| integer(kind=int64), | intent(inout), | optional, | dimension(:), target | :: | work | |
| logical, | intent(in), | optional | :: | reverse |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=sp), | intent(inout), | dimension(:), target | :: | array | ||
| real(kind=sp), | intent(inout), | optional, | dimension(:), target | :: | work | |
| logical, | intent(in), | optional | :: | reverse |