Exemplo n.º 1
0
INTERVAL cos0(double a, INTERVAL W) {
      INTERVAL R,A2,A4,a2,W2; //A

       //A = addDII(a,W);

       a2 = mulDDI(a,a);
       W2 = mulIII(W,addIII(W,mulDDI(2,a))); 
       A2=addIII(a2,W2);

       A4 = mulIII(A2,A2);

       /* (a+W)^2 in a2 + W2 */
       R= addDII(1.0,
          addIII(negII(divIDI(a2,2.0)),
          addIII(divIDI(negII(W2),2.0),
                 divIDI(mulIII(A4,cos_hot(A2)),24.0))));


     if (debug) print_interval("a2=",a2);
     if (debug) print_interval("W2=",W2);
     if (debug) print_interval("1-a2/2=",
                               subDII(+1.0,divIDI(a2,2.0)));
     if (debug) print_interval("y=",R);

  return(R);
}
Exemplo n.º 2
0
static void
print_intervals(void)
{
//    extern interval_t timeIrq[8];
//    char name[20];
//    int i;

    print_interval("init", &timeInit);
    print_interval("reset", &timeReset);
    print_interval("getpcm", &timeGetPCM);
    print_interval("write", &timeWrite);
    print_interval("wait", &mp3timeWait);
}
Exemplo n.º 3
0
INTERVAL cos_hot(INTERVAL A2) {
 int j,deg4 = 5;
 INTERVAL R;

 R = makeDDI(-1,1);

    for (j=4*deg4;j>=8;j -= 4) {
       /* y = cos(a), R = (1+a^2/((j-3)*(j-2))*(-1 + a^2/((j-1)*j)*R)) */
       R= addDII(-1.0,divIDI(mulIII(A2,R),(j-1)*j));
       R= addDII(+1.0,divIDI(mulIII(A2,R),(j-3)*(j-2)));
      if (debug){ printf("  j=%d  ",j); print_interval("R=",R); }
     }

     if (debug) print_interval("cos_hot=",R);

  return(R);
}
Exemplo n.º 4
0
INTERVAL sin0(double a, INTERVAL W) {
      INTERVAL A,A2,a2,W2,y;

      A = addDII(a,W);
      a2 = mulDDI(a,a);
      W2 = mulIII(W,addIII(W,mulDDI(2,a))); 
      A2=addIII(a2,W2);
      /* we need to compute A2 carefully so as to keep its
         width small. This is only a problem when a is near
         its maximum since a^3/6*sin_hot is about 1/12 and
         a is about 3/4. Thus, we only get 3 free bits
         hence A2^3*sin_hot(A2)/6 has to be correct to 8 ULP
      */    


      y = addDII(a,
          addIII(W,
                 divIDI(mulIII(A,mulIII(A2,sin_hot(A2))),
                        6.0)));

     if (debug) print_interval("a=",cnstDI(a));
     if (debug) print_interval("W=",W);
     if (debug) print_interval("A=",A);
     if (debug) print_interval("A2=",A2);
     if (debug) print_interval("A*A2=",mulIII(A,A2));
     if (debug) print_interval("a^3/6*R=",
                 divIDI(mulIII(A,mulIII(A2,sin_hot(A2))),
                        6.0));
     if (debug) print_interval("y=",y);
   return(y);

}
Exemplo n.º 5
0
int main (int argc, char **argv){

    create_file();

    print_interval(1,10000);
    print_interval(10001,20000);
    print_interval(20001,30000);
    print_interval(30001,40000);
    print_interval(40001,50000);
    print_interval(50001,60000);
    print_interval(60001,70000);
    print_interval(70001,80000);
    print_interval(80001,90000);
    print_interval(90001,100000);

    printf("\n\n");

    return 0;

}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
        SWRESET(generation);
        SWRESET(normalisation);
        SWRESET(split);
        SWRESET(construction);
        SWRESET(final);
        SWRESET(sampling);
        SWRESET(total);

        if (argc > 1) {
          omp_set_num_threads(atoi(argv[1]));
        }

        int j;
        SWTICK(total);
