Beispiel #1
0
static void normalize( int root, int n, int64 * a )
{
	int e1,e2;

	while( 2 * root + 1 < n )
	{
		e1 = 2 * root + 1; // first
		e2 = e1 + 1;       // second

		/*
		check if second ancessor exists and greater than first
		*/
#ifndef SORT_REVERSE
		if( e2 < n && cmp( a[e1], a[e2] ) )
#else
		if( e2 < n && rcmp( a[e1], a[e2] ) )
#endif
			e1 = e2; // swap

		// if a[root] < max( a[e1],a[e2] ), do a swap
#ifndef SORT_REVERSE
		if( cmp( a[root], a[e1] ) )
#else
		if( rcmp( a[root], a[e1] ) )
#endif
		{
			swap(&a[root],&a[e1]);
			root = e1;
		}
		else
			break;
	}
}
Beispiel #2
0
int main(){
  int count = 0;
  char sysout[1000];
  int sysrc;
  int vdrc;
  double value;
  int w,p;
  static char *format[] = { "%*.*g","%-*.*g","%#*.*g","%+*.*g", "% *.*G",
                            "%*.*e", "%#*.*E", "%*.*f", "%#*.*f", "%*%%*g"};
  int fcnt;
  for(fcnt=0; fcnt<sizeof(format)/sizeof(char*); fcnt++){
   for(w=0; w<=12; w += 3){
    for(p=0; p<=12; p += 3){
      for(value=1.234567890123456789e-32; value<1.3e+32; value *= 1e8 ){
        outidx = 0;
        sprintf(sysout,format[fcnt],w,p,value);
        vdrc = testprintf(format[fcnt],w,p,value);
        sysrc = strlen(sysout);
        outbuf[outidx] = 0;
        count++;
        if( vdrc!=sysrc || !rcmp(outbuf,sysout) ){
          printf("Count=%d  Format=%s  Width=%d  Precision=%d  Value=%.16g\n",
            count,format[fcnt],w,p,value);
          printf("  system:   [%s] returned %d\n",sysout,sysrc);
          printf("  vxprintf: [%s] returned %d\n",outbuf,vdrc);
        }
      }
    }
   }
  }
  printf("Checked %d combinations.\n",count);
  
  return 0;
}
Beispiel #3
0
static void rPsort2(double *x, int lo, int hi, int k)
{
    double v, w;
    int L, R, i, j;                     
                                
    for (L = lo, R = hi; L < R; ) {             
        v = x[k];                       
        for(i = L, j = R; i <= j;) {                
            while (rcmp(x[i], v) < 0) i++;          
            while (rcmp(v, x[j]) < 0) j--;          
            if (i <= j) { w = x[i]; x[i++] = x[j]; x[j--] = w; }
        }                           
        if (j < k) L = i;                   
        if (k < i) R = j;                 
    }

}
Beispiel #4
0
void rsort_with_index(double *x, unsigned *indx, int n) {
	double v;
	int i, j, h, iv;

	for (h = 1; h <= n / 9; h = 3 * h + 1)
		;
	for (; h > 0; h /= 3)
		for (i = h; i < n; i++) {
			v = x[i];
			iv = indx[i];
			j = i;
			while (j >= h && rcmp(x[j - h], v) > 0) {
				x[j] = x[j - h];
				indx[j] = indx[j - h];
				j -= h;
			}
			x[j] = v;
			indx[j] = iv;
		}
}
Beispiel #5
0
int rcmp(struct vertex *a, struct vertex *b)
{
#ifdef HASH
  if (a->hash < b->hash)
    return -1;
  if (a->hash > b->hash)
    return 1;
#endif
  if (a->deg < b->deg)
    return -1;
  if (a->deg > b->deg)
    return 1;
  if (a->depth < b->depth)
    return -1;
  if (a->depth > b->depth)
    return 1;
  for (int i=0; i<a->deg; i++)
    {
      int res = rcmp(a->son[i], b->son[i]);
      if (res)
	return res;
    }
  return 0;
}
Beispiel #6
0
int cmp(const void *A, const void *B)
{
  struct vertex * const *AA = A, * const *BB = B;
  struct vertex *a = *AA, *b = *BB;
  return rcmp(a, b);
}
Beispiel #7
0
main(int argc, char *argv[])
#endif
{
	struct stat sb1, sb2;
	off_t skip1, skip2;
	int ch, fd1, fd2, special;
	char *file1, *file2;

#ifdef __STACK_CHECK__
	atexit(cleanup);
	_beginStackCheck();
#endif

#ifdef __GNO__
	while ((ch = getopt(argc, argv, "-lsr")) != -1)
#else
	while ((ch = getopt(argc, argv, "-ls")) != -1)
#endif
		switch (ch) {
		case 'l':		/* print all differences */
			lflag = 1;
			break;
		case 's':		/* silent run */
			sflag = 1;
			break;
#ifdef __GNO__
		case 'r':
			rflag = 1;	/* ignore resource fork */
			break;
#endif
		case '-':		/* stdin (must be after options) */
			--optind;
			goto endargs;
		case '?':
		default:
			usage();
		}
endargs:
#ifndef __ORCAC__
	argv += optind;
#else
	argv = argv + optind;
#endif
	argc -= optind;

	if (lflag && sflag)
		errx(ERR_EXIT, "only one of -l and -s may be specified");

	if (argc < 2 || argc > 4)
		usage();

	/* Backward compatibility -- handle "-" meaning stdin. */
	special = 0;
	if (strcmp(file1 = argv[0], "-") == 0) {
		special = 1;
		fd1 = 0;
		file1 = "stdin";
	}
#ifndef __GNO__
	else if ((fd1 = open(file1, O_RDONLY, 0)) < 0) {
#else
	/* open() for GNO/ME requires 3rd arg iff creating file */
	else if ((fd1 = open(file1, O_RDONLY)) < 0) {
#endif
		if (!sflag)
			err(ERR_EXIT, "%s", file1);
		else
			exit(1);
	}
	if (strcmp(file2 = argv[1], "-") == 0) {
		if (special)
			errx(ERR_EXIT,
				"standard input may only be specified once");
		special = 1;
		fd2 = 0;
		file2 = "stdin";
	}
#ifndef __GNO__
	else if ((fd2 = open(file2, O_RDONLY, 0)) < 0) {
#else
	else if ((fd2 = open(file2, O_RDONLY)) < 0) {
#endif
		if (!sflag)
			err(ERR_EXIT, "%s", file2);
		else
			exit(1);
	}

	skip1 = argc > 2 ? strtol(argv[2], NULL, 10) : 0;
	skip2 = argc == 4 ? strtol(argv[3], NULL, 10) : 0;

#ifndef __GNO__
	if (!special) {
		if (fstat(fd1, &sb1)) {
			if (!sflag)
				err(ERR_EXIT, "%s", file1);
			else
				exit(1);
		}
		if (!S_ISREG(sb1.st_mode))
			special = 1;
		else {
			if (fstat(fd2, &sb2)) {
				if (!sflag)
					err(ERR_EXIT, "%s", file2);
				else
					exit(1);
			}
			if (!S_ISREG(sb2.st_mode))
				special = 1;
		}
	}
#else
	special = 1; 	/* GNO doesn't have mmap.h, so treat every file as
			   a special file and process byte by byte */
#endif
	if (special)
#ifdef __GNO__
	{
#endif
		c_special(fd1, file1, skip1, fd2, file2, skip2);
#ifdef __GNO__
		close(fd1);
		close(fd2);
	}

	if (rflag != 1) {
		rflag = 2;
		rcmp(&fd1, &fd2, file1, file2);
		close(fd1);
		close(fd2);
	}
#else
	else
		c_regular(fd1, file1, skip1, sb1.st_size,
		    fd2, file2, skip2, sb2.st_size);
#endif
/*	exit(0); */
}

static void
#ifndef __STDC__
usage()
#else
usage(void)
#endif
{

	(void)fprintf(stderr,
#ifndef __GNO__
	    "usage: cmp [-l | -s] file1 file2 [skip1 [skip2]]\n");
#else
	    "usage: cmp [-l | -s] [-r] file1 file2 [skip1 [skip2]]\n");
#endif
	exit(ERR_EXIT);
}