Skip to content
Snippets Groups Projects
Commit e8c6c606 authored by chafiol's avatar chafiol
Browse files

WIP:mremap_chunk()

parent 43572dc1
Branches
No related merge requests found
......@@ -9,22 +9,24 @@ int main(int argc, char **argv){
exit(1);
}
long tab[100];
long *tab = malloc(sizeof(long)*TAB_SIZE);
struct data data;
initData(&data);
if((strcmp(argv[1], "--insertion") == 0) || strcmp(argv[1], "-i")== 0){
int n = readToTab(tab, argv[2]);
printf("n:%d\n", n);
printf("Base : ");
for(int i = 0; i<n; i++){
printf("%ld,", tab[i]);
// printf("i:%d cont:%ld\n", i, tab[i]);
}
printf("\n");
triInsertion(tab, n);
printf("Insertion : ");
for(int i = 0; i<n; i++){
printf("%ld,", tab[i]);
printf("i:%d cont:%ld\n", i, tab[i]);
}
printf("\n");
}
......@@ -161,5 +163,6 @@ int main(int argc, char **argv){
else{
printf("Usage: ./tri <option> <input.txt> f\n");
}
free(tab);
return 0;
}
\ No newline at end of file
This diff is collapsed.
#include "utils.h"
int readToTab(long* tab, char* file){
int n = 0;
int fd = open(file, O_RDONLY);
if(fd == -1){
perror("open");
exit(1);
}
size_t j = 0, x=0, count = 1, sizet = 1000, nb_size = 1;
char* tmp = malloc(sizeof(char)*sizet);
memset(tmp, 0, 1000);
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));
......@@ -19,30 +24,33 @@ int readToTab(long* tab, char* file){
// 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 if(temp == ' '){
else{
long t = atol(tmp);
tab[j] = t;
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);
printf("%s\n", tmp);
memset(tmp, 0, sizet*nb_size);
j++;
count++;
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(long)*(TAB_SIZE*10));
}
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));
}
}
return n-1;
free(tmp);
return n;
}
void initData(struct data* d){
......@@ -57,8 +65,8 @@ long* generate_tab(size_t max, size_t length){
if(length==0){
return 0;
}
long* tab = malloc(sizeof(long)*length);
memset(tab, 0, sizeof(long)*length);
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);
......
......@@ -12,6 +12,8 @@
#include <string.h>
#include <time.h>
#define TAB_SIZE 1000
struct data {
long time;
unsigned int write;
......
No preview for this file type
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment