X-Git-Url: https://git.llucax.com/z.facultad/75.06/jacu.git/blobdiff_plain/9bf3b2c0c781aae449a69e32f95360f569702cdc..fef03d51453b511c6355d53f1c4f5d06f1e8519e:/src/blocksorting/bs.c diff --git a/src/blocksorting/bs.c b/src/blocksorting/bs.c index 6231d05..a1e14a2 100644 --- a/src/blocksorting/bs.c +++ b/src/blocksorting/bs.c @@ -1,12 +1,13 @@ #include "bs.h" #include +#include /* Block Sorting Optimizado en memoria! */ typedef struct _bs_decode_t_ { char c; - Uint32 pos; + Uint32 sig; } t_BlockSortDecode; char es_menor(char *data, t_BlockSort *bs, int i, int j); @@ -17,6 +18,11 @@ int _compare(const void *d1, const void *d2) { s1 = (t_BlockSortDecode *)d1; s2 = (t_BlockSortDecode *)d2; + /* Hack si es el mismo caracter, dejo como mejor la de menor sig */ + if (s1->c == s2->c) { + return (s1->sig - s2->sig); + } + return (s1->c - s2->c); } @@ -26,7 +32,7 @@ int __compare(const void *d1, const void *d2) { s1 = (t_BlockSortData *)d1; s2 = (t_BlockSortData *)d2; - return es_menor(s1->bs->data, s1->bs, s1->pos_inicial, s2->pos_inicial); + 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) @@ -61,26 +67,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; } @@ -99,9 +95,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; } @@ -114,7 +109,7 @@ void bs_restore(char *dst, char *c, Uint32 k, Uint32 len) for(i=0; i= pagesize) return; /* No pude! */ + + data[i++] = ' '; + data[i++] = ' '; + data[i++] = ' '; + data[i++] = ' '; + data[i++] = ' '; + data[i++] = ' '; + data[i++] = ' '; + data[i++] = ' '; + data[i++] = ' '; + + (*j) += 9; +} + +int bs_readblock(FILE *fp, char *data, Uint32 pagesize) +{ + Uint32 i=0; + char c; + while ((!feof(fp)) && (i < pagesize)) { + c = fgetc(fp); +/* if (c != '\n')*/ + if (c == '\0') { + /* Debo encodear el \0 para que no complique */ + data[i++] = 0x00; + data[i++] = 0xFF; + } + if (isupper(c)) { + data[i++] = '\0'; + data[i++] = tolower(c); + } else { + data[i++] = c; + } +/* else + bs_EOL(data, pagesize, &i);*/ + } + + /* Saco un EOF que lee de mas */ + if (i