int generar_salida(char *data, t_BlockSort *bs, char *salida)
{
unsigned long int i, k;
+ char *out;
+
+ /* Dejo lugar para guardar el k y el tamaño de este bloque */
+ out = salida + sizeof(unsigned long int)*2;
+
k=-1;
for(i=0; i<bs->len; i++) {
/* print_(data, bs->array[i].pos_inicial, bs->len); */
- salida[i] = data[bs->array[i].pos_final];
+ out[i] = data[bs->array[i].pos_final];
if (bs->array[i].ord == 1) k = i;
}
return k;
ordenar_array(in, bs);
(*k) = generar_salida(in, bs, out);
- /* Guardo el k en el array */
- memcpy(out+leido, k, sizeof(unsigned long int));
+ /* Guardo el k y el tamaño en el array */
+ memcpy(out, k, sizeof(unsigned long int));
+ memcpy(out+sizeof(unsigned long int), &leido, sizeof(unsigned long int));
bs->len = l;
}
char *salida, *data, c;
data = malloc(sizeof(char)*pagesize);
/* Reservo lugar tambien para guardar el k */
- salida = malloc(sizeof(char)*(pagesize)+sizeof(unsigned long int));
+ salida = malloc(sizeof(char)*(pagesize)+sizeof(unsigned long int)*2);
bs = bs_create(pagesize);
fp = fopen(argv[optind], "rb");
fp_out = fopen("tmp.comp", "wb");
/* Hago el BS */
bs_solve(data, salida, bs, &k, i);
/* Le aplico el MTF */
- mtf = jacu_mtf(salida, i+sizeof(unsigned long int));
+ mtf = jacu_mtf(salida, i+sizeof(unsigned long int)*2);
for(j=0; j<i; j++)
fputc(mtf[j], fp_out);
}