X-Git-Url: https://git.llucax.com/z.facultad/75.06/jacu.git/blobdiff_plain/de5da6745aa448b96eee01fbd9df0575629678b9..a5aecc71c7b3edd7a7b150b2d1becae044d5718f:/src/blocksorting/bs.c diff --git a/src/blocksorting/bs.c b/src/blocksorting/bs.c index 21e1ff6..fa14152 100644 --- a/src/blocksorting/bs.c +++ b/src/blocksorting/bs.c @@ -1,11 +1,12 @@ #include "bs.h" +#include /* Block Sorting Optimizado en memoria! */ typedef struct _bs_decode_t_ { char c; - unsigned long int pos; + Uint32 sig; } t_BlockSortDecode; char es_menor(char *data, t_BlockSort *bs, int i, int j); @@ -16,6 +17,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); } @@ -25,12 +31,12 @@ 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) { - unsigned long int pi, pj, k; + Uint32 pi, pj, k; for(k=0; klen; k++) { pi = (i+k)%bs->len; @@ -60,28 +66,23 @@ void ordenar_array(char *data, t_BlockSort *bs) qsort(bs->array, bs->len, sizeof(t_BlockSortData), __compare); } -void print_(char *data, unsigned long int pos, unsigned long int len) +int generar_salida(char *data, t_BlockSort *bs, char *salida) { - unsigned long int i; + Uint32 i, k; + char *out; - for(i=0; ilen; 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; } -void bs_solve(char *in, char *out, t_BlockSort *bs, unsigned long int *k, unsigned int leido) +void bs_solve(char *in, char *out, t_BlockSort *bs, Uint32 *k, Uint32 leido) { unsigned int l; l = bs->len; @@ -93,19 +94,22 @@ void bs_solve(char *in, char *out, t_BlockSort *bs, unsigned long int *k, unsign 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)); bs->len = l; } -void bs_restore(char *dst, char *c, unsigned long int k, unsigned long int len) +void bs_restore(char *dst, char *c, Uint32 k, Uint32 len) { - unsigned long int i, current; + Uint32 i, current; t_BlockSortDecode *in; in = malloc(sizeof(t_BlockSortDecode)*len); for(i=0; i