@@ -12,9 +12,9 @@ The ``flc_algorithm`` module wraps C++ standard `<algorithm>`_ routines.
12
12
Instead of taking pairs of iterators, the Flibcpp algorithm subroutines accept
13
13
target-qualified 1-D arrays.
14
14
15
- Algorithms that take comparators (e.g. sort) will be instantiated with function
16
- pointers that allow user functions to add arbitrary ordering by defining
17
- ``bind(C) `` functions and calling with ``c_funloc(my_comparator) ``.
15
+ Algorithms that take comparators (e.g. sorting and searching) are instantiated
16
+ with function pointers that allow user functions to add arbitrary ordering by
17
+ defining ``bind(C) `` functions and calling with ``c_funloc(my_comparator) ``.
18
18
19
19
Wherever possible, array indices are returned as Fortran 1-offset native
20
20
integers, with the value 0 indicating off-the-end (e.g. "not found").
@@ -24,21 +24,31 @@ integers, with the value 0 indicating off-the-end (e.g. "not found").
24
24
Sorting
25
25
=======
26
26
27
- All sorting functions
28
-
29
- Sort
27
+ sort
30
28
----
31
29
32
30
Sorting and checking order is a single simple subroutine call::
33
31
34
- use flc_algorithm, only : sort, is_sorted
32
+ use flc_algorithm, only : sort
35
33
implicit none
36
34
integer, dimension(5) :: iarr = [ 2, 5, -2, 3, -10000]
37
- logical :: sortitude
38
35
39
36
call sort(iarr)
37
+
38
+ is_sorted
39
+ ---------
40
+
41
+ Checking the ordering of array is just as simple::
42
+
43
+ use flc_algorithm, only : is_sorted
44
+ integer, dimension(5) :: iarr = [ 2, 5, -2, 3, -10000]
45
+ logical :: sortitude
46
+
40
47
sortitude = is_sorted(iarr)
41
48
49
+ argsort
50
+ -------
51
+
42
52
A routine that provides the indices that correspond to a sorted array, like
43
53
Numpy's argsort _ ,
44
54
takes an array to analyze and an empty array of integers to fill::
@@ -61,9 +71,13 @@ the index array is larger than the data, invalid entries will be filled with
61
71
zero.
62
72
63
73
.. _argsort : https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.argsort.html
74
+
64
75
Searching
65
76
=========
66
77
78
+ binary_search
79
+ -------------
80
+
67
81
A binary search can be performed on sorted data to efficiently find an element
68
82
in a range. If the element is not found, the function returns zero; otherwise,
69
83
it returns the Fortran index of the array.
@@ -84,25 +98,54 @@ Example::
84
98
idx = binary_search(iarr, 9) ! returns 6
85
99
idx = binary_search(iarr, 10) ! returns 0
86
100
101
+ minmax_element
102
+ --------------
103
+
104
+ TODO
87
105
88
106
Set operations
89
107
==============
90
108
91
109
Sorted arrays can be manipulated as "sets," supporting unions, intersections,
92
110
and differences. TODO.
93
111
112
+ includes
113
+ --------
114
+
115
+ TODO
116
+
117
+ set_difference
118
+ --------------
119
+
120
+ TODO
121
+
122
+ set_intersection
123
+ ----------------
124
+
125
+ TODO
126
+
127
+ set_symmetric_difference
128
+ ------------------------
129
+
130
+ TODO
131
+
132
+ set_union
133
+ ---------
134
+
135
+ TODO
136
+
94
137
Modifying
95
138
=========
96
139
97
140
.. _modules_algorithm_shuffle :
98
141
99
- Shuffle
142
+ shuffle
100
143
-------
101
144
102
- The `` algorithm `` module depends on the `` random `` module so that it can use
103
- the supported random number generator to randomly reorder an array.
145
+ The "shuffle" subroutine depends on the :ref: ` modules_random ` module so that it
146
+ can use the supported random number generator to randomly reorder an array.
104
147
105
- Unique
148
+ unique
106
149
------
107
150
108
151
TODO
0 commit comments