@@ -55,12 +55,12 @@ data:
55
55
56
56
The Fortran Standard Library is distributed under the MIT
57
57
License. However components of the library may be based on code with
58
- additional licensing restriction . In particular ` ORD_SORT ` ,
58
+ additional licensing restrictions . In particular ` ORD_SORT ` ,
59
59
` SORT_INDEX ` , and ` SORT ` are translations of codes with their
60
60
own distribution restrictions.
61
61
62
62
The ` ORD_SORT ` and ` SORT_INDEX ` subroutines are essentially
63
- translations to Fortran 2008 of the ` "rust " sort ` of the Rust Language
63
+ translations to Fortran 2008 of the ` "Rust " sort ` of the Rust Language
64
64
distributed as part of
65
65
[ ` slice.rs ` ] ( https://github.com/rust-lang/rust/blob/90eb44a5897c39e3dff9c7e48e3973671dcd9496/src/liballoc/slice.rs ) .
66
66
The header of the ` slice.rs ` file has as its licensing requirements:
@@ -75,7 +75,7 @@ The header of the `slice.rs` file has as its licensing requirements:
75
75
option. This file may not be copied, modified, or distributed
76
76
except according to those terms.
77
77
78
- so the license for the ` slice.rs ` code is compatible with the use of
78
+ So the license for the ` slice.rs ` code is compatible with the use of
79
79
modified versions of the code in the Fortran Standard Library under
80
80
the MIT license.
81
81
@@ -108,17 +108,16 @@ performance than `SORT` on partially sorted data, having O(N)
108
108
performance on uniformly increasing or decreasing data.
109
109
110
110
111
- ` ORD_SORT ` begins by traversing the array starting in its tail
112
- attempting to identify ` runs ` in the array, where a run is either a
113
- uniformly decreasing sequence, ` ARRAY(i-1) > ARRAY(i) ` , or a
114
- non-decreasing, ` ARRAY(i-1) <= ARRAY(i) ` , sequence. First delimitated
115
- decreasing sequences are reversed in their order. Then, if the
116
- sequence has less than ` MIN_RUN ` elements, previous elements in the
117
- array are added to the run using ` insertion sort ` until the run
118
- contains ` MIN_RUN ` elements or the array is completely processed. As
119
- each run is identified the start and length of the run
120
- are then pushed onto a stack and the stack is then processed using
121
- ` merge ` until it obeys the stack invariants:
111
+ When sorting in an increasing order, ` ORD_SORT ` begins by traversing the array
112
+ starting in its tail attempting to identify ` runs ` in the array, where a run is
113
+ either a uniformly decreasing sequence, ` ARRAY(i-1) > ARRAY(i) ` , or a
114
+ non-decreasing, ` ARRAY(i-1) <= ARRAY(i) ` , sequence. First delimited decreasing
115
+ sequences are reversed in their order. Then, if the sequence has less than
116
+ ` MIN_RUN ` elements, previous elements in the array are added to the run using
117
+ ` insertion sort ` until the run contains ` MIN_RUN ` elements or the array is
118
+ completely processed. As each run is identified the start and length of the run
119
+ are then pushed onto a stack and the stack is then processed using ` merge ` until
120
+ it obeys the stack invariants:
122
121
123
122
1 . len(i-2) > len(i-1) + len(i)
124
123
2 . len(i-1) > len(i)
@@ -134,6 +133,9 @@ structured data. As a modified `merge sort`, `ORD_SORT` requires the
134
133
use of a "scratch" array, that may be provided as an optional ` work `
135
134
argument or allocated internally on the stack.
136
135
136
+ Arrays can be also sorted in a decreasing order by providing the argument `reverse
137
+ = .true.`.
138
+
137
139
#### The ` SORT_INDEX ` subroutine
138
140
139
141
The ` SORT ` and ` ORD_SORT ` subroutines can sort rank 1 isolated
@@ -205,11 +207,11 @@ Experimental
205
207
##### Description
206
208
207
209
Returns an input ` array ` with the elements sorted in order of
208
- increasing value.
210
+ increasing, or decreasing, value.
209
211
210
212
##### Syntax
211
213
212
- ` call [[stdlib_sorting(module):ord_sort(subroutine)]]ord_sort ( array[, work ] ) `
214
+ ` call [[stdlib_sorting(module):ord_sort(subroutine)]]ord_sort ( array[, work, reverse ] ) `
213
215
214
216
##### Class
215
217
@@ -233,6 +235,12 @@ memory for internal record keeping. If associated with an array in
233
235
static storage, its use can significantly reduce the stack memory
234
236
requirements for the code. Its contents on return are undefined.
235
237
238
+ ` reverse ` (optional): shall be a scalar of type default logical. It
239
+ is an ` intent(in) ` argument. If present with a value of ` .true. ` then
240
+ ` array ` will be sorted in order of non-increasing values in stable
241
+ order. Otherwise index will sort ` array ` in order of non-decreasing
242
+ values in stable order.
243
+
236
244
##### Notes
237
245
238
246
` ORD_SORT ` implements a hybrid sorting algorithm combining
@@ -246,26 +254,12 @@ non-decreasing arrays. The optional `work` array replaces "scratch"
246
254
memory that would otherwise be allocated on the stack. If ` array ` is of
247
255
any type ` REAL ` the order of its elements on return undefined if any
248
256
element of ` array ` is a ` NaN ` . Sorting of ` CHARACTER(*) ` and
249
- ` STRING_TYPE ` arrays are based on the operator ` > ` , and not on the
257
+ ` STRING_TYPE ` arrays are based on the operators ` > ` and ` < ` , and not on the
250
258
function ` LGT ` .
251
259
252
260
253
261
##### Example
254
262
255
- ``` fortran
256
- ...
257
- ! Read arrays from sorted files
258
- call read_sorted_file( 'dummy_file1', array1 )
259
- call read_sorted_file( 'dummy_file2', array2 )
260
- ! Concatenate the arrays
261
- array = [ array1, array2 ]
262
- ! Sort the resulting array
263
- call ord_sort( array, work )
264
- ! Process the sorted array
265
- call array_search( array, values )
266
- ...
267
- ```
268
-
269
263
``` fortran
270
264
program demo_ord_sort
271
265
use stdlib_sorting, only: ord_sort
@@ -287,12 +281,12 @@ Experimental
287
281
288
282
##### Description
289
283
290
- Returns an input array with the elements sorted in order of increasing
291
- value.
284
+ Returns an input array with the elements sorted in order of increasing, or
285
+ decreasing, value.
292
286
293
287
##### Syntax
294
288
295
- ` call [[stdlib_sorting(module):sort(subroutine)]]sort ( array ) `
289
+ ` call [[stdlib_sorting(module):sort(subroutine)]]sort ( array, reverse ) `
296
290
297
291
##### Class
298
292
@@ -306,6 +300,13 @@ Pure generic subroutine.
306
300
` type(string_type) ` . It is an ` intent(inout) ` argument. On return its
307
301
input elements will be sorted in order of non-decreasing value.
308
302
303
+
304
+ ` reverse ` (optional): shall be a scalar of type default logical. It
305
+ is an ` intent(in) ` argument. If present with a value of ` .true. ` then
306
+ ` array ` will be sorted in order of non-increasing values in unstable
307
+ order. Otherwise index will sort ` array ` in order of non-decreasing
308
+ values in unstable order.
309
+
309
310
##### Notes
310
311
311
312
` SORT ` implements a hybrid sorting algorithm combining
0 commit comments