本文整理汇总了C++中qsort_r函数的典型用法代码示例。如果您正苦于以下问题:C++ qsort_r函数的具体用法?C++ qsort_r怎么用?C++ qsort_r使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qsort_r函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: archive_compare_files
static int archive_compare_files(const void *a, const void *b, void *thunk) {
#else
// OSX, *BSD
static int archive_compare_files(void *thunk, const void *a, const void *b) {
#endif
return english_compare_natural((((struct archive *)thunk)->names[*((int*)a)]),
(((struct archive *)thunk)->names[*((int*)b)]));
}
static void archive_make_map(struct archive *ar) {
for (int i = 0; i < ar->files; i++)
ar->map[i] = i;
#ifdef __gnu_linux__
qsort_r(&(ar->map), ar->files, sizeof(int), archive_compare_files, (void*)ar);
#else
// OSX, *BSD
qsort_r(&(ar->map), ar->files, sizeof(int), (void*)ar, archive_compare_files);
#endif
}
//////////////////////////////////////////////////////////////////////
static void archive_free(struct archive *ar) {
free(ar);
}
示例2: qsort_r
void qsort_r( int* ar, int start, int end )
{
int l = start;
int r = end;
int p = ar[start];
if( start >= end )
return;
while( l < r )
{
if( ar[l] <= p )
l++;
else if( ar[r] >= p )
r--;
else
swap( ar+l, ar+r );
}
if( ar[l] < p )
{
swap( ar+start, ar+l );
l--;
}
else
{
l--;
swap( ar+start, ar+l );
}
qsort_r( ar, start, l );
qsort_r( ar, r, end );
return;
}
示例3: crowd_cut
void crowd_cut(list** l, size_t nn, size_t n, size_t m, double* xs, double* ys) {
double* dis = (double*) malloc(sizeof(double) * nn);
size_t* a = (size_t*) malloc(sizeof(size_t) * n);
list* tmp;
int k = 0;
for (size_t i=0; i<nn; i++) dis[i] = 0;
while (*l) {
a[k++] = (*l)->data;
tmp = *l;
*l = (*l)->next;
free(tmp);
}
qsort_r(a, n, sizeof(size_t), cmp_l, xs);
dis[a[0]] = dis[a[n-1]] = INF;
if (xs[a[n-1]] != xs[a[0]])
for (size_t i=1; i<n-1; i++)
dis[a[i]] += (xs[a[i+1]] - xs[a[i-1]]) / (xs[a[n-1]] - xs[a[0]]);
qsort_r(a, n, sizeof(size_t), cmp_l, ys);
dis[a[0]] = dis[a[n-1]] = INF;
if (ys[a[n-1]] != ys[a[0]])
for (size_t i=1; i<n-1; i++)
dis[a[i]] += (ys[a[i+1]] - ys[a[i-1]]) / (ys[a[n-1]] - ys[a[0]]);
qsort_r(a, n, sizeof(size_t), cmp_l, dis);
for (size_t i=1; i<=m; i++)
add_item(l, a[n-i]);
free(a);
free(dis);
}
示例4: tvh_qsort_r
void
tvh_qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg)
{
#if defined(PLATFORM_FREEBSD) || defined(PLATFORM_DARWIN)
struct tvh_qsort_data swap_arg = {arg, compar};
qsort_r(base, nmemb, size, &swap_arg, tvh_qsort_swap);
#else
qsort_r(base, nmemb, size, compar, arg);
#endif
}
示例5: QuickSort
void QuickSort( void *base, size_t num, size_t width, void *context,
int ( *compare )(void *, const void *, const void *) ) {
#if OG_WIN32
qsort_s( base, num, width, compare, context );
#elif OG_MACOS_X
qsort_r( base, num, width, context, compare );
#elif OG_LINUX
CompareWrapper data(context, compare);
qsort_r( base, num, width, CompareWrapper::Compare, &data );
#endif
}
示例6: compare_for_sort_index
static int compare_for_sort_index (const void *v1, const void *v2)
{
#elif defined(HAVE_QSORT_R)
static int compare_for_sort_index (void *thunk, const void *v1, const void *v2)
{
const int *tab_to_sort = thunk;
#else
#error "please provide some kind of thread-local storage"
#endif
int dt = tab_to_sort[*(int *)v1] - tab_to_sort[*(int *)v2];
if (dt)
return dt;
return *(int *)v1 - *(int *)v2;
}
void ivec_sort_index (const int *tab, int n, int *perm)
{
int i;
for (i = 0 ; i < n ; i++)
perm[i] = i;
#ifdef HAVE_TLS
tab_to_sort = tab;
qsort (perm, n, sizeof(int), compare_for_sort_index);
#elif defined(HAVE_QSORT_R)
qsort_r (perm, n, sizeof(int), (void*)tab, compare_for_sort_index);
#endif
}
示例7: polygon
void polygon(POINT *points[], size_t n)
{
// According to Wikipedia, a polygon of one point is a point and a polygon
// of two is a straight line and they are both valid.
assert (n >= 1);
// Extracts the leftmost point and swaps it with the first point of the
// array.
for (size_t i = 1; i < n; i++) {
if (points[i]->x < points[0]->x) {
POINT *tmp = points[i];
points[i] = points[0];
points[0] = tmp;
}
}
// Uses the leftmost point as the first point of the polygon.
// Sort the remainder of the vector by comparing the relative slope of each
// point to this first point.
qsort_r(points + 1, n - 1, sizeof (POINT *), point_cmp, (void *) points[0]);
// By selecting the leftmost point, I'm able to compare points by their
// slopes instead of their angles (because I don't care in which side of the
// first point they sit).
// This is way faster because I avoid expensive trigonometric computations.
// Moreover, as the computation and comparison of two slopes is fast, I
// don't cache them.
}
示例8: fts_sort
static FTSENT *
fts_sort(FTS *sp, FTSENT *head, size_t nitems)
{
FTSENT **ap, *p;
/*
* Construct an array of pointers to the structures and call qsort(3).
* Reassemble the array in the order returned by qsort. If unable to
* sort for memory reasons, return the directory entries in their
* current order. Allocate enough space for the current needs plus
* 40 so don't realloc one entry at a time.
*/
if (nitems > sp->fts_nitems) {
sp->fts_nitems = nitems + 40;
if ((sp->fts_array = reallocf(sp->fts_array,
sp->fts_nitems * sizeof(FTSENT *))) == NULL) {
sp->fts_nitems = 0;
return (head);
}
}
for (ap = sp->fts_array, p = head; p; p = p->fts_link)
*ap++ = p;
if (ISSET(FTS_COMPAR_B))
qsort_r(sp->fts_array, nitems, sizeof(FTSENT *),
sp->fts_compar_b, fts_compar_b);
else
qsort(sp->fts_array, nitems, sizeof(FTSENT *), fts_compar);
for (head = *(ap = sp->fts_array); --nitems; ++ap)
ap[0]->fts_link = ap[1];
ap[0]->fts_link = NULL;
return (head);
}
示例9: price_routes
/* Compute (and allocate) migration price matrix for optimization */
static void
price_routes(PRICEMAT *pm, const RBFNODE *from_rbf, const RBFNODE *to_rbf)
{
FVECT *vto = (FVECT *)malloc(sizeof(FVECT) * to_rbf->nrbf);
int i, j;
pm->nrows = from_rbf->nrbf;
pm->ncols = to_rbf->nrbf;
pm->price = (float *)malloc(sizeof(float) * pm->nrows*pm->ncols);
pm->sord = (short *)malloc(sizeof(short) * pm->nrows*pm->ncols);
if ((pm->price == NULL) | (pm->sord == NULL) | (vto == NULL)) {
fprintf(stderr, "%s: Out of memory in migration_costs()\n",
progname);
exit(1);
}
for (j = to_rbf->nrbf; j--; ) /* save repetitive ops. */
ovec_from_pos(vto[j], to_rbf->rbfa[j].gx, to_rbf->rbfa[j].gy);
for (i = from_rbf->nrbf; i--; ) {
const double from_ang = R2ANG(from_rbf->rbfa[i].crad);
FVECT vfrom;
ovec_from_pos(vfrom, from_rbf->rbfa[i].gx, from_rbf->rbfa[i].gy);
for (j = to_rbf->nrbf; j--; ) {
double dprod = DOT(vfrom, vto[j]);
pricerow(pm,i)[j] = ((dprod >= 1.) ? .0 : acos(dprod)) +
fabs(R2ANG(to_rbf->rbfa[j].crad) - from_ang);
psortrow(pm,i)[j] = j;
}
qsort_r(psortrow(pm,i), pm->ncols, sizeof(short), pm, &msrt_cmp);
}
free(vto);
}
示例10: main
int main() {
int array;
int baton;
qsort_r(&array, 1, sizeof(int), &baton, cmp);
//printf("#define NEED_QSORT_R 0\n");
return 0;
}
示例11: wget_vector_sort
void wget_vector_sort(wget_vector_t *v)
{
if (v && v->cmp) {
qsort_r(v->entry, v->cur, sizeof(void *), _compare, v);
v->sorted = 1;
}
}
示例12: qsort_b
void
qsort_b(void *base, size_t nel, size_t width,
DECLARE_BLOCK(int, compar, const void *, const void *))
{
qsort_r(base, nel, width, compar,
(int (*)(void *, const void *, const void *))
GET_BLOCK_FUNCTION(compar));
}
示例13: Q_SSetReverseSort
void Q_SSetReverseSort(sset_t *ss, qboolean caseSensitive) {
int (*func)(void *, const void *, const void *) = caseSensitive ? revtokcmp : revtokcasecmp;
#ifdef WIN32
qsort_s(&ss->tokens[0], ss->currentSize, sizeof(int32_t), func, (void *)&ss->table);
#else
qsort_r(&ss->tokens[0], ss->currentSize, sizeof(int32_t), (void *)&ss->table, func);
#endif
}
示例14: printObj
static void printObj(CFPropertyListRef obj, struct printContext* c) {
CFTypeID typeID = CFGetTypeID(obj);
if (typeID == _CFKeyedArchiverUIDGetTypeID()) {
unsigned uid = _CFKeyedArchiverUIDGetValue(obj);
CFPropertyListRef refObj = CFArrayGetValueAtIndex(c->objs, uid);
if (CFEqual(refObj, CFSTR("$null")))
printf("nil");
else if (c->refCount[uid] > 1 && isComplexObj(refObj))
printf("{CF$UID = %u;}", uid);
else
printObj(refObj, c);
} else if (typeID == CFArrayGetTypeID()) {
printf("(\n");
++ c->tabs;
CFArrayApplyFunction(obj, CFRangeMake(0, CFArrayGetCount(obj)), (CFArrayApplierFunction)&printObjAsArrayEntry, c);
-- c->tabs;
for (unsigned i = 0; i < c->tabs; ++ i)
printf("\t");
printf(")");
} else if (typeID == CFDictionaryGetTypeID()) {
CFStringRef className = CFDictionaryGetValue(obj, CFSTR("$classname"));
if (className != NULL)
printObjAsClassName(className);
else {
printf("{\n");
++ c->tabs;
CFIndex dictCount = CFDictionaryGetCount(obj);
struct dictionarySorterContext sc;
sc.keys = malloc(sizeof(CFStringRef)*dictCount);
sc.values = malloc(sizeof(CFPropertyListRef)*dictCount);
unsigned* mapping = malloc(sizeof(unsigned)*dictCount);
for (unsigned i = 0; i < dictCount; ++ i)
mapping[i] = i;
CFDictionaryGetKeysAndValues(obj, (const void**)sc.keys, sc.values);
qsort_r(mapping, dictCount, sizeof(unsigned), &sc, (int(*)(void*,const void*,const void*))&dictionaryComparer);
for (unsigned i = 0; i < dictCount; ++ i)
printObjAsDictionaryEntry(sc.keys[mapping[i]], sc.values[mapping[i]], c);
free(mapping);
free(sc.keys);
free(sc.values);
-- c->tabs;
for (unsigned i = 0; i < c->tabs; ++ i)
printf("\t");
printf("}");
}
} else if (typeID == CFDataGetTypeID())
printObjAsData(obj);
else if (typeID == CFNumberGetTypeID())
printObjAsNumber(obj);
else if (typeID == CFStringGetTypeID())
printObjAsString(obj);
else if (typeID == CFBooleanGetTypeID())
printf(CFBooleanGetValue(obj) ? "true" : "false");
else if (typeID == CFDateGetTypeID())
printf("/*date*/ %0.09g", CFDateGetAbsoluteTime(obj));
}
示例15: color_table_sort
void color_table_sort(color_table table, axis component)
{
/* Condition d'erreur qui permetent de quitter la focntion si necessaire*/
assert(table != NULL);
qsort_r(table->colors, color_table_get_nb_color(table), sizeof(color), compare, &component);
}