#include "utils.h" int readToTab(long* tab, char* file){ int fd = open(file, O_RDONLY); if(fd == -1){ perror("open"); exit(1); } int n = 0; int sizet = 1000, nb_size = 1; int nb_size_tab = 1; size_t x=0; char temp; char* tmp = malloc(sizeof(char)*sizet); memset(tmp, 0, sizet); read(fd,&temp,sizeof(char)); int size_tab = 0; while(temp != '.'){ if(temp == ' '){ testn++; } read(fd,&temp,sizeof(char)); } while(temp != '.'){ // printf("n:%d j:%d nb_size:%d\n", n,j,nb_size); if(temp != ' '){ tmp[x] = temp; //printf("tmp[%d] = %c\n", x, temp); x++; } else{ long t = atol(tmp); tab[n] = t; //printf("char:%c long:%d n:%d j:%d nb_size:%d, size:%d\n",temp,tab[j], n,j,nb_size, sizet); memset(tmp, 0, sizet*nb_size); x=0; n++; } read(fd,&temp,sizeof(char)); if(n==TAB_SIZE*(nb_size_tab*10)){ nb_size_tab+=1; //printf("size:%d nb_size:%d, sizef:%d\n", sizet, nb_size, sizeof(char)*(sizet*nb_size)); tab = realloc(tab, sizeof(*tab)*2); } if(n==sizet*nb_size){ nb_size+=1; //printf("size:%d nb_size:%d, sizef:%d\n", sizet, nb_size, sizeof(char)*(sizet*nb_size)); tmp = realloc(tmp, sizeof(char)*(sizet*nb_size)); } } free(tmp); return n; } void initData(struct data* d){ d->time = 0; d->comparison = 0; d->ct_fusion = 0; d->ct_parse = 0; d->write = 0; } long* generate_tab(size_t max, size_t length){ if(length==0){ return 0; } long* tab = malloc(sizeof(long)*length+1); memset(tab, 0, sizeof(long)*length+1); size_t index = 0; for(index = 0; index<length; index++){ long p = (long)(rand()%max); tab[index] = p; } return tab; } void printData(struct data d){ printf("Time passed : %ld\n", d.time); printf("Number of comparison : %ld\n", d.comparison); printf("Number of write : %ld\n", d.write); printf("Call of fusion : %ld\n", d.ct_fusion); printf("Call of parsing : %ld\n", d.ct_parse); }