Debian Codegraph @

cextern/astrometry.net/permutedsort.h

raw
1 /*
2 # This file is part of the Astrometry.net suite.
3 # Licensed under a 3-clause BSD style license - see LICENSE
4 */
5
6 #ifndef PERMUTED_SORT_H
7 #define PERMUTED_SORT_H
8
9 // for QSORT_COMPARISON_FUNCTION
10 #include "os-features.h"
11
12 /*
13 Computes the permutation array that will cause the "realarray" to be
14 sorted according to the "compare" function.
15
16 Ie, the first element in the sorted array will be at
17 (char*)realarray + perm[0] * array_stride
18
19 The "stride" parameter gives the number of bytes between successive entries
20 in "realarray".
21
22 If "perm" is NULL, a new permutation array will be allocated and returned.
23 Otherwise, the permutation array will be placed in "perm".
24
25 Note that if you pass in a non-NULL "perm" array, its existing values will
26 be used! You probably want to initialize it with "permutation_init()" to
27 set it to the identity permutation.
28 */
29 int* permuted_sort(const void* realarray, int array_stride,
30 int (*compare)(const void*, const void*),
31 int* perm, int Nperm);
32
33 int* permutation_init(int* perm, int Nperm);
34
35 /**
36 Applies a permutation array to a data vector.
37
38 Copies "inarray" into "outarray" according to the given "perm"utation.
39
40 This also works when "inarray" == "outarray".
41 */
42 void permutation_apply(const int* perm, int Nperm, const void* inarray,
43 void* outarray, int elemsize);
44
45 /*
46 Some sort functions that might come in handy:
47 */
48 int compare_doubles_asc(const void* v1, const void* v2);
49 int compare_doubles_desc(const void* v1, const void* v2);
50
51 int compare_floats_asc(const void* v1, const void* v2);
52 int compare_floats_desc(const void* v1, const void* v2);
53
54 int compare_int64_asc(const void* v1, const void* v2);
55 int compare_int64_desc(const void* v1, const void* v2);
56
57 int compare_ints_asc(const void* v1, const void* v2);
58 int compare_ints_desc(const void* v1, const void* v2);
59
60 int compare_uchars_asc(const void* v1, const void* v2);
61 int compare_uchars_desc(const void* v1, const void* v2);
62
63 /*
64 Versions for use with QSORT_R directly (not with permuted_sort).
65 */
66 int QSORT_COMPARISON_FUNCTION(compare_floats_asc_r,
67 void* thunk, const void* v1, const void* v2);
68
69
70 #endif