#pragma omp parallel
        {
#pragma omp master
                printf("Running with %d threads\n",
                                omp_get_num_threads());
                srand48_r(omp_get_thread_num(), buffer);
        }
        for (j = 0; j < 100; j++) {
                float *weights = malloc(NUM_SIDES * sizeof(float));
                float *dartboard = malloc(NUM_SIDES * sizeof(float));
                int *aliases = malloc(NUM_SIDES * sizeof(int));
                int i;
                SWTICK(generation);
#pragma omp parallel for shared(weights)
                for (i = 0; i < NUM_SIDES; i++) {
                        double w;
                        drand48_r(buffer, &w);
                        weights[i] = (float) w;
                }       
                SWTOCK(generation);
                SWTICK(normalisation);
                normalise(weights, NUM_SIDES);
                SWTOCK(normalisation);
                make_table(weights, dartboard, aliases, NUM_SIDES);
                SWTICK(sampling);
#pragma omp parallel for shared(dartboard, aliases) schedule(static) 
                for (i = 0; i < NUM_ROLLS; i++) {
                        roll(dartboard, aliases, NUM_SIDES, buffer);
                }
                SWTOCK(sampling);
                free(aliases);
                free(dartboard);
                free(weights);
        }
        SWTOCK(total);
        print_interval("Weight generation", SWGET(generation));
        print_interval("Normalisation", SWGET(normalisation));
        print_interval("Table split", SWGET(split));
        print_interval("Table construction", SWGET(construction));
        print_interval("Table final", SWGET(final));
        print_interval("Sampling", SWGET(sampling));
        print_interval("Total", SWGET(total));
        return 0;
}
Exemplo n.º 7
0
void dump_test(skdtree_t *kdtree)
{
    std::vector<meta_info_t *> result;
    struct timeval start, end;
    gettimeofday(&start, NULL);
    kdtree->dump(result);
    gettimeofday(&end, NULL);
    printf("height: %d\n", kdtree->height());
    print_interval(start, end);
    printf("%d\n", result.size());

    printf("-------------\n");

    kdtree->balance();
    result.clear();
    gettimeofday(&start, NULL);
    kdtree->dump(result);
    gettimeofday(&end, NULL);
    printf("height: %d\n", kdtree->height());
    print_interval(start, end);
    printf("%d\n", result.size()); 
}
/* 
    Print all intervals in array
*/
void print_intervals(Intervals intervals) {
    Interval first = intervals->first;
    Intervals rest = intervals->rest;

    if (first) {
        print_interval(first);

        if (rest) {
            printf(",");
            print_intervals(rest);
        }
    }
}
Exemplo n.º 9
0
int main(void)
{
    time_t start = get_current_time();
 
    sleep(1);
    time_t end = get_current_time();

    Interval *interval = make_interval(start, end);
    double diff = interval_duration(interval);
    print_interval(interval);
    free_interval(interval);

    (void) printf("Elapsed time in seconds %lf\n", diff);

    return EXIT_SUCCESS;
}
Exemplo n.º 10
0
/*!
 * print interval list
 *
 * @param   output      output stream to print to
 * @param   l           interval list to print
 */
