X-Git-Url: https://git.llucax.com/z.facultad/75.06/jacu.git/blobdiff_plain/0f208e595dd865267c9a4af16164c9874f8e334e..61867dc77de42e411942e3a8cb5b652e8007f538:/src/blocksorting/bs.c diff --git a/src/blocksorting/bs.c b/src/blocksorting/bs.c index d8bd093..93b7bb5 100644 --- a/src/blocksorting/bs.c +++ b/src/blocksorting/bs.c @@ -27,18 +27,11 @@ int _compare(const void *d1, const void *d2) { int __compare(const void *d1, const void *d2) { t_BlockSortData *s1, *s2; - char i; s1 = (t_BlockSortData *)d1; s2 = (t_BlockSortData *)d2; - i = es_menor(s1->bs->data, s1->bs, s1->pos_inicial, s2->pos_inicial); - -/* if (i == 0) {*/ - /* si ambos strings son iguales, fuerzo a que d1 quede primero */ - /*return -1; - }*/ - return i; + return es_menor(s1->bs->data, s1->bs, s1->pos_inicial, s2->pos_inicial); } char es_menor(char *data, t_BlockSort *bs, int i, int j) @@ -54,7 +47,6 @@ char es_menor(char *data, t_BlockSort *bs, int i, int j) } /* Son iguales! */ - /* Hack */ return 0; } @@ -74,26 +66,16 @@ void ordenar_array(char *data, t_BlockSort *bs) qsort(bs->array, bs->len, sizeof(t_BlockSortData), __compare); } -void print_(char *data, Uint32 pos, Uint32 len) -{ - Uint32 i; - - for(i=0; ilen; i++) { - /* print_(data, bs->array[i].pos_inicial, bs->len); */ out[i] = data[bs->array[i].pos_final]; if (bs->array[i].ord == 1) k = i; } @@ -112,9 +94,8 @@ void bs_solve(char *in, char *out, t_BlockSort *bs, Uint32 *k, Uint32 leido) ordenar_array(in, bs); (*k) = generar_salida(in, bs, out); - /* Guardo el k y el tamaño en el array */ - memcpy(out, &leido, sizeof(Uint32)); - memcpy(out+sizeof(Uint32), k, sizeof(Uint32)); + /* Guardo el k y el tamaño en el array */ + memcpy(out, k, sizeof(Uint32)); bs->len = l; } @@ -139,8 +120,6 @@ void bs_restore(char *dst, char *c, Uint32 k, Uint32 len) current = in[current].sig; } while (current != k); free(in); - - if (i < len) printf("Noo %ld != %ld\n", i, len); } t_BlockSort *bs_create(Uint32 len) @@ -161,3 +140,17 @@ void bs_destroy(t_BlockSort *bs) free(bs); } +int bs_readblock(FILE *fp, char *data, Uint32 pagesize) +{ + Uint32 i=0; + + while ((!feof(fp)) && (i < pagesize)) { + data[i++] = fgetc(fp); + } + + /* Saco un EOF que lee de mas */ + if (i