#include "utils.h" long* readToTab(char* file, int *sizze){ 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 == ' '){ size_tab++; } read(fd,&temp,sizeof(char)); } *sizze = size_tab; lseek(fd, 0, SEEK_SET); long *tab = malloc(sizeof(long)*size_tab); 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)); } // for(int i = 0; i<size_tab; i++){ // if(i%15 == 0) // printf("i:%ld\n",tab[i]); // else // printf("i:%ld ", tab[i]); // } free(tmp); return tab; } 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); }