My Project
programmer's documentation
cs_sort.h
Go to the documentation of this file.
1 #ifndef __CS_SORT_H__
2 #define __CS_SORT_H__
3 
4 /*============================================================================
5  * Functions related to in-place sorting of arrays.
6  *===========================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2019 EDF S.A.
12 
13  This program is free software; you can redistribute it and/or modify it under
14  the terms of the GNU General Public License as published by the Free Software
15  Foundation; either version 2 of the License, or (at your option) any later
16  version.
17 
18  This program is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21  details.
22 
23  You should have received a copy of the GNU General Public License along with
24  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25  Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------*/
29 
30 #include "cs_defs.h"
31 
32 /*----------------------------------------------------------------------------
33  * Local headers
34  *---------------------------------------------------------------------------*/
35 
36 #include "cs_base.h"
37 
38 /*---------------------------------------------------------------------------*/
39 
41 
42 /*=============================================================================
43  * Macro definitions
44  *===========================================================================*/
45 
46 /*============================================================================
47  * Type definitions
48  *===========================================================================*/
49 
50 /*=============================================================================
51  * Static global variables
52  *===========================================================================*/
53 
54 /*=============================================================================
55  * Public function prototypes
56  *===========================================================================*/
57 
58 /*----------------------------------------------------------------------------
59  * Sort an array "a" between its left bound "l" and its right bound "r"
60  * thanks to a shell sort (Knuth algorithm).
61  * Index location of the sorted array are stored in loc. a is unchanged.
62  *
63  * parameters:
64  * l <-- left bound
65  * r <-- right bound
66  * a <-> array to sort (not modified)
67  * loc <-> position by increasing order (size = r-l)
68  *---------------------------------------------------------------------------*/
69 
70 void
72  cs_lnum_t r,
73  const cs_lnum_t a[],
74  cs_lnum_t loc[]);
75 
76 /*----------------------------------------------------------------------------
77  * Sort an array "a" between its left bound "l" and its right bound "r"
78  * thanks to a shell sort (Knuth algorithm).
79  *
80  * parameters:
81  * l <-- left bound
82  * r <-- right bound
83  * a <-> array to sort
84  *---------------------------------------------------------------------------*/
85 
86 void
88  cs_lnum_t r,
89  cs_lnum_t a[]);
90 
91 /*----------------------------------------------------------------------------
92  * Sort a global array "a" between its left bound "l" and its right bound "r"
93  * thanks to a shell sort (Knuth algorithm).
94  *
95  * parameters:
96  * l <-- left bound
97  * r <-- right bound
98  * a <-> array to sort
99  *---------------------------------------------------------------------------*/
100 
101 void
103  cs_lnum_t r,
104  cs_gnum_t a[]);
105 
106 /*----------------------------------------------------------------------------
107  * Sort an array "a" and apply the sort to its associated array "b" (local
108  * numbering)
109  * Sort is realized thanks to a shell sort (Knuth algorithm).
110  *
111  * parameters:
112  * l --> left bound
113  * r --> right bound
114  * a <-> array to sort
115  * b <-> associated array
116  *---------------------------------------------------------------------------*/
117 
118 void
120  cs_lnum_t r,
121  cs_lnum_t a[],
122  cs_lnum_t b[]);
123 
124 /*----------------------------------------------------------------------------
125  * Sort an array "a" and apply the sort to its associated array "b" (local
126  * numbering)
127  * Sort is realized thanks to a shell sort (Knuth algorithm).
128  *
129  * parameters:
130  * l --> left bound
131  * r --> right bound
132  * a <-> array to sort
133  * b <-> associated array
134  *---------------------------------------------------------------------------*/
135 
136 void
138  int r,
139  int a[],
140  double b[]);
141 
142 /*----------------------------------------------------------------------------
143  * Sort an array "a" and apply the sort to its associated array "b" (local
144  * numbering)
145  * Sort is realized thanks to a shell sort (Knuth algorithm).
146  *
147  * parameters:
148  * l --> left bound
149  * r --> right bound
150  * a <-> array to sort
151  * b <-> associated array
152  *---------------------------------------------------------------------------*/
153 
154 void
156  int r,
157  int a[],
158  short int b[]);
159 
160 /*----------------------------------------------------------------------------
161  * Sort an array "a" and apply the sort to its associated array "b" (local
162  * numbering)
163  * Sort is realized thanks to a shell sort (Knuth algorithm).
164  *
165  * parameters:
166  * l --> left bound
167  * r --> right bound
168  * a <-> array to sort
169  * b <-> associated array
170  *---------------------------------------------------------------------------*/
171 
172 void
174  cs_lnum_t r,
175  cs_gnum_t a[],
176  cs_gnum_t b[]);
177 
178 /*----------------------------------------------------------------------------
179  * Order an array of local numbers.
180  *
181  * parameters:
182  * number <-> array of numbers to sort
183  * n_elts <-- number of elements considered
184  *----------------------------------------------------------------------------*/
185 
186 void
187 cs_sort_lnum(cs_lnum_t number[],
188  size_t n_elts);
189 
190 /*----------------------------------------------------------------------------
191  * Sort rows of an indexed structure.
192  *
193  * parameters:
194  * n_elts <-- number of indexed elements
195  * elt_idx <-- element index (size: n_elts+1)
196  * elts <-> indexed values
197  *
198  * returns:
199  * true if no values were encountered multiple times in a given row
200  *---------------------------------------------------------------------------*/
201 
202 bool
204  const cs_lnum_t elt_idx[],
205  cs_lnum_t elts[]);
206 
207 /*----------------------------------------------------------------------------
208  * Sort rows of an indexed structure of global ids
209  *
210  * parameters:
211  * n_elts <-- number of indexed elements
212  * elt_idx <-- element index (size: n_elts+1)
213  * elts <-> indexed values
214  *
215  * returns:
216  * true if no values were encountered multiple times in a given row
217  *---------------------------------------------------------------------------*/
218 
219 bool
221  const cs_lnum_t elt_idx[],
222  cs_gnum_t elts[]);
223 
224 /*----------------------------------------------------------------------------
225  * Sort an array of global number and remove duplicate entries.
226  *
227  * The calling code may choose to reallocate the array to the new, compacted
228  * size; this is not done automatically, to avoid the overhead of memory
229  * management in cases where it is not useful (i.e. when the array is
230  * discarded soon after use).
231  *
232  * parameters:
233  * n_elts <-- initial number of elements
234  * elts <-> elements to sort
235  *
236  * returns:
237  * number of compacted elements
238  *---------------------------------------------------------------------------*/
239 
240 cs_lnum_t
242  cs_gnum_t elts[]);
243 
244 /*----------------------------------------------------------------------------
245  * Sort an array of global number couples and remove duplicate entries.
246  *
247  * Lexicographical ordering is considered.
248  *
249  * The calling code may choose to reallocate the array to the new, compacted
250  * size; this is not done automatically, to avoid the overhead of memory
251  * management in cases where it is not useful (i.e. when the array is
252  * discarded soon after use).
253  *
254  * parameters:
255  * n_elts <-- initial number of elements
256  * elts <-> elements to sort (size: n_elts*2, interleaved)
257  *
258  * returns:
259  * number of compacted elements
260  *---------------------------------------------------------------------------*/
261 
262 cs_lnum_t
264  cs_gnum_t elts[]);
265 
266 /*---------------------------------------------------------------------------*/
267 
269 
270 #endif /* __CS_SORT_H__ */
cs_defs.h
cs_fuel_incl::a
double precision, save a
Definition: cs_fuel_incl.f90:146
cs_sort_indexed
bool cs_sort_indexed(cs_lnum_t n_elts, const cs_lnum_t elt_idx[], cs_lnum_t elts[])
Definition: cs_sort.c:654
cs_sort_gnum_shell
void cs_sort_gnum_shell(cs_lnum_t l, cs_lnum_t r, cs_gnum_t a[])
Definition: cs_sort.c:345
cs_fuel_incl::b
double precision, save b
Definition: cs_fuel_incl.f90:146
cs_sort_and_compact_gnum_2
cs_lnum_t cs_sort_and_compact_gnum_2(cs_lnum_t n_elts, cs_gnum_t elts[])
Definition: cs_sort.c:826
cs_sort_lnum
void cs_sort_lnum(cs_lnum_t number[], size_t n_elts)
Definition: cs_sort.c:589
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:468
cs_sort_shell
void cs_sort_shell(cs_lnum_t l, cs_lnum_t r, cs_lnum_t a[])
Definition: cs_sort.c:310
cs_sort_sicoupled_shell
void cs_sort_sicoupled_shell(int l, int r, int a[], short int b[])
Definition: cs_sort.c:488
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:467
cs_sort_coupled_gnum_shell
void cs_sort_coupled_gnum_shell(cs_lnum_t l, cs_lnum_t r, cs_gnum_t a[], cs_gnum_t b[])
Definition: cs_sort.c:539
cs_sort_indexed_gnum
bool cs_sort_indexed_gnum(cs_lnum_t n_elts, const cs_lnum_t elt_idx[], cs_gnum_t elts[])
Definition: cs_sort.c:691
cs_gnum_t
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:286
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_sort_and_compact_gnum
cs_lnum_t cs_sort_and_compact_gnum(cs_lnum_t n_elts, cs_gnum_t elts[])
Definition: cs_sort.c:730
cs_sort_shell_inplace
void cs_sort_shell_inplace(cs_lnum_t l, cs_lnum_t r, const cs_lnum_t a[], cs_lnum_t loc[])
Definition: cs_sort.c:268
cs_sort_coupled_shell
void cs_sort_coupled_shell(cs_lnum_t l, cs_lnum_t r, cs_lnum_t a[], cs_lnum_t b[])
Definition: cs_sort.c:387
cs_sort_dcoupled_shell
void cs_sort_dcoupled_shell(int l, int r, int a[], double b[])
Definition: cs_sort.c:437
cs_base.h