61#define SORT_TYPE idxpos_type
62#define SORT_TYPE_SUFFIX idxpos
63#define SORT_TYPE_CMP_LT(a,b,...) ((a).idx < (b).idx || ((a).idx == (b).idx && (a).pos < (b).pos))
64#define SORT_TYPE_CMP_LE(a,b,...) ((a).idx < (b).idx || ((a).idx == (b).idx && (a).pos <= (b).pos))
65#define SORT_TYPE_CMP_EQ(a,b,...) ((a).idx == (b).idx && (a).pos == (b).pos)
75 int *v_pos_orig = v_pos;
77 if (!v_pos) v_pos =
xmalloc((
size_t)n *
sizeof(v_pos[0]));
79 if (v_pos != v_pos_orig || reset_pos)
83 if (v_pos != v_pos_orig) free(v_pos);
87#undef SORT_TYPE_SUFFIX
88#undef SORT_TYPE_CMP_LT
89#undef SORT_TYPE_CMP_LE
90#undef SORT_TYPE_CMP_EQ
92#define SORT_TYPE_SUFFIX int
93#define SORT_TYPE_CMP_LT(a,b,...) ((a) < (b))
94#define SORT_TYPE_CMP_LE(a,b,...) ((a) <= (b))
95#define SORT_TYPE_CMP_EQ(a,b,...) ((a) == (b))
99#undef SORT_TYPE_SUFFIX
100#undef SORT_TYPE_CMP_LT
101#undef SORT_TYPE_CMP_LE
102#undef SORT_TYPE_CMP_EQ
103#define SORT_TYPE Xt_int
104#define SORT_TYPE_SUFFIX xt_int
105#define SORT_TYPE_CMP_LT(a,b,...) ((a) < (b))
106#define SORT_TYPE_CMP_LE(a,b,...) ((a) <= (b))
107#define SORT_TYPE_CMP_EQ(a,b,...) ((a) == (b))
111#undef SORT_TYPE_SUFFIX
112#undef SORT_TYPE_CMP_LT
113#undef SORT_TYPE_CMP_LE
114#undef SORT_TYPE_CMP_EQ
115#define SORT_TYPE Xt_int
116#define SORT_TYPE_SUFFIX xt_int_permutation
117#define SORT_TYPE_CMP_LT(u,v,i,j) \
118 ((u) < (v) || ((u) == (v) && permutation[(i)] < permutation[(j)]))
119#define SORT_TYPE_CMP_LE(u,v,i,j) \
120 ((u) < (v) || ((u) == (v) && permutation[(i)] <= permutation[(j)]))
121#define SORT_TYPE_CMP_EQ(u,v,i,j) \
122 ((u) == (v) && permutation[(i)] == permutation[(j)])
123#define XT_SORT_EXTRA_ARGS_DECL , int *restrict permutation
124#define XT_SORT_EXTRA_ARGS_PASS , permutation
125#define XT_SORT_EXTRA_ARGS_ADVANCE(adv) permutation += (adv)
126#define XT_SORT_EXTRA_ARGS_SWAP(i,j) do { \
127 size_t i_ = (size_t)(i), j_ = (size_t)(j); \
128 int tp = permutation[i_]; \
129 permutation[i_] = permutation[j_]; \
130 permutation[j_] = tp; \
136#undef SORT_TYPE_SUFFIX
137#undef SORT_TYPE_CMP_LT
138#undef SORT_TYPE_CMP_LE
139#undef SORT_TYPE_CMP_EQ
141#define SORT_TYPE_SUFFIX int_permutation
142#define SORT_TYPE_CMP_LT(u,v,i,j) ((u) < (v) || (u == v && permutation[(i)] < permutation[(j)]))
143#define SORT_TYPE_CMP_LE(u,v,i,j) ((u) < (v) || (u == v && permutation[(i)] <= permutation[(j)]))
144#define SORT_TYPE_CMP_EQ(u,v,i,j) ((u) == (v) && permutation[(i)] == permutation[(j)])
145#define XT_SORT_EXTRA_ARGS_DECL , int *restrict permutation
146#define XT_SORT_EXTRA_ARGS_PASS , permutation
147#define XT_SORT_EXTRA_ARGS_ADVANCE(adv) permutation += (adv)
148#define XT_SORT_EXTRA_ARGS_SWAP(i,j) do { \
149 size_t i_ = (size_t)(i), j_ = (size_t)(j); \
150 int tp = permutation[i_]; \
151 permutation[i_] = permutation[j_]; \
152 permutation[j_] = tp; \
add versions of standard API functions not returning on error
void xt_quicksort_index(Xt_int *restrict v_idx, int n, int *restrict v_pos, int reset_pos)
void xt_quicksort_xt_int_permutation(Xt_int *a, size_t n, int *restrict permutation)
macros to create quicksort implementations
void xt_assign_id_map_int(size_t n, int *restrict a, int ofs)