当前位置: 首页>>代码示例>>C++>>正文


C++ qsort_r函数代码示例

本文整理汇总了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);
}
开发者ID:encryptio,项目名称:NimbleInk,代码行数:26,代码来源:archive.c

示例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;
}
开发者ID:zodiac608,项目名称:polecat,代码行数:35,代码来源:30_union_intersection.cpp

示例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);
}
开发者ID:Tefx,项目名称:MoWSC,代码行数:35,代码来源:nsga2.c

示例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
}
开发者ID:c0mm0n,项目名称:tvheadend,代码行数:10,代码来源:wrappers.c

示例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
}
开发者ID:ensiform,项目名称:open-game-libraries,代码行数:11,代码来源:Common.cpp

示例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
}
开发者ID:antran89,项目名称:BoW_frameworks,代码行数:31,代码来源:sorting.c

示例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.
}
开发者ID:RaphaelJ,项目名称:Cours-passerelle,代码行数:28,代码来源:polygon.c

示例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);
}
开发者ID:outbackdingo,项目名称:uBSD,代码行数:32,代码来源:fts.c

示例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);
}
开发者ID:kalyanam-FMTGA,项目名称:ray-original,代码行数:34,代码来源:bsdfmesh.c

示例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;
}
开发者ID:migueldvb,项目名称:astrometry.net,代码行数:7,代码来源:os-features-test.c

示例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;
	}
}
开发者ID:armistace,项目名称:wget2,代码行数:7,代码来源:vector.c

示例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));
}
开发者ID:lionel0806,项目名称:freebsd,代码行数:8,代码来源:qsort_r.c

示例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
}
开发者ID:postfix,项目名称:quake2vr,代码行数:8,代码来源:sset.c

示例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));

}
开发者ID:bu2,项目名称:networkpx,代码行数:58,代码来源:visualize-archived-object.c

示例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);
	
}
开发者ID:RTWPA,项目名称:panini-vodka,代码行数:9,代码来源:color_table.c


注:本文中的qsort_r函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。