SpM Handbook
1.2.4
Loading...
Searching...
No Matches
spm_integers.c
Go to the documentation of this file.
1
/**
2
*
3
* @file spm_integers.c
4
*
5
* SParse Matrix package integers array management routines.
6
*
7
* @copyright 2016-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8
* Univ. Bordeaux. All rights reserved.
9
*
10
* @version 1.2.4
11
* @author Francois Pellegrini
12
* @author Xavier Lacoste
13
* @author Pierre Ramet
14
* @author Mathieu Faverge
15
* @author Matias Hastaran
16
* @author Tony Delarue
17
* @author Alycia Lisito
18
* @date 2024-05-29
19
*
20
**/
21
#include "common.h"
22
23
/**
24
*******************************************************************************
25
*
26
* @ingroup spm
27
*
28
* @brief Convert integer array to spm_int_t format.
29
*
30
*******************************************************************************
31
*
32
* @param[in] n
33
* The number of elements in the array.
34
*
35
* @param[in] input
36
* The input int array.
37
*
38
* @param[inout] output
39
* The output spm_int_t array.
40
*
41
*******************************************************************************/
42
void
43
spmIntConvert
(
spm_int_t
n,
const
int
*input,
spm_int_t
*output )
44
{
45
if
(
sizeof
(
spm_int_t
) !=
sizeof
(
int
)) {
46
spm_int_t
*tmpo;
47
const
int
*tmpi;
48
int
i;
49
50
tmpi = input;
51
tmpo = output;
52
for
(i=0; i<n; i++, tmpi++, tmpo++) {
53
*tmpo = (
spm_int_t
)(*tmpi);
54
}
55
}
56
else
{
57
memcpy( output, input, n *
sizeof
(
int
) );
58
}
59
}
60
61
/**
62
*******************************************************************************
63
*
64
* @fn void spmIntSort1Asc1(void * const pbase, const spm_int_t n);
65
* @ingroup spm_dev_integer
66
*
67
* Sorts in ascending order array of element composed of one single
68
* spm_int_t with a single key value.
69
*
70
*******************************************************************************
71
*
72
* @param[inout] pbase
73
* Pointer to the array of integers to sort.
74
*
75
* @param[in] n
76
* The number of elements in the array.
77
*
78
*******************************************************************************/
79
#ifndef DOXYGEN_SHOULD_SKIP_THIS
80
#define INTSORTNAME spmIntSort1Asc1
81
#define INTSORTSIZE (sizeof (spm_int_t))
82
#define INTSORTSWAP(p,q) do { \
83
spm_int_t t; \
84
t = *((spm_int_t *) (p)); \
85
*((spm_int_t *) (p)) = *((spm_int_t *) (q)); \
86
*((spm_int_t *) (q)) = t; \
87
} while (0)
88
#define INTSORTCMP(p,q) (*((spm_int_t *) (p)) < *((spm_int_t *) (q)))
89
#include "integer_sort.c"
90
#undef INTSORTNAME
91
#undef INTSORTSIZE
92
#undef INTSORTSWAP
93
#undef INTSORTCMP
94
#endif
/* DOXYGEN_SHOULD_SKIP_THIS */
95
96
/**
97
*******************************************************************************
98
*
99
* @fn void spmIntSort2Asc1(void * const pbase, const spm_int_t n);
100
* @ingroup spm_dev_integer
101
*
102
* Sorts in ascending order array of element composed of two
103
* spm_int_t by ascending order. The first value is used as key.
104
*
105
*******************************************************************************
106
*
107
* @param[inout] pbase
108
* Pointer to the array of couple of integers to sort.
109
*
110
* @param[in] n
111
* The number of elements in the array.
112
*
113
*******************************************************************************/
114
#ifndef DOXYGEN_SHOULD_SKIP_THIS
115
#define INTSORTNAME spmIntSort2Asc1
116
#define INTSORTSIZE (2 * sizeof (spm_int_t))
117
#define INTSORTSWAP(p,q) do { \
118
spm_int_t t, u; \
119
t = *((spm_int_t *) (p)); \
120
u = *((spm_int_t *) (p) + 1); \
121
*((spm_int_t *) (p)) = *((spm_int_t *) (q)); \
122
*((spm_int_t *) (p) + 1) = *((spm_int_t *) (q) + 1); \
123
*((spm_int_t *) (q)) = t; \
124
*((spm_int_t *) (q) + 1) = u; \
125
} while (0)
126
#define INTSORTCMP(p,q) (*((spm_int_t *) (p)) < *((spm_int_t *) (q)))
127
#include "integer_sort.c"
128
#undef INTSORTNAME
129
#undef INTSORTSIZE
130
#undef INTSORTSWAP
131
#undef INTSORTCMP
132
#endif
/* DOXYGEN_SHOULD_SKIP_THIS */
133
134
/**
135
*******************************************************************************
136
*
137
* @fn void spmIntSort3Asc1(void * const pbase, const spm_int_t n);
138
* @ingroup spm_dev_integer
139
*
140
* @brief Sorts in ascending order array of element composed of three
141
* spm_int_t by ascending order. The first value is used as key.
142
*
143
*******************************************************************************
144
*
145
* @param[inout] pbase
146
* Pointer to the array of triplet of integers to sort.
147
*
148
* @param[in] n
149
* The number of elements in the array.
150
*
151
********************************************************************************/
152
/* Declared here for now, because unused */
153
void
spmIntSort3Asc1(
void
*
const
pbase,
const
spm_int_t
n);
154
155
#ifndef DOXYGEN_SHOULD_SKIP_THIS
156
#define INTSORTNAME spmIntSort3Asc1
157
#define INTSORTSIZE (3 * sizeof (spm_int_t))
158
#define INTSORTSWAP(p,q) do { \
159
spm_int_t t, u, v; \
160
t = *((spm_int_t *) (p)); \
161
u = *((spm_int_t *) (p) + 1); \
162
v = *((spm_int_t *) (p) + 2); \
163
*((spm_int_t *) (p)) = *((spm_int_t *) (q)); \
164
*((spm_int_t *) (p) + 1) = *((spm_int_t *) (q) + 1); \
165
*((spm_int_t *) (p) + 2) = *((spm_int_t *) (q) + 2); \
166
*((spm_int_t *) (q)) = t; \
167
*((spm_int_t *) (q) + 1) = u; \
168
*((spm_int_t *) (q) + 2) = v; \
169
} while (0)
170
#define INTSORTCMP(p,q) (*((spm_int_t *) (p)) < *((spm_int_t *) (q)))
171
#include "integer_sort.c"
172
#undef INTSORTNAME
173
#undef INTSORTSIZE
174
#undef INTSORTSWAP
175
#undef INTSORTCMP
176
#endif
/* DOXYGEN_SHOULD_SKIP_THIS */
177
178
/**
179
*******************************************************************************
180
*
181
* @fn void spmIntSort2Asc2(void * const pbase, const spm_int_t n);
182
* @ingroup spm_dev_integer
183
* @brief Sorts in ascending order array of element composed of two
184
* spm_int_t by ascending order. Both values are used as key.
185
*
186
*******************************************************************************
187
*
188
* @param[inout] pbase
189
* Pointer to the array of couple of integers to sort.
190
*
191
* @param[in] n
192
* The number of elements in the array.
193
*
194
********************************************************************************/
195
#ifndef DOXYGEN_SHOULD_SKIP_THIS
196
#define INTSORTNAME spmIntSort2Asc2
197
#define INTSORTSIZE (2 * sizeof (spm_int_t))
198
#define INTSORTSWAP(p,q) do { \
199
spm_int_t t, u; \
200
t = *((spm_int_t *) (p)); \
201
u = *((spm_int_t *) (p) + 1); \
202
*((spm_int_t *) (p)) = *((spm_int_t *) (q)); \
203
*((spm_int_t *) (p) + 1) = *((spm_int_t *) (q) + 1); \
204
*((spm_int_t *) (q)) = t; \
205
*((spm_int_t *) (q) + 1) = u; \
206
} while (0)
207
#define INTSORTCMP(p,q) ((*((spm_int_t *) (p)) < *((spm_int_t *) (q))) || ((*((spm_int_t *) (p)) == *((spm_int_t *) (q))) && (*((spm_int_t *) (p) + 1) < *((spm_int_t *) (q) + 1))))
208
#include "integer_sort.c"
209
#undef INTSORTNAME
210
#undef INTSORTSIZE
211
#undef INTSORTSWAP
212
#undef INTSORTCMP
213
#endif
/* DOXYGEN_SHOULD_SKIP_THIS */
214
215
/**
216
*******************************************************************************
217
*
218
* @fn void spmIntMSortIntAsc(void ** const pbase, const spm_int_t n);
219
* @ingroup spm_dev_integer
220
*
221
* @brief Sort 2 arrays simultaneously, the first array is an array of
222
* spm_int_t and used as primary key for sorting. The second array is an
223
* other array of spm_int_t used as secondary key.
224
*
225
*******************************************************************************
226
*
227
* @param[inout] pbase
228
* Array of pointers to the arrays of integers to sort.
229
*
230
* @param[in] n
231
* The number of elements in the array.
232
*
233
********************************************************************************/
234
#ifndef DOXYGEN_SHOULD_SKIP_THIS
235
#define INTSORTNAME spmIntMSortIntAsc
236
#define INTSORTSIZE(x) (sizeof (spm_int_t))
237
#define INTSORTNTAB 2
238
#define INTSORTSWAP(p,q) do { \
239
spm_int_t t; \
240
long disp_p = (((spm_int_t*)p)-((spm_int_t*)base_ptr)); \
241
long disp_q = (((spm_int_t*)q)-((spm_int_t*)base_ptr)); \
242
spm_int_t * int2ptr = *(pbase+1); \
243
/* swap integers */
\
244
t = *((spm_int_t *) (p)); \
245
*((spm_int_t *) (p)) = *((spm_int_t *) (q)); \
246
*((spm_int_t *) (q)) = t; \
247
/* swap on second integer array */
\
248
t = int2ptr[disp_p]; \
249
int2ptr[disp_p] = int2ptr[disp_q]; \
250
int2ptr[disp_q] = t; \
251
} while (0)
252
#define INTSORTCMP(p,q) ((*((spm_int_t *) (p)) < *((spm_int_t *) (q))) || \
253
((*((spm_int_t *) (p)) == *((spm_int_t *) (q))) && \
254
((( spm_int_t *)(*(pbase+1)))[(((spm_int_t*)p)-((spm_int_t*)base_ptr))] < \
255
(( spm_int_t *)(*(pbase+1)))[(((spm_int_t*)q)-((spm_int_t*)base_ptr))])))
256
#include "integer_sort_mtypes.c"
257
#undef INTSORTNAME
258
#undef INTSORTSIZE
259
#undef INTSORTSWAP
260
#undef INTSORTCMP
261
#undef INTSORTNTAB
262
#endif
/* DOXYGEN_SHOULD_SKIP_THIS */
263
264
/**
265
*******************************************************************************
266
*
267
* @fn void spmIntMSortSmallIntAsc(void **const pbase, const spm_int_t n);
268
* @ingroup spm_dev_integer
269
* @brief Sort 2 arrays simultaneously, the first array is an array of
270
* spm_int_t and used as primary key for sorting. The second array is an
271
* other array of spm_int_t used as secondary key.
272
*
273
*******************************************************************************
274
*
275
* @param[inout] pbase
276
* Array of pointers to the arrays of integers to sort.
277
*
278
* @param[in] n
279
* The number of elements in the array.
280
*
281
********************************************************************************/
282
/* Declared here for now, because unused */
283
void
spmIntMSortSmallIntAsc(
void
**
const
pbase,
const
spm_int_t
n);
284
285
#ifndef DOXYGEN_SHOULD_SKIP_THIS
286
#define INTSORTNAME spmIntMSortSmallIntAsc
287
#define INTSORTSIZE(x) (sizeof (int))
288
#define INTSORTNTAB 2
289
#define INTSORTSWAP(p,q) do { \
290
int t; \
291
long disp_p = (((int*)p)-((int*)base_ptr)); \
292
long disp_q = (((int*)q)-((int*)base_ptr)); \
293
int * int2ptr = *(pbase+1); \
294
/* swap integers */
\
295
t = *((int *) (p)); \
296
*((int *) (p)) = *((int *) (q)); \
297
*((int *) (q)) = t; \
298
/* swap on secont integer array */
\
299
t = int2ptr[disp_p]; \
300
int2ptr[disp_p] = int2ptr[disp_q]; \
301
int2ptr[disp_q] = t; \
302
} while (0)
303
#define INTSORTCMP(p,q) ((*((int *) (p)) < *((int *) (q))) || \
304
((*((int *) (p)) == *((int *) (q))) && \
305
((( int *)(*(pbase+1)))[(((int*)p)-((int*)base_ptr))] < \
306
(( int *)(*(pbase+1)))[(((int*)q)-((int*)base_ptr))])))
307
#include "integer_sort_mtypes.c"
308
#undef INTSORTNAME
309
#undef INTSORTSIZE
310
#undef INTSORTSWAP
311
#undef INTSORTCMP
312
#undef INTSORTNTAB
313
#endif
/* DOXYGEN_SHOULD_SKIP_THIS */
spm_int_t
int spm_int_t
The main integer datatype used in spm arrays.
Definition
datatypes.h:70
spmIntConvert
void spmIntConvert(spm_int_t n, const int *input, spm_int_t *output)
Convert integer array to spm_int_t format.
Definition
spm_integers.c:43
src
spm_integers.c
Generated by
1.9.8