|
3 | 3 |
|
4 | 4 | !! Licensing:
|
5 | 5 | !!
|
6 |
| -!! This file is subjec† both to the Fortran Standard Library license, and |
| 6 | +!! This file is subject both to the Fortran Standard Library license, and |
7 | 7 | !! to additional licensing requirements as it contains translations of
|
8 | 8 | !! other software.
|
9 | 9 | !!
|
|
65 | 65 | module stdlib_sorting
|
66 | 66 | !! This module implements overloaded sorting subroutines named `ORD_SORT`,
|
67 | 67 | !! `SORT_INDEX`, and `SORT`, that each can be used to sort four kinds
|
68 |
| -!! of `INTEGER` arrays and three kinds of `REAL` arrays. By default, sorting |
69 |
| -!! is in order of increasing value, though `SORT_INDEX` has the option of |
70 |
| -!! sorting in order of decresasing value. All the subroutines have worst |
71 |
| -!! case run time performance of `O(N Ln(N))`, but on largely sorted data |
72 |
| -!! `ORD_SORT` and `SORT_INDEX` can have a run time performance of `O(N)`. |
| 68 | +!! of `INTEGER` arrays, three kinds of `REAL` arrays, `character(len=*)` arrays, |
| 69 | +!! and arrays of `type(string_type)`. |
| 70 | +!! ([Specification](../page/specs/stdlib_sorting.html)) |
| 71 | +!! |
| 72 | +!! By default sorting is in order of |
| 73 | +!! increasing value, but there is an option to sort in decreasing order. |
| 74 | +!! All the subroutines have worst case run time performance of `O(N Ln(N))`, |
| 75 | +!! but on largely sorted data `ORD_SORT` and `SORT_INDEX` can have a run time |
| 76 | +!! performance of `O(N)`. |
73 | 77 | !!
|
74 | 78 | !! `ORD_SORT` is a translation of the `"Rust" sort` sorting algorithm in
|
75 | 79 | !! `slice.rs`:
|
@@ -149,10 +153,10 @@ module stdlib_sorting
|
149 | 153 | !! * array: the rank 1 array to be sorted. It is an `intent(inout)`
|
150 | 154 | !! argument of any of the types `integer(int8)`, `integer(int16)`,
|
151 | 155 | !! `integer(int32)`, `integer(int64)`, `real(real32)`, `real(real64)`,
|
152 |
| -!! `real(real128)`, or `character(*)`. If both the type of `array` is |
153 |
| -!! real and at least one of the elements is a `NaN`, then the ordering |
154 |
| -!! of the result is undefined. Otherwise it is defined to be the |
155 |
| -!! original elements in non-decreasing order. |
| 156 | +!! `real(real128)`, `character(*)`, `type(string_type)`. If both the |
| 157 | +!! type of `array` is real and at least one of the elements is a |
| 158 | +!! `NaN`, then the ordering of the result is undefined. Otherwise it |
| 159 | +!! is defined to be the original elements in non-decreasing order. |
156 | 160 | !!
|
157 | 161 | !! * work (optional): shall be a rank 1 array of the same type as
|
158 | 162 | !! `array`, and shall have at least `size(array)/2` elements. It is an
|
@@ -199,9 +203,9 @@ module stdlib_sorting
|
199 | 203 | !! * array: the rank 1 array to be sorted. It is an `intent(inout)`
|
200 | 204 | !! argument of any of the types `integer(int8)`, `integer(int16)`,
|
201 | 205 | !! `integer(int32)`, `integer(int64)`, `real(real32)`, `real(real64)`,
|
202 |
| -!! `real(real128)`, or `character(*)`. If both the type of `array` is |
203 |
| -!! real and at least one of the elements is a `NaN`, then the ordering |
204 |
| -!! of the result is undefined. Otherwise it is defined to be the |
| 206 | +!! `real(real128)`, `character(*)`, `type(string_type)`. If both the type |
| 207 | +!! of `array` is real and at least one of the elements is a `NaN`, then |
| 208 | +!! the ordering of the result is undefined. Otherwise it is defined to be the |
205 | 209 | !! original elements in non-decreasing order.
|
206 | 210 | !! * `reverse` (optional): shall be a scalar of type default logical. It
|
207 | 211 | !! is an `intent(in)` argument. If present with a value of `.true.` then
|
@@ -238,10 +242,10 @@ module stdlib_sorting
|
238 | 242 | !! * array: the rank 1 array to be sorted. It is an `intent(inout)`
|
239 | 243 | !! argument of any of the types `integer(int8)`, `integer(int16)`,
|
240 | 244 | !! `integer(int32)`, `integer(int64)`, `real(real32)`, `real(real64)`,
|
241 |
| -!! `real(real128)`, or `character(*)`. If both the type of `array` is |
242 |
| -!! real and at least one of the elements is a `NaN`, then the ordering |
243 |
| -!! of the `array` and `index` results is undefined. Otherwise it is |
244 |
| -!! defined to be as specified by reverse. |
| 245 | +!! `real(real128)`, `character(*)`, `type(string_type)`. If both the |
| 246 | +!! type of `array` is real and at least one of the elements is a `NaN`, |
| 247 | +!! then the ordering of the `array` and `index` results is undefined. |
| 248 | +!! Otherwise it is defined to be as specified by reverse. |
245 | 249 | !!
|
246 | 250 | !! * index: a rank 1 array of sorting indices. It is an `intent(out)`
|
247 | 251 | !! argument of the type `integer(int_size)`. Its size shall be the
|
@@ -340,7 +344,10 @@ module stdlib_sorting
|
340 | 344 | !! `slice.rs`
|
341 | 345 | !! https://github.com/rust-lang/rust/blob/90eb44a5897c39e3dff9c7e48e3973671dcd9496/src/liballoc/slice.rs#L2159
|
342 | 346 | !! `ORD_SORT` is a hybrid stable comparison algorithm combining `merge sort`,
|
343 |
| -!! and `insertion sort`. It is always at worst O(N Ln(N)) in sorting random |
| 347 | +!! and `insertion sort`. |
| 348 | +!! ([Specification](../page/specs/stdlib_sorting.html#ord_sort-sorts-an-input-array)) |
| 349 | +!! |
| 350 | +!! It is always at worst O(N Ln(N)) in sorting random |
344 | 351 | !! data, having a performance about 25% slower than `SORT` on such
|
345 | 352 | !! data, but has much better performance than `SORT` on partially
|
346 | 353 | !! sorted data, having O(N) performance on uniformly non-increasing or
|
@@ -376,6 +383,7 @@ module stdlib_sorting
|
376 | 383 | !!
|
377 | 384 | !! The generic subroutine interface implementing the `SORT` algorithm, based
|
378 | 385 | !! on the `introsort` of David Musser.
|
| 386 | +!! ([Specification](../page/specs/stdlib_sorting.html#sort-sorts-an-input-array)) |
379 | 387 |
|
380 | 388 | #:for k1, t1 in IRS_KINDS_TYPES
|
381 | 389 | pure module subroutine ${k1}$_sort( array, reverse )
|
@@ -413,7 +421,10 @@ module stdlib_sorting
|
413 | 421 | !! based on the `"Rust" sort` algorithm found in `slice.rs`
|
414 | 422 | !! https://github.com/rust-lang/rust/blob/90eb44a5897c39e3dff9c7e48e3973671dcd9496/src/liballoc/slice.rs#L2159
|
415 | 423 | !! but modified to return an array of indices that would provide a stable
|
416 |
| -!! sort of the rank one `ARRAY` input. The indices by default correspond to a |
| 424 | +!! sort of the rank one `ARRAY` input. |
| 425 | +!! ([Specification](../page/specs/stdlib_sorting.html#sort_index-creates-an-array-of-sorting-indices-for-an-input-array-while-also-sorting-the-array)) |
| 426 | +!! |
| 427 | +!! The indices by default correspond to a |
417 | 428 | !! non-decreasing sort, but if the optional argument `REVERSE` is present
|
418 | 429 | !! with a value of `.TRUE.` the indices correspond to a non-increasing sort.
|
419 | 430 |
|
|
0 commit comments