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


C++ qsort函数代码示例

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


在下文中一共展示了qsort函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: memread


//.........这里部分代码省略.........

	/* Now, if we're at level 0(main PSF), load the main executable, and any libN stuff*/
    if(!level && !type) {
    	poffset = out[0x18] | out[0x19]<<8 | out[0x1a]<<16 | out[0x1b]<<24;
		poffset &= 0x3fffffff;	// kill any MIPS cache segment indicators
		plength = out[0x1c] | out[0x1d]<<8 | out[0x1e]<<16 | out[0x1f]<<24;

		// TODO - investigate: should i just make
		//        plength = outlen-0x800?

		// Philosoma has an illegal "plength".  *sigh*
		if (plength > (outlen-0x800))
		{
			plength = outlen-0x800;
		}

		if( psfi->game ) {
			// Suikoden Tenmei has an illegal "plength". *sigh sigh*
			if( !strncmp(psfi->game, "Suikoden: Tenmei no Chikai", 26) ) {
				plength = outlen-0x800;
			}

			// Einhänder has an illegal "plength". *sigh sigh sigh*
			if( !strncmp(psfi->game, "Einhänder", 9) ) {
				plength = outlen-0x800;
			}
		}

#ifdef DEBUG
		fprintf(stderr, "%d Level: offset %x plength: %d\n", level, poffset, plength);
#endif

		LoadPSXMem(poffset,plength,out+0x800);
		free(out);
    }

	if(!type && __psflibs)	/* Load libN */ {
		LIBNCACHE *cache;
		PSFTAG *tag;
		unsigned int libncount=0;
		unsigned int cur=0;

		tag=psfi->tags;
		while(tag) {
			if(!strncasecmp(tag->key,"_lib",4) && tag->key[4])
			libncount++;
			tag=tag->next;
		}

		if(libncount) {
			cache=malloc(sizeof(LIBNCACHE)*libncount);

			tag=psfi->tags;
			while(tag) {
				if(!strncasecmp(tag->key,"_lib",4) && tag->key[4]) {
					cache[cur].num=atoi(&tag->key[4]);
					cache[cur].value=tag->value;
					cur++;
				}
				tag=tag->next;
			}
			qsort(cache, libncount, sizeof(LIBNCACHE), ccomp);
			for(cur=0;cur<libncount;cur++) {
				u32 ba[3];

 				if(cache[cur].num < 2) continue;

				ba[0]=psxRegs->pc;
				ba[1]=psxRegs->GPR.n.gp;
				ba[2]=psxRegs->GPR.n.sp;

				/* Search file name "value" from the __psflibs array */
				int n, found = 0;
				for(n=0;n<__psflibs->count;n++)
					if( !strcasecmp(cache[cur].value, __psflibs->libn[n].name) ) {
						found = 1;
						break;
					}

				if(!found || !(tmpi=memLoadPSF(__psflibs->libn[n].addr,__psflibs->libn[n].size,level+1,0))) {
					//free(key);
					//free(value);
					//free(tmpfn);
					//fclose(fp);
					//return(0);
				}
				FreeTags(tmpi->tags);
				free(tmpi);

				psxRegs->pc=ba[0];
       			psxRegs->GPR.n.gp=ba[1];
				psxRegs->GPR.n.sp=ba[2];
			}
			free(cache);
		}	// if(libncount)

	}	// if(!type)

	return(psfi);
}
开发者ID:mistydemeo,项目名称:modizer,代码行数:101,代码来源:Misc.c

示例2: sunionDiffGenericCommand

