Skip to content

Commit 1c86812

Browse files
authored
Merge pull request #422 from gareth-nx/master
Minor fixes to sorting documentation
2 parents 4b96cdd + 3df88d3 commit 1c86812

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

doc/specs/stdlib_sorting.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ increasing, or decreasing, value.
211211

212212
##### Syntax
213213

214-
`call [[stdlib_sorting(module):ord_sort(subroutine)]]ord_sort ( array[, work, reverse ] )`
214+
`call [[stdlib_sorting(module):ord_sort(interface)]]( array[, work, reverse ] )`
215215

216216
##### Class
217217

@@ -286,7 +286,7 @@ decreasing, value.
286286

287287
##### Syntax
288288

289-
`call [[stdlib_sorting(module):sort(subroutine)]]sort ( array[, reverse] )`
289+
`call [[stdlib_sorting(module):sort(interface)]]( array[, reverse] )`
290290

291291
##### Class
292292

@@ -349,7 +349,7 @@ sort the input `array` to produce the output `array`.
349349

350350
##### Syntax
351351

352-
`call [[stdlib_sorting(module):sort_index(subroutine)]]sort_index ( array, index[, work, iwork, reverse ] )`
352+
`call [[stdlib_sorting(module):sort_index(interface)]]( array, index[, work, iwork, reverse ] )`
353353

354354
##### Class
355355

src/stdlib_sorting.fypp

+30-19
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
!! Licensing:
55
!!
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
77
!! to additional licensing requirements as it contains translations of
88
!! other software.
99
!!
@@ -65,11 +65,15 @@
6565
module stdlib_sorting
6666
!! This module implements overloaded sorting subroutines named `ORD_SORT`,
6767
!! `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)`.
7377
!!
7478
!! `ORD_SORT` is a translation of the `"Rust" sort` sorting algorithm in
7579
!! `slice.rs`:
@@ -149,10 +153,10 @@ module stdlib_sorting
149153
!! * array: the rank 1 array to be sorted. It is an `intent(inout)`
150154
!! argument of any of the types `integer(int8)`, `integer(int16)`,
151155
!! `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.
156160
!!
157161
!! * work (optional): shall be a rank 1 array of the same type as
158162
!! `array`, and shall have at least `size(array)/2` elements. It is an
@@ -199,9 +203,9 @@ module stdlib_sorting
199203
!! * array: the rank 1 array to be sorted. It is an `intent(inout)`
200204
!! argument of any of the types `integer(int8)`, `integer(int16)`,
201205
!! `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
205209
!! original elements in non-decreasing order.
206210
!! * `reverse` (optional): shall be a scalar of type default logical. It
207211
!! is an `intent(in)` argument. If present with a value of `.true.` then
@@ -238,10 +242,10 @@ module stdlib_sorting
238242
!! * array: the rank 1 array to be sorted. It is an `intent(inout)`
239243
!! argument of any of the types `integer(int8)`, `integer(int16)`,
240244
!! `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.
245249
!!
246250
!! * index: a rank 1 array of sorting indices. It is an `intent(out)`
247251
!! argument of the type `integer(int_size)`. Its size shall be the
@@ -340,7 +344,10 @@ module stdlib_sorting
340344
!! `slice.rs`
341345
!! https://github.com/rust-lang/rust/blob/90eb44a5897c39e3dff9c7e48e3973671dcd9496/src/liballoc/slice.rs#L2159
342346
!! `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
344351
!! data, having a performance about 25% slower than `SORT` on such
345352
!! data, but has much better performance than `SORT` on partially
346353
!! sorted data, having O(N) performance on uniformly non-increasing or
@@ -376,6 +383,7 @@ module stdlib_sorting
376383
!!
377384
!! The generic subroutine interface implementing the `SORT` algorithm, based
378385
!! on the `introsort` of David Musser.
386+
!! ([Specification](../page/specs/stdlib_sorting.html#sort-sorts-an-input-array))
379387

380388
#:for k1, t1 in IRS_KINDS_TYPES
381389
pure module subroutine ${k1}$_sort( array, reverse )
@@ -413,7 +421,10 @@ module stdlib_sorting
413421
!! based on the `"Rust" sort` algorithm found in `slice.rs`
414422
!! https://github.com/rust-lang/rust/blob/90eb44a5897c39e3dff9c7e48e3973671dcd9496/src/liballoc/slice.rs#L2159
415423
!! 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
417428
!! non-decreasing sort, but if the optional argument `REVERSE` is present
418429
!! with a value of `.TRUE.` the indices correspond to a non-increasing sort.
419430

0 commit comments

Comments
 (0)