void
print_interval_list(const char *output, struct pmm_interval_list *l)
{
    struct pmm_interval *i;
    int c;

    i = l->top;

    c=0;
    while(i != NULL) {
        SWITCHPRINTF(output, "%d of %d intervals ...\n", c, l->size);

        print_interval(output, i);

        i = i->previous;
        c++;
    }
}
Exemplo n.º 11
0
int main() {
	int starts[] = { 7, 8, 2, 3, 6, 9};
	int ends[] = {9, 10, 3, 4, 8, 12};
	int i, n = 6;
	NV *itree = NULL, *p;
	
	for (i = 0; i < n; i++) {
		itree = insert(itree, newitem(starts[i], ends[i], NULL));
	}
	
	puts("\nlookupany");
	p = lookupany(itree, 5, 9);
	print_interval(p);
	
	puts("\nlookupall");
	lookupall(itree, 5, 9);
	
	return 0;
}
Exemplo n.º 12
0
void procmonitor_t::work()
{

    if (*&_state==CPS_NOTSET) _setup(_interval_sec);
    assert (*&_state!=CPS_NOTSET);

    // Hook
    case_setup();
    
    eCPS astate = *&_state;
    int error = 0;
    struct timespec start;

    pthread_mutex_lock(&_mutex);
    clock_gettime(CLOCK_REALTIME, &start);    

    struct timespec ts = start;    
    static long const BILLION = 1000*1000*1000;

    while (true) {

        astate = *&_state;
            
        switch (astate) {
        case (CPS_RUNNING):
        case (CPS_PAUSE):    // PAUSE behaves like RUNNING, but without recording data

            // Hook
            case_tick();
            print_interval();

            // Update secs/usecs
            ts = start;
            ts.tv_nsec += _interval_usec*1000;
            if(ts.tv_nsec > BILLION) {
                ts.tv_nsec -= BILLION;
                ts.tv_sec++;
            }            

            // sleep periodically until next measurement
            while(true) {

                error = pthread_cond_timedwait(&_cond, &_mutex, &ts);
                clock_gettime(CLOCK_REALTIME, &start);
                if(start.tv_sec > ts.tv_sec || 
                   (start.tv_sec == ts.tv_sec && start.tv_nsec > ts.tv_nsec))
                    break;
            }
            start = ts;
            break;


        case (CPS_RESET):

            // Hook
            case_reset();

            // clear
            _total_usage = 0;
            _num_usage_readings = 0;
            _avg_usage = 0;
            _state = CPS_RUNNING;
            break;

        case (CPS_STOP):

            // Hook
            case_stop();
            return;

        case (CPS_NOTSET): 
        default:
            assert(0); // invalid value 
            break;
        }
    }
}
Exemplo n.º 13
0
int 
main (int argc, char *argv[]) {
  char *filename;
  char *divstring = NULL, *lasttypestring, *ptr;
  Univcoord_T univ_coordstart, univ_coordend;
  Chrpos_T coordstart, coordend, lastcoord = 0U;
  char Buffer[BUFLEN], nocomment[BUFLEN], query[BUFLEN], typestring[BUFLEN];
  int typeint, *types, c;
  int nargs, ntypes, ndivs;
  int *value_matches = NULL, *matches = NULL;
  int n_value_matches = 0, nmatches = 0, i;
  int *leftflanks, *rightflanks, nleftflanks = 0, nrightflanks = 0;
  long int total;
  int n;
  IIT_T iit = NULL;
  Univ_IIT_T chromosome_iit = NULL;
  bool skipp, universalp;
  
  int opt;
  extern int optind;
  extern char *optarg;
  const char *long_name;
  int long_option_index = 0;

  while ((opt = getopt_long(argc,argv,"a:b:f:LCASUu:c:HRTZN",long_options,&long_option_index)) != -1) {
    switch (opt) {
    case 0:
      long_name = long_options[long_option_index].name;
      if (!strcmp(long_name,"version")) {
	print_program_version();
	exit(0);
      } else if (!strcmp(long_name,"help")) {
	print_program_usage();
	exit(0);
      } else if (!strcmp(long_name,"exact")) {
	exactp = true;
      } else {
	/* Shouldn't reach here */
	fprintf(stderr,"Don't recognize option %s.  For usage, run 'gsnap --help'",long_name);
	exit(9);
      }
      break;

    case 'a': lowval = atof(optarg); user_lowvalue_p = true; value_matches_p = true; break;
    case 'b': highval = atof(optarg); user_highvalue_p = true; value_matches_p = true; break;

    case 'f': fieldstring = optarg; break;
    case 'L': force_label_p = true; break;
    case 'C': force_coords_p = true; break;
    case 'A': annotationonlyp = true; break;
    case 'S': sortp = true; break;
    case 'U': signedp = false; break;
    case 'u': nflanking = atoi(optarg); break;

    case 'c': centerp = true; centerlength = atoi(optarg); break;
    case 'H': centeruc = true; break;
    case 'R': runlengthp = true; break;
    case 'T': tallyp = true; break;
    case 'Z': zeroesp = true; break;
    case 'N': statsp = true; break;

    case 'V': print_program_version(); exit(0);
    case '?': print_program_usage(); exit(0);
    default: exit(9);
    }
  }

  argc -= (optind - 1);
  argv += (optind - 1);

  if (argc <= 1) {
    fprintf(stderr,"Need to specify an iit file.  Type \"iit_get --help\" for help.\n");
    exit(9);
  } else {
    filename = argv[1];
  }

  if (value_matches_p == true) {
    if ((iit = IIT_read(filename,/*name*/NULL,true,/*divread*/READ_ALL,/*divstring*/NULL,
			/*add_iit_p*/true,/*labels_read_p*/true)) == NULL) {
      if (Access_file_exists_p(filename) == false) {
	fprintf(stderr,"Cannot read file %s\n",filename);
      } else {
	fprintf(stderr,"File %s appears to be an invalid IIT file\n",filename);
      }
      exit(9);

    } else if (fieldstring != NULL) {
      if ((fieldint = IIT_fieldint(iit,fieldstring)) < 0) {
	fprintf(stderr,"No field %s defined in iit file.\n",fieldstring);
	exit(9);
      }
    }

    if (IIT_valuep(iit) == false) {
      fprintf(stderr,"Error: This IIT file does not have values stored\n");
      exit(9);
    }

    if (user_lowvalue_p == true && user_highvalue_p == true) {
      if (lowval > highval) {
	fprintf(stderr,"Cannot have lowval %f > highval %f\n",lowval,highval);
	exit(9);
      } else {
	value_matches = IIT_get_values_between(&n_value_matches,iit,lowval,highval,/*sortp*/false);
      }
    } else if (user_lowvalue_p == true) {
      value_matches = IIT_get_values_above(&n_value_matches,iit,lowval,/*sortp*/false);
      
    } else { /* user_highvalue_p == true */
      value_matches = IIT_get_values_below(&n_value_matches,iit,highval,/*sortp*/false);
    }
  }

  if (0 && statsp == true && argc == 2) {
    /* Want total over entire IIT */
    if ((iit = IIT_read(filename,NULL,true,/*divread*/READ_ALL,/*divstring*/NULL,/*add_iit_p*/true,
			/*labels_read_p*/false)) == NULL) {
      if (Access_file_exists_p(filename) == false) {
	fprintf(stderr,"Cannot read file %s\n",filename);
      } else {
	fprintf(stderr,"File %s appears to be an invalid IIT file\n",filename);
      }
      exit(9);

    } else if (fieldstring != NULL) {
      if ((fieldint = IIT_fieldint(iit,fieldstring)) < 0) {
	fprintf(stderr,"No field %s defined in iit file.\n",fieldstring);
	exit(9);
      }
    } 

    total = 0;
    n = 0;
    for (i = 0; i < IIT_total_nintervals(iit); i++) {
      debug(printf("index = %d\n",matches[i]));
      compute_totals_tally(&total,&n,/*coordstart*/0,/*coordend*/-1U,i,iit);
    }
    printf("counts:%ld non-zero-positions:%u mean-over-nonzero:%.3f\n",total,n,(double) total/(double) n);
      
    IIT_free(&iit);
    return 0;

  } else if ((universalp = IIT_universalp(filename,/*add_iit_p*/true)) == true) {
    chromosome_iit = Univ_IIT_read(filename,/*readonlyp*/true,/*add_iit_p*/true);
    if (argc != 3) {
      fprintf(stderr,"For chromosome IIT file, need to specify a query on the command line\n");
      exit(9);
    } else {
      /* Try as 0:<iitfile> 1:<query> */
      matches = get_matches_univ(&nmatches,&divstring,&univ_coordstart,&univ_coordend,
				 &leftflanks,&nleftflanks,&rightflanks,&nrightflanks,
				 argv[2],/*typestring*/NULL,&chromosome_iit,filename);

      for (i = 0; i < nmatches; i++) {
	debug(printf("\nindex = %d\n",matches[i]));
	print_interval_univ(univ_coordstart,univ_coordend,matches[i],chromosome_iit);
      }
    }

    if (divstring != NULL) {
      FREE(divstring);
    }
    Univ_IIT_free(&chromosome_iit);
    return 0;

  } else if (argc == 2 && value_matches_p == true) {
    /* Note: Could potentially handle input from stdin, but currently just deal with value_matches */

    ndivs = IIT_ndivs(iit);
    for (i = 0; i < n_value_matches; i++) {
      debug(printf("\nindex = %d\n",matches[i]));
      print_interval(&lastcoord,/*total*/0,/*divstring*/NULL,/*coordstart*/0,/*coordend*/0,
		     value_matches[i],iit,ndivs,fieldint);
    }
    
    FREE(value_matches);
    IIT_free(&iit);
    return 0;

  } else if (argc == 2) {
    debug(printf("Running under argc 2\n"));
    /* Expecting input from stdin */
      
    if ((iit = IIT_read(filename,NULL,true,/*divread*/READ_ALL,/*divstring*/NULL,/*add_iit_p*/true,
			/*labels_read_p*/true)) == NULL) {
      if (Access_file_exists_p(filename) == false) {
	fprintf(stderr,"Cannot read file %s\n",filename);
      } else {
	fprintf(stderr,"File %s appears to be an invalid IIT file\n",filename);
      }
      exit(9);
    } else if (fieldstring != NULL) {
      if ((fieldint = IIT_fieldint(iit,fieldstring)) < 0) {
	fprintf(stderr,"No field %s defined in iit file.\n",fieldstring);
	exit(9);
      }
    }
	
    while (fgets(Buffer,BUFLEN,stdin) != NULL) {
      if ((ptr = rindex(Buffer,'\n')) != NULL) {
	*ptr = '\0';
      }
      strcpy(nocomment,Buffer);
      if ((ptr = rindex(nocomment,'#')) != NULL) {
	*ptr = '\0';
      }

      skipp = false;

      if ((nargs = sscanf(nocomment,"%s %s",query,typestring)) == 2) {
	debug(printf("typestring is %s\n",typestring));
	matches = get_matches(&nmatches,&divstring,&univ_coordstart,&univ_coordend,
			      &leftflanks,&nleftflanks,&rightflanks,&nrightflanks,
			      query,typestring,&iit,filename);
	coordstart = (Chrpos_T) univ_coordstart;
	coordend = (Chrpos_T) univ_coordend;

      } else if (nargs == 1) {
	debug(printf("typestring is NULL\n"));
	matches = get_matches(&nmatches,&divstring,&univ_coordstart,&univ_coordend,
			      &leftflanks,&nleftflanks,&rightflanks,&nrightflanks,
			      query,/*typestring*/NULL,&iit,filename);
	coordstart = (Chrpos_T) univ_coordstart;
	coordend = (Chrpos_T) univ_coordend;

      } else {
	fprintf(stderr,"Can't parse line %s.  Ignoring.\n",nocomment);
	skipp = true;
      }
	
      total = 0;
      if (skipp == false) {
	fprintf(stdout,"# Query: %s\n",Buffer);
	ndivs = IIT_ndivs(iit);
	if (nflanking > 0) {
	  for (i = nleftflanks-1; i >= 0; i--) {
	    debug(printf("\nleft index = %d\n",leftflanks[i]));
	    print_interval(&lastcoord,/*total*/0,divstring,coordstart,coordend,leftflanks[i],iit,ndivs,fieldint);
	  }
	  printf("====================\n");
	  FREE(leftflanks);
	}

	lastcoord = coordstart;
	for (i = 0; i < nmatches; i++) {
	  debug(printf("\nindex = %d\n",matches[i]));
	  total = print_interval(&lastcoord,total,divstring,coordstart,coordend,matches[i],iit,ndivs,fieldint);
	}

	if (nflanking > 0) {
	  printf("====================\n");
	  for (i = 0; i < nrightflanks; i++) {
	    debug(printf("\nright index = %d\n",rightflanks[i]));
	    print_interval(&lastcoord,/*total*/0,divstring,coordstart,coordend,rightflanks[i],iit,ndivs,fieldint);
	  }
	  FREE(rightflanks);
	}

	if (zeroesp == true) {
	  while (lastcoord <= coordend) {
	    printf("%s\t%u\t%d\n",divstring,lastcoord,0);
	    lastcoord++;
	  }
	}
      }

      if (divstring != NULL) {
	FREE(divstring);
      }
      FREE(matches);
      printf("%ld\n",total);
      fprintf(stdout,"# End\n");
      fflush(stdout);
    }

    IIT_free(&iit);
    return 0;

  } else {
    /* Get coordinates/type from command line */
    if (argc == 3) {
      /* Try as 0:<iitfile> 1:<query> */
      matches = get_matches(&nmatches,&divstring,&univ_coordstart,&univ_coordend,
			    &leftflanks,&nleftflanks,&rightflanks,&nrightflanks,
			    argv[2],/*typestring*/NULL,&iit,filename);
      coordstart = (Chrpos_T) univ_coordstart;
      coordend = (Chrpos_T) univ_coordend;
    
    } else if (argc == 4) {
      /* Try as 0:<iitfile> 1:<query> 2:<type> */
      debug(printf("Running under argc 4\n"));
      matches = get_matches(&nmatches,&divstring,&univ_coordstart,&univ_coordend,
			    &leftflanks,&nleftflanks,&rightflanks,&nrightflanks,
			    argv[2],argv[3],&iit,filename);
      coordstart = (Chrpos_T) univ_coordstart;
      coordend = (Chrpos_T) univ_coordend;

    } else {
      types = (int *) CALLOC(argc-3,sizeof(int));
      for (c = 3, ntypes = 0; c < argc; c++) {
	if ((typeint = IIT_typeint(iit,argv[c])) < 0) {
	  fprintf(stderr,"No such type as %s.  Ignoring the type.\n",argv[c]);
	} else {
	  types[ntypes++] = typeint;
	  lasttypestring = argv[c];
	}
      }
      if (ntypes == 0) {
	matches = get_matches(&nmatches,&divstring,&univ_coordstart,&univ_coordend,
			      &leftflanks,&nleftflanks,&rightflanks,&nrightflanks,
			      argv[2],/*typestring*/NULL,&iit,filename);
	coordstart = (Chrpos_T) univ_coordstart;
	coordend = (Chrpos_T) univ_coordend;

      } else if (ntypes == 1) {
	matches = get_matches(&nmatches,&divstring,&univ_coordstart,&univ_coordend,
			      &leftflanks,&nleftflanks,&rightflanks,&nrightflanks,
			      argv[2],lasttypestring,&iit,filename);
	coordstart = (Chrpos_T) univ_coordstart;
	coordend = (Chrpos_T) univ_coordend;

      } else {
	matches = get_matches_multiple_typed(&nmatches,&divstring,&univ_coordstart,&univ_coordend,
					     &leftflanks,&nleftflanks,&rightflanks,&nrightflanks,
					     argv[2],types,ntypes,&iit,filename);
	coordstart = (Chrpos_T) univ_coordstart;
	coordend = (Chrpos_T) univ_coordend;
      }
    }

    if (value_matches_p == true) {
      matches = match_intersection(&nmatches,/*matches1*/matches,/*nmatches1*/nmatches,
				   /*matches2*/value_matches,/*nmatches2*/n_value_matches);
      FREE(value_matches);
    }

#if 0
    if (centerp == true) {
      print_spaces(centerlength);
      printf("*");
      print_spaces(centerlength-1);
      printf("\n");
    }
#endif

    if (statsp == true) {
      total = 0;
      n = 0;
      for (i = 0; i < nmatches; i++) {
	debug(printf("index = %d\n",matches[i]));
	compute_totals_tally(&total,&n,coordstart,coordend,matches[i],iit);
      }
      n = coordend - coordstart + 1;
      printf("counts:%ld width:%u mean:%.3f\n",total,n,(double)total/(double) n);

#if 0
    } else if (geomeanp == true) {
      logtotal = 0.0;
      total = 0;
      n = 0;
      for (i = 0; i < nmatches; i++) {
	debug(printf("index = %d\n",matches[i]));
	logtotal = compute_logtotal_tally(&total,&n,coordstart,coordend,matches[i],iit);
      }
      printf("geomean:%f totalcounts:%ld posrange:%d\n",
	     exp(logtotal/(double) (coordend - coordstart + 1)) - 1.0,total,n);
#endif

    } else {
      ndivs = IIT_ndivs(iit);
      if (nflanking > 0) {
	for (i = nleftflanks-1; i >= 0; i--) {
	  debug(printf("\nleft index = %d\n",leftflanks[i]));
	  print_interval(&lastcoord,/*total*/0,divstring,coordstart,coordend,leftflanks[i],iit,ndivs,fieldint);
	}
	printf("====================\n");
	FREE(leftflanks);
      }

      lastcoord = coordstart;
      for (i = 0; i < nmatches; i++) {
	debug(printf("\nindex = %d\n",matches[i]));
	print_interval(&lastcoord,/*total*/0,divstring,coordstart,coordend,matches[i],iit,ndivs,fieldint);
      }
      
      if (nflanking > 0) {
	printf("====================\n");
	for (i = 0; i < nrightflanks; i++) {
	  debug(printf("\nright index = %d\n",rightflanks[i]));
	  print_interval(&lastcoord,/*total*/0,divstring,coordstart,coordend,rightflanks[i],iit,ndivs,fieldint);
	}
	FREE(rightflanks);
      }
    }

    if (divstring != NULL) {
      FREE(divstring);
    }
    FREE(matches);
    IIT_free(&iit);
    return 0;
  }
}
Exemplo n.º 14
0
int main(int argc, char *argv[])
{
    if(2 != argc) {
        printf("./meta_kdtree metapath\n");
        return -1;
    }

    skdtree_t se(6);
    mylist *mlist = meta_read(argv[1]);
    printf("partiton size = %d\n", mlist->size);

    // insert every file's metadata to simple kdtree
    for(int i = 0; i < mlist->size; i++) {
        file_meta *m = (file_meta *)mlist->item[i].data;
        meta_info_t *mi = new meta_info_t(m->uid, m->gid, m->size, m->atime, m->ctime, m->mtime);
        se.insert(mi);
    }
    
    // dump test
    {
        // dump in normal tree
        std::vector<meta_info_t *> result;
        struct timeval start, end;
        gettimeofday(&start, NULL);
        se.dump(result);
        gettimeofday(&end, NULL);
        printf("height: %d\n", se.height());
        print_interval(start, end);
        printf("%d\n", result.size());

        printf("\n");

        // dump in balance tree
        se.balance();
        result.clear();
        gettimeofday(&start, NULL);
        se.dump(result);
        gettimeofday(&end, NULL);
        printf("height: %d\n", se.height());
        print_interval(start, end);
        printf("%d\n", result.size()); 

        printf("\n");

        // dump in list
        std::vector<file_meta *> mresult;
        gettimeofday(&start, NULL);
        for(int i = 0; i < mlist->size; i++) {
            mresult.push_back((file_meta *)mlist->item[i].data);
        }
        gettimeofday(&end, NULL);
        print_interval(start, end);
        printf("%d\n", result.size()); 
        printf("\n");
    }

    
    {
        
        struct timeval start, end;
        meta_info_t low(0, 0, 1024*1024, 0, 0, 0);
        meta_info_t high(0, 0, 2024*1024, 0xffffffff, 0xffffffff, 0xffffffff);
        region_t r(low, high);

        // range find in kdtree

        std::cout << "range find in simple kdtree" << std::endl;
        std::vector<meta_info_t *> v;
        gettimeofday(&start, NULL);
        se.find_within_range(r, v);
        gettimeofday(&end, NULL);
        print_interval(start, end);
        printf("results: %u\n", v.size());
        printf("\n");


        v.clear();
        se.balance();
        printf("height after optimise: %d\n", se.height());

        std::cout << "range find in simple balance kdtree" << std::endl;
        gettimeofday(&start, NULL);
        se.find_within_range(r, v);
        gettimeofday(&end, NULL);
        print_interval(start, end);
        printf("results: %u\n", v.size());
        printf("\n");

    }
}