void sunionDiffGenericCommand(redisClient *c, robj **setkeys, int setnum, robj *dstkey, int op) {
    robj **sets = zmalloc(sizeof(robj*)*setnum);
    setTypeIterator *si;
    robj *ele, *dstset = NULL;
    int j, cardinality = 0;
    int diff_algo = 1;

    for (j = 0; j < setnum; j++) {
        robj *setobj = dstkey ?
            lookupKeyWrite(c->db,setkeys[j]) :
            lookupKeyRead(c->db,setkeys[j]);
        if (!setobj) {
            sets[j] = NULL;
            continue;
        }
        if (checkType(c,setobj,REDIS_SET)) {
            zfree(sets);
            return;
        }
        sets[j] = setobj;
    }

    /* Select what DIFF algorithm to use.
     *
     * Algorithm 1 is O(N*M) where N is the size of the element first set
     * and M the total number of sets.
     *
     * Algorithm 2 is O(N) where N is the total number of elements in all
     * the sets.
     *
     * We compute what is the best bet with the current input here. */
    if (op == REDIS_OP_DIFF && sets[0]) {
        long long algo_one_work = 0, algo_two_work = 0;

        for (j = 0; j < setnum; j++) {
            if (sets[j] == NULL) continue;

            algo_one_work += setTypeSize(sets[0]);
            algo_two_work += setTypeSize(sets[j]);
        }

        /* Algorithm 1 has better constant times and performs less operations
         * if there are elements in common. Give it some advantage. */
        algo_one_work /= 2;
        diff_algo = (algo_one_work <= algo_two_work) ? 1 : 2;

        if (diff_algo == 1 && setnum > 1) {
            /* With algorithm 1 it is better to order the sets to subtract
             * by decreasing size, so that we are more likely to find
             * duplicated elements ASAP. */
            qsort(sets+1,setnum-1,sizeof(robj*),
                qsortCompareSetsByRevCardinality);
        }
    }

    /* We need a temp set object to store our union. If the dstkey
     * is not NULL (that is, we are inside an SUNIONSTORE operation) then
     * this set object will be the resulting object to set into the target key*/
    dstset = createIntsetObject();

    if (op == REDIS_OP_UNION) {
        /* Union is trivial, just add every element of every set to the
         * temporary set. */
        for (j = 0; j < setnum; j++) {
            if (!sets[j]) continue; /* non existing keys are like empty sets */

            si = setTypeInitIterator(sets[j]);
            while((ele = setTypeNextObject(si)) != NULL) {
                if (setTypeAdd(dstset,ele)) cardinality++;
                decrRefCount(ele);
            }
            setTypeReleaseIterator(si);
        }
    } else if (op == REDIS_OP_DIFF && sets[0] && diff_algo == 1) {
        /* DIFF Algorithm 1:
         *
         * We perform the diff by iterating all the elements of the first set,
         * and only adding it to the target set if the element does not exist
         * into all the other sets.
         *
         * This way we perform at max N*M operations, where N is the size of
         * the first set, and M the number of sets. */
        si = setTypeInitIterator(sets[0]);
        while((ele = setTypeNextObject(si)) != NULL) {
            for (j = 1; j < setnum; j++) {
                if (!sets[j]) continue; /* no key is an empty set. */
                if (sets[j] == sets[0]) break; /* same set! */
                if (setTypeIsMember(sets[j],ele)) break;
            }
            if (j == setnum) {
                /* There is no other set with this element. Add it. */
                setTypeAdd(dstset,ele);
                cardinality++;
            }
            decrRefCount(ele);
        }
        setTypeReleaseIterator(si);
    } else if (op == REDIS_OP_DIFF && sets[0] && diff_algo == 2) {
        /* DIFF Algorithm 2:
         *
//.........这里部分代码省略.........
开发者ID:0x-Jin,项目名称:toolforspider,代码行数:101,代码来源:t_set.c

示例3: gt_dlist_unit_test

int gt_dlist_unit_test(GtError *err)
{
  GtDlist *dlist;
  GtDlistelem *dlistelem;
  int i, j, size, *data,
      elem_a = 7,
      elem_b = 6,
      elems[MAX_SIZE],
      elems_backup[MAX_SIZE],
      had_err = 0;
  gt_error_check(err);

  /* boundary case: empty dlist */
  dlist = gt_dlist_new(intcompare);
  gt_ensure(had_err, !gt_dlist_size(dlist));
  gt_dlist_delete(dlist);

  dlist = gt_dlist_new(NULL);
  gt_ensure(had_err, !gt_dlist_size(dlist));
  gt_dlist_delete(dlist);

  /* boundary case: dlist containing one element */
  dlist = gt_dlist_new(intcompare);
  gt_dlist_add(dlist, &elem_a);
  gt_ensure(had_err, gt_dlist_size(dlist) == 1);
  gt_ensure(had_err,
         elem_a == *(int*) gt_dlistelem_get_data(gt_dlist_first(dlist)));
  gt_dlist_delete(dlist);

  dlist = gt_dlist_new(NULL);
  gt_dlist_add(dlist, &elem_a);
  gt_ensure(had_err, gt_dlist_size(dlist) == 1);
  gt_ensure(had_err,
         elem_a == *(int*) gt_dlistelem_get_data(gt_dlist_first(dlist)));
  gt_dlist_delete(dlist);

  /* boundary case: dlist containing two elements */
  dlist = gt_dlist_new(intcompare);
  gt_dlist_add(dlist, &elem_a);
  gt_dlist_add(dlist, &elem_b);
  gt_ensure(had_err, gt_dlist_size(dlist) == 2);
  gt_ensure(had_err,
         elem_b == *(int*) gt_dlistelem_get_data(gt_dlist_first(dlist)));
  gt_dlist_delete(dlist);

  dlist = gt_dlist_new(NULL);
  gt_dlist_add(dlist, &elem_a);
  gt_dlist_add(dlist, &elem_b);
  gt_ensure(had_err, gt_dlist_size(dlist) == 2);
  gt_ensure(had_err,
         elem_a == *(int*) gt_dlistelem_get_data(gt_dlist_first(dlist)));
  gt_dlist_delete(dlist);

  for (i = 0; i < NUM_OF_TESTS && !had_err; i++) {
    /* construct the random elements for the list */
    size = gt_rand_max(MAX_SIZE);
    for (j = 0; j < size; j++) {
      elems[j] = gt_rand_max(INT_MAX);
      elems_backup[j] = elems[j];
    }

    /* sort the backup elements */
    qsort(elems_backup, size, sizeof (int), intcompare);

    /* test with compare function */
    dlist = gt_dlist_new(intcompare);
    gt_ensure(had_err, !gt_dlist_size(dlist));
    for (j = 0; j < size && !had_err; j++) {
      gt_dlist_add(dlist, elems + j);
      gt_ensure(had_err, gt_dlist_size(dlist) == j+1);

      for (dlistelem = gt_dlist_first(dlist); dlistelem != NULL;
           dlistelem = gt_dlistelem_next(dlistelem)) {
      }
    }
    j = 0;
    for (dlistelem = gt_dlist_first(dlist); dlistelem != NULL;
         dlistelem = gt_dlistelem_next(dlistelem)) {
      data = gt_dlistelem_get_data(dlistelem);
      gt_ensure(had_err, *data == elems_backup[j]);
      j++;
    }
    /* test gt_dlist_find() */
    for (j = 0; j < size; j++) {
      dlistelem = gt_dlist_find(dlist, elems_backup + j);
      gt_ensure(had_err, dlistelem);
      gt_ensure(had_err,
             *(int*) gt_dlistelem_get_data(dlistelem) == elems_backup[j]);
    }
    /* remove first element */
    if (gt_dlist_size(dlist)) {
      gt_dlist_remove(dlist, gt_dlist_first(dlist));
      if (gt_dlist_size(dlist)) {
        data = gt_dlistelem_get_data(gt_dlist_first(dlist));
        gt_ensure(had_err, *data == elems_backup[1]);
      }
    }
    /* remove last element */
    if (gt_dlist_size(dlist)) {
      gt_dlist_remove(dlist, gt_dlist_last(dlist));
//.........这里部分代码省略.........
开发者ID:simongog,项目名称:genometools,代码行数:101,代码来源:dlist.c

示例4: main


//.........这里部分代码省略.........

			count++;
		}
	}	
	nrOffIindexFiles = count;
	/*
	//inaliserer iindeksene
	for (i=0;i<nrOffIindexFiles;i++) {
		printf("iindex file %s\n",argv[i +2]);

		if ((iindexfile[i].fileha = fopen(argv[i +2],"rb")) == NULL) {
                	perror(argv[i +2]);
			exit(1);
        	}

		iindexfile[i].eof = 0;

		//leser inn første term
		fread(&iindexfile[i].lastTerm,sizeof(unsigned long),1,iindexfile[i].fileha);
                fread(&iindexfile[i].lastAntall,sizeof(unsigned long),1,iindexfile[i].fileha);

		iindexfile[i].nr = i;
		
	}
	*/


	gotEof = 0;
	//for (y=0;y<nrOffIindexFiles;y++) {
	while (nrOffIindexFiles != 0) {
		//hvis vi har fåt en en of file siden sist sorterer vi slik at den kommer nederst
		if (gotEof) {

			qsort(iindexfile, nrOffIindexFiles , sizeof(struct iindexfileFormat), compare_elements_eof);

			gotEof = 0;
			nrOffIindexFiles--;
		}

		//sorter de etter term
		qsort(iindexfile, nrOffIindexFiles , sizeof(struct iindexfileFormat), compare_elements);

		for (i=0;i<nrOffIindexFiles;i++) {
		
			printf("%i: t %lu : %lu eof %i\n",iindexfile[i].nr,iindexfile[i].lastTerm,iindexfile[i].lastAntall,iindexfile[i].eof);
			
		}

		//finner elementene som skal kopieres inn
		mergeTerm = iindexfile[0].lastTerm;
		i = 0;
		totaltAntall = 0;
		while (mergeTerm == iindexfile[i].lastTerm) {
			totaltAntall += iindexfile[i].lastAntall;
			iindexfile[i].Have = 1;
			i++;
		}

		printf("totaltAntall %lu for term %ul\n",totaltAntall,iindexfile[0].lastTerm);

		currentTerm = iindexfile[0].lastTerm;

		startAdress = (unsigned long)ftell(FinalIindexFileFA);
		fwrite(&iindexfile[0].lastTerm,sizeof(iindexfile[0].lastTerm),1,FinalIindexFileFA);
		fwrite(&totaltAntall,sizeof(totaltAntall),1,FinalIindexFileFA);
开发者ID:Web5design,项目名称:enterprise-search,代码行数:66,代码来源:mainOLD.c

示例5: main

int main(int argc, char** argv)
{
  if (argc<4)
  {
    fprintf(stderr,"%s node_in_file edge_in_file map_out_path",argv[0]);
    exit(-1);
  }
  const char* node_in_fname = argv[1];
  const char* edge_in_fname = argv[2];
  const char* map_out_path = argv[3];
  MFRNodeArray nodes(node_in_fname);
  MFREdgeArray edges(edge_in_fname, nodes);

  
  fprintf(stderr,"Sort edges\n");fflush(stderr);
  qsort(edges.edges, edges.nredges, sizeof(MFREdgeInt), strength_compare);

  fprintf(stderr,"Max edge strength: %d\n",edges.edges[0].strength);
  if (edges.edges[0].strength < edges.edges[edges.nredges-1].strength)
  {
    fprintf(stderr, "@@@@@@@@@@@@@@@@@@@@\nWrong sorting\[email protected]@@@@@@@@@@@@@@@@@@@@@\n");
    exit(-1);
  }
  fprintf(stderr,"Finished sorting edges\n");fflush(stderr);

  fprintf(stderr,"Count edges and store with nodes\n");fflush(stderr);
  {
    int i;
    for (i=0;i<edges.nredges;i++)
    {
      edges.edges[i].nodeA->totalnredges ++;
      edges.edges[i].nodeB->totalnredges ++;
    }
  }
//[email protected]
  fprintf(stderr,"Finished counting edges\n");fflush(stderr);



  fprintf(stderr,"Cleaning names (should perhaps be done earlier?)\n");fflush(stderr);
  nodes.CleanNames();
  fprintf(stderr,"Finished cleaning names\n");fflush(stderr);


//  nodes.debug_show_if_sorted(12);
  
  MFRQuadTree quadTree(nodes, quadLevels);
  
#define MAX_NODES_PER_QUAD 50  
  
  quadTree.BuildTree(MAX_NODES_PER_QUAD);

  quadTree.AssignQuadIds();

  fprintf(stderr,"Writing out quadtree\n");fflush(stderr);

  nrquadnodeswritten = 0;

  int nredges = edges.nredges;
  int i;

#define MAX_EDGES_PER_NODE 25

  fprintf(stderr,"Collecting edges for quads (limited to max 25 per node)\n");fflush(stderr);
  CollectEdgesIntoQuads(nodes, edges, quadTree, MAX_EDGES_PER_NODE);
  fprintf(stderr, "Done assigning edges to quads (max 25 edges per node)\n");fflush(stderr);
  quadTree.DetermineStats(edges);
  fprintf(stderr,"Writing nodeid lookup table\n");fflush(stderr);
  WriteHashtable(map_out_path, nodes, edges, quadTree);
  WriteMap(map_out_path, nodes, edges, quadTree);
  {
    char fnamebuilder[1024];
    if (quadLevels)
    {
      sprintf(fnamebuilder,"%squad_",map_out_path);
      WriteRootJSON(fnamebuilder, nodes, edges, quadTree, quadTree.root, ECompactModeCompact);

      sprintf(fnamebuilder,"%sequad_",map_out_path);
      WriteRootJSON(fnamebuilder, nodes, edges, quadTree, quadTree.root, ECompactModeExpanded);

      fprintf(stderr,"Collecting edges for quads (unlimited)\n");fflush(stderr);
      CollectEdgesIntoQuads(nodes, edges, quadTree, 0);
      fprintf(stderr, "Done assigning edges to quads (unlimited)\n");fflush(stderr);
      sprintf(fnamebuilder,"%sxquad_",map_out_path);
      WriteRootJSON(fnamebuilder, nodes, edges, quadTree, quadTree.root, ECompactModeFull);
    }
    else
    {
      sprintf(fnamebuilder,"%squad_",map_out_path);
      WriteRootJSON(fnamebuilder, nodes, edges, quadTree, quadTree.root, 0);
    }
  }
  fprintf(stderr,"Finisned\n");fflush(stderr);
  return 0;
}
开发者ID:ayalpinkus,项目名称:shinglejs,代码行数:95,代码来源:quadbuilder.cpp

示例6: qsort

static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  codec_setup_info     *ci=vi->codec_setup;
  int j,k,count=0,maxclass=-1,rangebits;

  vorbis_info_floor1 *info=_ogg_calloc(1,sizeof(*info));
  /* read partitions */
  info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  for(j=0;j<info->partitions;j++){
    info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
    if(info->partitionclass[j]<0)goto err_out;
    if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  }

  /* read partition classes */
  for(j=0;j<maxclass+1;j++){
    info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
    info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
    if(info->class_subs[j]<0)
      goto err_out;
    if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
    if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
      goto err_out;
    for(k=0;k<(1<<info->class_subs[j]);k++){
      info->class_subbook[j][k]=oggpack_read(opb,8)-1;
      if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
        goto err_out;
    }
  }

  /* read the post list */
  info->mult=oggpack_read(opb,2)+1;     /* only 1,2,3,4 legal now */
  rangebits=oggpack_read(opb,4);
  if(rangebits<0)goto err_out;

  for(j=0,k=0;j<info->partitions;j++){
    count+=info->class_dim[info->partitionclass[j]];
    for(;k<count;k++){
      int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
      if(t<0 || t>=(1<<rangebits))
        goto err_out;
    }
  }
  info->postlist[0]=0;
  info->postlist[1]=1<<rangebits;

  /* don't allow repeated values in post list as they'd result in
     zero-length segments */
  {
    int *sortpointer[VIF_POSIT+2];
    for(j=0;j<count+2;j++)sortpointer[j]=info->postlist+j;
    qsort(sortpointer,count+2,sizeof(*sortpointer),icomp);

    for(j=1;j<count+2;j++)
      if(*sortpointer[j-1]==*sortpointer[j])goto err_out;
  }

  return(info);

 err_out:
  floor1_free_info(info);
  return(NULL);
}
开发者ID:Wings1986,项目名称:iOS-projects-2013,代码行数:62,代码来源:floor1.c

示例7: main

int main()
{
        int T, size;
	int i, j, k, temp, unique;
	INTERVAL *node = NULL;
	int open;

        scanf("%d", &T);	
	while(T--)
	{

	        scanf("%d", &size);
		if(size>0)
		{
			node = (INTERVAL *) malloc(sizeof(INTERVAL) * size * 2);

			for(i=0; i<size*2; i=i+2){
				scanf("%d%d", &(node[i].val),&(node[i+1].val) );
				node[i].type = start;
				node[i+1].type = end;
			}

			qsort(node, size*2, sizeof(INTERVAL), int_compare);

			/*
			for(i=0; i<size*2; i = i+2){
				printf("\n%d %d\n", node[i].val,node[i].type );
				printf("%d %d\n", node[i+1].val,node[i+1].type );
			}
			*/

			open = 1;
			printf("(%d,",node[0].val);
		
			for(i=1; i<size*2; i++){

				if( node[i].type == start)
					open++;
				else if( node[i].type == end)
					open--;
				//printf("\nafter parsing %d, open : %d\n", node[i].val, open);

				if(!open)
				{
					if(i+1<size*2)
					{
						if( node[i].val == node[i+1].val)
							continue;
					}		
					printf("%d)",node[i].val);
	
					if(i+1<size*2)
						printf(" (%d,",node[i+1].val);
				}
			}	

			if(node)	
			{
				free(node);
			}
		
			printf("\n");
		}
		
        }
	return 0;
}
开发者ID:keerthanpai,项目名称:IIITB_Assignments,代码行数:67,代码来源:merge.c

示例8: dns_cb

static void dns_cb(struct dns_ctx *ctx, void *result, void *data) {
  int r = dns_status(ctx);
  int len, i;
  struct dns_check_info *ci = data;
  struct dns_parse p;
  struct dns_rr rr;
  unsigned nrr;
  unsigned char dn[DNS_MAXDN];
  const unsigned char *pkt, *cur, *end;
  char *result_str[MAX_RR] = { NULL };
  char *result_combined = NULL;

  /* If out ci isn't active, we must have timed out already */
  if(!__isactive_ci(ci)) {
    if(result) free(result);
    return;
  }

  ci->timed_out = 0;
  /* If we don't have a result, explode */
  if (!result) {
    ci->error = strdup(dns_strerror(r));
    goto cleanup;
  }

  /* Process the packet */
  pkt = result; end = pkt + r; cur = dns_payload(pkt);
  dns_getdn(pkt, &cur, end, dn, sizeof(dn));
  dns_initparse(&p, NULL, pkt, cur, end);
  p.dnsp_qcls = 0;
  p.dnsp_qtyp = 0;
  nrr = 0;

  while((r = dns_nextrr(&p, &rr)) > 0) {
    if (!dns_dnequal(dn, rr.dnsrr_dn)) continue;
    if ((ci->query_ctype == DNS_C_ANY || ci->query_ctype == rr.dnsrr_cls) &&
        (ci->query_rtype == DNS_T_ANY || ci->query_rtype == rr.dnsrr_typ))
      ++nrr;
    else if (rr.dnsrr_typ == DNS_T_CNAME && !nrr) {
      if (dns_getdn(pkt, &rr.dnsrr_dptr, end,
                    p.dnsp_dnbuf, sizeof(p.dnsp_dnbuf)) <= 0 ||
          rr.dnsrr_dptr != rr.dnsrr_dend) {
        ci->error = strdup("protocol error");
        break;
      }
      else {
        int32_t on = 1;
        /* This actually updates what we're looking for */
        dns_dntodn(p.dnsp_dnbuf, ci->dn, sizeof(dn));
        noit_stats_set_metric(&ci->current, "cname", METRIC_INT32, &on);

        /* Now follow the leader */
        noitL(nldeb, "%s. CNAME %s.\n", dns_dntosp(dn),
              dns_dntosp(p.dnsp_dnbuf));
        dns_dntodn(p.dnsp_dnbuf, dn, sizeof(dn));
        noitL(nldeb, " ---> '%s'\n", dns_dntosp(dn));
      }
    }
  }
  if (!r && !nrr) {
    ci->error = strdup("no data");
  }

  dns_rewind(&p, NULL);
  p.dnsp_qtyp = ci->query_rtype == DNS_T_ANY ? 0 : ci->query_rtype;
  p.dnsp_qcls = ci->query_ctype == DNS_C_ANY ? 0 : ci->query_ctype;
  while(dns_nextrr(&p, &rr) && ci->nrr < MAX_RR)
    decode_rr(ci, &p, &rr, &result_str[ci->nrr]);
  if(ci->sort)
    qsort(result_str, ci->nrr, sizeof(*result_str), cstring_cmp);
  /* calculate the length and allocate on the stack */
  len = 0;
  for(i=0; i<ci->nrr; i++) len += strlen(result_str[i]) + 2;
  result_combined = alloca(len);
  result_combined[0] = '\0';
  /* string it together */
  len = 0;
  for(i=0; i<ci->nrr; i++) {
    int slen;
    if(i) { memcpy(result_combined + len, ", ", 2); len += 2; }
    slen = strlen(result_str[i]);
    memcpy(result_combined + len, result_str[i], slen);
    len += slen;
    result_combined[len] = '\0';
    free(result_str[i]); /* free as we go */
  }
  noit_stats_set_metric(&ci->current, "answer", METRIC_STRING, result_combined);

 cleanup:
  if(result) free(result);
  if(ci->timeout_event) {
    eventer_t e = eventer_remove(ci->timeout_event);
    ci->timeout_event = NULL;
    if(e) eventer_free(e);
  }
  ci->check->flags &= ~NP_RUNNING;
  dns_check_log_results(ci);
  __deactivate_ci(ci);
}
开发者ID:Icarus-xx,项目名称:reconnoiter,代码行数:99,代码来源:dns.c

示例9: copy_ref_list

static struct ref *do_fetch_pack(struct fetch_pack_args *args,
				 int fd[2],
				 const struct ref *orig_ref,
				 struct ref **sought, int nr_sought,
				 struct shallow_info *si,
				 char **pack_lockfile)
{
	struct ref *ref = copy_ref_list(orig_ref);
	unsigned char sha1[20];
	const char *agent_feature;
	int agent_len;

	sort_ref_list(&ref, ref_compare_name);
	qsort(sought, nr_sought, sizeof(*sought), cmp_ref_by_name);

	if ((args->depth > 0 || is_repository_shallow()) && !server_supports("shallow"))
		die("Server does not support shallow clients");
	if (server_supports("multi_ack_detailed")) {
		if (args->verbose)
			fprintf(stderr, "Server supports multi_ack_detailed\n");
		multi_ack = 2;
		if (server_supports("no-done")) {
			if (args->verbose)
				fprintf(stderr, "Server supports no-done\n");
			if (args->stateless_rpc)
				no_done = 1;
		}
	}
	else if (server_supports("multi_ack")) {
		if (args->verbose)
			fprintf(stderr, "Server supports multi_ack\n");
		multi_ack = 1;
	}
	if (server_supports("side-band-64k")) {
		if (args->verbose)
			fprintf(stderr, "Server supports side-band-64k\n");
		use_sideband = 2;
	}
	else if (server_supports("side-band")) {
		if (args->verbose)
			fprintf(stderr, "Server supports side-band\n");
		use_sideband = 1;
	}
	if (server_supports("allow-tip-sha1-in-want")) {
		if (args->verbose)
			fprintf(stderr, "Server supports allow-tip-sha1-in-want\n");
		allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
	}
	if (server_supports("allow-reachable-sha1-in-want")) {
		if (args->verbose)
			fprintf(stderr, "Server supports allow-reachable-sha1-in-want\n");
		allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
	}
	if (!server_supports("thin-pack"))
		args->use_thin_pack = 0;
	if (!server_supports("no-progress"))
		args->no_progress = 0;
	if (!server_supports("include-tag"))
		args->include_tag = 0;
	if (server_supports("ofs-delta")) {
		if (args->verbose)
			fprintf(stderr, "Server supports ofs-delta\n");
	} else
		prefer_ofs_delta = 0;

	if ((agent_feature = server_feature_value("agent", &agent_len))) {
		agent_supported = 1;
		if (args->verbose && agent_len)
			fprintf(stderr, "Server version is %.*s\n",
				agent_len, agent_feature);
	}

	if (everything_local(args, &ref, sought, nr_sought)) {
		packet_flush(fd[1]);
		goto all_done;
	}
	if (find_common(args, fd, sha1, ref) < 0)
		if (!args->keep_pack)
			/* When cloning, it is not unusual to have
			 * no common commit.
			 */
			warning("no common commits");

	if (args->stateless_rpc)
		packet_flush(fd[1]);
	if (args->depth > 0)
		setup_alternate_shallow(&shallow_lock, &alternate_shallow_file,
					NULL);
	else if (si->nr_ours || si->nr_theirs)
		alternate_shallow_file = setup_temporary_shallow(si->shallow);
	else
		alternate_shallow_file = NULL;
	if (get_pack(args, fd, pack_lockfile))
		die("git fetch-pack: fetch failed.");

 all_done:
	return ref;
}
开发者ID:1tgr,项目名称:git,代码行数:98,代码来源:fetch-pack.c

示例10: sort_signal_list_alphabetically

void sort_signal_list_alphabetically(signal_list_t *list)
{
	qsort(list->pins, list->count,  sizeof(npin_t *), compare_npin_t_names);
}
开发者ID:EliasVansteenkiste,项目名称:ConnectionRouter,代码行数:4,代码来源:netlist_utils.c

示例11: _bfd_elf_strtab_finalize

void
_bfd_elf_strtab_finalize (struct elf_strtab_hash *tab)
{
  struct elf_strtab_hash_entry **array, **a, *e;
  bfd_size_type size, amt;

  /* GCC 2.91.66 (egcs-1.1.2) on i386 miscompiles this function when i is
     a 64-bit bfd_size_type: a 64-bit target or --enable-64-bit-bfd.
     Besides, indexing with a long long wouldn't give anything but extra
     cycles.  */
  size_t i;

  /* Sort the strings by suffix and length.  */
  amt = tab->size * sizeof (struct elf_strtab_hash_entry *);
  array = (struct elf_strtab_hash_entry **) bfd_malloc (amt);
  if (array == NULL)
    goto alloc_failure;

  for (i = 1, a = array; i < tab->size; ++i)
    {
      e = tab->array[i];
      if (e->refcount)
	{
	  *a++ = e;
	  /* Adjust the length to not include the zero terminator.  */
	  e->len -= 1;
	}
      else
	e->len = 0;
    }

  size = a - array;
  if (size != 0)
    {
      qsort (array, size, sizeof (struct elf_strtab_hash_entry *), strrevcmp);

      /* Loop over the sorted array and merge suffixes.  Start from the
	 end because we want eg.

	 s1 -> "d"
	 s2 -> "bcd"
	 s3 -> "abcd"

	 to end up as

	 s3 -> "abcd"
	 s2 _____^
	 s1 _______^

	 ie. we don't want s1 pointing into the old s2.  */
      e = *--a;
      e->len += 1;
      while (--a >= array)
	{
	  struct elf_strtab_hash_entry *cmp = *a;

	  cmp->len += 1;
	  if (is_suffix (e, cmp))
	    {
	      cmp->u.suffix = e;
	      cmp->len = -cmp->len;
	    }
	  else
	    e = cmp;
	}
    }

alloc_failure:
  if (array)
    free (array);

  /* Assign positions to the strings we want to keep.  */
  size = 1;
  for (i = 1; i < tab->size; ++i)
    {
      e = tab->array[i];
      if (e->refcount && e->len > 0)
	{
	  e->u.index = size;
	  size += e->len;
	}
    }

  tab->sec_size = size;

  /* Adjust the rest.  */
  for (i = 1; i < tab->size; ++i)
    {
      e = tab->array[i];
      if (e->refcount && e->len < 0)
	e->u.index = e->u.suffix->u.index + (e->u.suffix->len + e->len);
    }
}
开发者ID:0x7678,项目名称:playbook-dev-tools,代码行数:93,代码来源:elf-strtab.c

示例12: compute_tsvector_stats


//.........这里部分代码省略.........
		 */
		cutoff_freq = 9 * lexeme_no / bucket_width;

		i = hash_get_num_entries(lexemes_tab);	/* surely enough space */
		sort_table = (TrackItem **) palloc(sizeof(TrackItem *) * i);

		hash_seq_init(&scan_status, lexemes_tab);
		track_len = 0;
		minfreq = lexeme_no;
		maxfreq = 0;
		while ((item = (TrackItem *) hash_seq_search(&scan_status)) != NULL)
		{
			if (item->frequency > cutoff_freq)
			{
				sort_table[track_len++] = item;
				minfreq = Min(minfreq, item->frequency);
				maxfreq = Max(maxfreq, item->frequency);
			}
		}
		Assert(track_len <= i);

		/* emit some statistics for debug purposes */
		elog(DEBUG3, "tsvector_stats: target # mces = %d, bucket width = %d, "
			 "# lexemes = %d, hashtable size = %d, usable entries = %d",
			 num_mcelem, bucket_width, lexeme_no, i, track_len);

		/*
		 * If we obtained more lexemes than we really want, get rid of those
		 * with least frequencies.	The easiest way is to qsort the array into
		 * descending frequency order and truncate the array.
		 */
		if (num_mcelem < track_len)
		{
			qsort(sort_table, track_len, sizeof(TrackItem *),
				  trackitem_compare_frequencies_desc);
			/* reset minfreq to the smallest frequency we're keeping */
			minfreq = sort_table[num_mcelem - 1]->frequency;
		}
		else
			num_mcelem = track_len;

		/* Generate MCELEM slot entry */
		if (num_mcelem > 0)
		{
			MemoryContext old_context;
			Datum	   *mcelem_values;
			float4	   *mcelem_freqs;

			/*
			 * We want to store statistics sorted on the lexeme value using
			 * first length, then byte-for-byte comparison. The reason for
			 * doing length comparison first is that we don't care about the
			 * ordering so long as it's consistent, and comparing lengths
			 * first gives us a chance to avoid a strncmp() call.
			 *
			 * This is different from what we do with scalar statistics --
			 * they get sorted on frequencies. The rationale is that we
			 * usually search through most common elements looking for a
			 * specific value, so we can grab its frequency.  When values are
			 * presorted we can employ binary search for that.	See
			 * ts_selfuncs.c for a real usage scenario.
			 */
			qsort(sort_table, num_mcelem, sizeof(TrackItem *),
				  trackitem_compare_lexemes);

			/* Must copy the target values into anl_context */
开发者ID:GisKook,项目名称:Gis,代码行数:67,代码来源:ts_typanalyze.c

示例13: uint32_t_ll_non_leading_serialize_to_wah

//{{{uint64_t uint32_t_ll_non_leading_serialize_to_wah(void *deserialized,
uint64_t uint32_t_ll_non_leading_serialize_to_wah(void *deserialized,
                                                  void **serialized)
{
    if (deserialized == NULL) {
        *serialized = NULL;
        return 0;
    }

    struct uint32_t_ll_bpt_non_leading_data *d =  
            (struct uint32_t_ll_bpt_non_leading_data *)deserialized;

    uint32_t SA_len, SE_len, serialized_len;

    if (d->SA != NULL)
        SA_len = d->SA->len;
    else
        SA_len = 0;

    if (d->SE != NULL)
        SE_len = d->SE->len;
    else
        SE_len = 0;

    struct wah_bpt_non_leading_data *wah_d =  
        (struct wah_bpt_non_leading_data *)
        calloc(1,
               sizeof(struct wah_bpt_non_leading_data));

    wah_d->SA = NULL;
    wah_d->SE = NULL;

    if (d->SA != NULL) {
        uint32_t *B = (uint32_t *)calloc(SA_len,sizeof(uint32_t));
        uint32_t i;
        struct uint32_t_ll_node *curr;

        curr = d->SA->head;
        i = 0;
        while (curr != NULL) {
            B[i++] = curr->val;
            curr = curr->next;
        }

        if (i != d->SA->len)
            errx(1, "Incorrect length in SA:leading_data.");

        qsort(B, d->SA->len, sizeof(uint32_t), uint32_t_cmp);
        uint8_t *w = uints_to_wah(B, d->SA->len);

        wah_d->SA = w;
        free(B);
    }

    if (d->SE != NULL) {
        uint32_t *B = (uint32_t *)calloc(SE_len,sizeof(uint32_t));
        uint32_t i;
        struct uint32_t_ll_node *curr;

        curr = d->SE->head;
        i = 0;
        while (curr != NULL) {
            B[i++] = curr->val;
            curr = curr->next;
        }

        if (i != d->SE->len)
            errx(1, "Incorrect length in SE:leading_data.");

        qsort(B, d->SE->len, sizeof(uint32_t), uint32_t_cmp);
        uint8_t *w = uints_to_wah(B, d->SE->len);

        wah_d->SE = w;
        free(B);
    }

    uint64_t w_size = wah_non_leading_serialize(wah_d, serialized);

    if (wah_d->SA != NULL)
        free(wah_d->SA);
    if (wah_d->SE != NULL)
        free(wah_d->SE);
    free(wah_d);

    return w_size;
}
开发者ID:theboocock,项目名称:giggle,代码行数:86,代码来源:ll.c

示例14: fprintf


//.........这里部分代码省略.........

	/* Now, if we're at level 0(main PSF), load the main executable, and any libN stuff */
    if(!level && !type) {
		offset = out[0x18] | out[0x19]<<8 | out[0x1a]<<16 | out[0x1b]<<24;
		offset &= 0x3fffffff;	// kill any MIPS cache segment indicators
		plength = out[0x1c] | out[0x1d]<<8 | out[0x1e]<<16 | out[0x1f]<<24;

		// TODO - investigate: should i just make
		//        plength = outlen-0x800?

		// Philosoma has an illegal "plength".  *sigh*
		if (plength > (outlen-0x800))
		{
			plength = outlen-0x800;
		}

		if( psfi->game ) {
			// Suikoden Tenmei has an illegal "plength". *sigh sigh*
			if( !strncmp(psfi->game, "Suikoden: Tenmei no Chikai", 26) ) {
				plength = outlen-0x800;
			}

			// Einhänder has an illegal "plength". *sigh sigh sigh*
			if( !strncmp(psfi->game, "Einhänder", 9) ) {
				plength = outlen-0x800;
			}
		}

#ifdef DEBUG
		fprintf(stderr, "%d Level: offset %x plength: %d [%d]\n", level, offset, plength, outlen-2048);
#endif

		LoadPSXMem(offset,plength,(char*)out+0x800);
		free(out);
    }

	if(!type)	/* Load libN */{
		LIBNCACHE *cache;
		PSFTAG *tag;
		unsigned int libncount=0;
		unsigned int cur=0;

		tag=psfi->tags;
		while(tag) {
			if(!strncasecmp(tag->key,"_lib",4) && tag->key[4])
			libncount++;
			tag=tag->next;
		}

		if(libncount) {
			cache=malloc(sizeof(LIBNCACHE)*libncount);

			tag=psfi->tags;
			while(tag) {
				if(!strncasecmp(tag->key,"_lib",4) && tag->key[4]) {
					cache[cur].num=atoi(&tag->key[4]);
					cache[cur].value=tag->value;
					cur++;
				}
				tag=tag->next;
			}
			qsort(cache, libncount, sizeof(LIBNCACHE), ccomp);
			for(cur=0;cur<libncount;cur++) {
				u32 ba[3];
				char *tmpfn;

 				if(cache[cur].num < 2) continue;

				ba[0]=psxRegs->pc;
				ba[1]=psxRegs->GPR.n.gp;
				ba[2]=psxRegs->GPR.n.sp;

				/* Load file name "value" from the directory specified in
				the full path(directory + file name) "path"
				*/
				tmpfn=GetFileWithBase(path,cache[cur].value,pathDir);
				if(!(tmpi=LoadPSF(tmpfn,level+1,0,pathDir))) {
					//free(key);
					//free(value);
					//free(tmpfn);
					//fclose(fp);
			        //return(0);
				} else {
                    FreeTags(tmpi->tags);
                    free(tmpi);
                }
                free(tmpfn);


				psxRegs->pc=ba[0];
       			psxRegs->GPR.n.gp=ba[1];
				psxRegs->GPR.n.sp=ba[2];
			}
			free(cache);
		}	// if(libncount)

	}	// if(!type)

	return(psfi);
}
开发者ID:mistydemeo,项目名称:modizer,代码行数:101,代码来源:Misc.c

示例15: cvalue_list_sort_abs

static void cvalue_list_sort_abs(cvalue_list *l)
{
    qsort(l->data, l->len, sizeof(l->data[0]), cvalue_sort_abs_comp);
}
开发者ID:dmsc,项目名称:tbxl-parser,代码行数:4,代码来源:optconstvar.c


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