• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ qsort_r函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中qsort_r函数的典型用法代码示例。如果您正苦于以下问题:C++ qsort_r函数的具体用法?C++ qsort_r怎么用?C++ qsort_r使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了qsort_r函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: compute_puzzle_size

puzzle_size compute_puzzle_size(IplImage *puzzle, IplImage **annotated) {
    IplImage *threshold_image = _grid(puzzle);

    *annotated = cvCloneImage(puzzle);
    cvCvtColor(threshold_image, *annotated, CV_GRAY2RGB);

    // the logic here is to "rank" the possible sizes, by computing the average pixel intensity
    // in the vicinity of where the lines should be.
    unsigned short guess_id = 0;
    puzzle_size guesses[PUZZLE_SIZE_MAX - PUZZLE_SIZE_MIN + 1];
    unsigned long means[PUZZLE_SIZE_MAX + 1];

    const int fuzz = threshold_image->width / 50;
    for (puzzle_size guess_size = PUZZLE_SIZE_MIN; guess_size <= PUZZLE_SIZE_MAX; ++guess_size) {
        guesses[guess_id++] = guess_size;
        means[guess_size] = 0;

        for (unsigned short i = 1; i < guess_size; ++i) {
            int center = i * (threshold_image->width / guess_size);
            for (int x = 0; x < threshold_image->width; ++x) {
                for (int y = center - fuzz; y < center + fuzz; ++y) {
                    CvScalar s = cvGet2D(threshold_image, y, x);
                    means[guess_size] += s.val[0];
                }
            }
            for (int x = center - fuzz; x < center + fuzz; ++x) {
                for (int y = 0; y < threshold_image->height; ++y) {
                    CvScalar s = cvGet2D(threshold_image, y, x);
                    means[guess_size] += s.val[0];
                }
            }
        }
        means[guess_size] /= (guess_size - 1);
    }

    qsort_r(guesses, sizeof(guesses) / sizeof(puzzle_size), sizeof(puzzle_size), (void *)means, _compare_means);

    puzzle_size size = guesses[0];

    // evenly divisible sizes are easily confused. Err on the side of the larger size puzzle.
    puzzle_size confusable[][2] = { { 4, 8 }, { 3, 9 }, { 3, 6 } };
    for (int i = 0; i < (sizeof(confusable) / sizeof(puzzle_size) / 2); ++i) {
        if ((guesses[0] == confusable[i][0]) && (guesses[1] == confusable[i][1]) && (means[guesses[0]] - means[guesses[1]] < means[guesses[1]] - means[guesses[2]])) {
            size = confusable[i][1];
            break;
        }
    }

    for (unsigned short i = 1; i < size; ++i) {
        int center = i * (threshold_image->width / size);
        cvRectangle(*annotated, cvPoint(0, center - fuzz), cvPoint(threshold_image->width, center + fuzz), CV_RGB(255, 0, 0), 2, 8, 0);
        cvRectangle(*annotated, cvPoint(center - fuzz, 0), cvPoint(center + fuzz, threshold_image->height), CV_RGB(255, 0, 0), 2, 8, 0);
    }
    cvReleaseImage(&threshold_image);

    return size;
}
开发者ID:dlowe,项目名称:kenken,代码行数:57,代码来源:kenken.c


示例17: endpoints_preference_sort

/**
 * Sort endpoints in place in descending order of preference.
 * @param endpoints array of endpoint pointers.
 */
static void
endpoints_preference_sort(const as_endpoint* endpoints[], size_t n_endpoints)
{
	// Random tie breaker to load balance between two equivalent endpoints.
	int tie_breaker = rand();

	qsort_r(endpoints, n_endpoints, sizeof(as_endpoint*),
		endpoint_preference_compare, &tie_breaker);
}
开发者ID:aerospike,项目名称:aerospike-server,代码行数:13,代码来源:endpoint.c


示例18: das_sortobs_byij

/** Sorts all observations by j,i so that they can be processed in a single
 * cycle over horizontal grid cells.
 */
static void das_sortobs_byij(dasystem* das)
{
    observations* obs = das->obs;
    int o, e;

    if (das->sort_mode == OBS_SORTMODE_IJ)
        return;
    if (obs->nobs == 0)
        return;

    enkf_printf("    sorting obs by ij:\n");
    qsort_r(obs->data, obs->nobs, sizeof(observation), cmp_obs_byij, das);

    if (das->s_f != NULL) {
        double* s = calloc(obs->nobs, sizeof(double));

        for (o = 0; o < obs->nobs; ++o)
            s[o] = das->s_f[obs->data[o].id];
        memcpy(das->s_f, s, obs->nobs * sizeof(double));

        for (o = 0; o < obs->nobs; ++o)
            s[o] = das->std_f[obs->data[o].id];
        memcpy(das->std_f, s, obs->nobs * sizeof(double));

        free(s);
    }

    if (das->s_a != NULL) {
        double* s = calloc(obs->nobs, sizeof(double));

        for (o = 0; o < obs->nobs; ++o)
            s[o] = das->s_a[obs->data[o].id];
        memcpy(das->s_a, s, obs->nobs * sizeof(double));

        for (o = 0; o < obs->nobs; ++o)
            s[o] = das->std_a[obs->data[o].id];
        memcpy(das->std_a, s, obs->nobs * sizeof(double));

        free(s);
    }

    {
        ENSOBSTYPE* S = calloc(obs->nobs, sizeof(ENSOBSTYPE));

        for (e = 0; e < das->nmem; ++e) {
            ENSOBSTYPE* Se = das->S[e];

            for (o = 0; o < obs->nobs; ++o)
                S[o] = Se[obs->data[o].id];
            memcpy(Se, S, obs->nobs * sizeof(ENSOBSTYPE));
        }
        free(S);
    }

    das->sort_mode = OBS_SORTMODE_IJ;
}
开发者ID:juicydut,项目名称:enkf-c,代码行数:59,代码来源:ensobs.c


示例19: d_argsort

void d_argsort(double *vec, int *idxs, int N)
{
    int i;
    for(i = 0; i < N; i++) {
        idxs[i] = i;
    }

    /* perform qsort */
    qsort_r(idxs, N, sizeof(int), d_argsort_compare, (void *)vec);
}
开发者ID:psclib,项目名称:pscgen,代码行数:10,代码来源:util.c


示例20: qsort_r

void
qsort_r (void *base, size_t nmemb, size_t size,
         int (*cmp) (void const *, void const *, void *),
         void *arg)
{
# undef qsort_r
  struct thunk thunk;
  thunk.cmp = cmp;
  thunk.arg = arg;
  qsort_r (base, nmemb, size, &thunk, thunk_cmp);
}
开发者ID:Chainfire,项目名称:android-ndk-compression-tools,代码行数:11,代码来源:qsort_r.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ qspRestoreCallState函数代码示例发布时间:2022-05-30
下一篇:
C++ qsort函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap