}
/* Son iguales! */
- /* Hack */
return 0;
}
bs->len = l;
}
+void print_v(t_BlockSortDecode *d, size_t len)
+{
+ size_t i;
+
+ for(i=0; i<len; i++)
+ printf("(%ld)", d[i].sig);
+ printf("\n");
+ for(i=0; i<len; i++)
+ printf("(%d)", d[i].c);
+ printf("\n");
+}
+
void bs_restore(char *dst, char *c, Uint32 k, Uint32 len)
{
Uint32 i, current;
in[i].sig = i;
}
+ /*printf("Antes de QSort\n");
+ print_v(in, len);*/
qsort(in, len, sizeof(t_BlockSortDecode), _compare);
+ /*printf("Despues de QSort\n");
+ print_v(in, len);*/
current = k;
i=0;
#include "bs.h"
+void _print_(char *s, size_t len)
+{
+ size_t i;
+ for(i=0; i<len; i++)
+ printf("(%d)", s[i]);
+ printf("\n");
+}
+
int main(int argc, char *argv[])
{
char *data;
c = fgetc(fp);
total++;
}
+ /* lleno data mano! */
+ srand(time(NULL));
+ {
+ size_t jj;
+ for(jj=0; jj<i;jj++)
+ data[jj] = rand()%255;
+ }
+ printf("Leido : ");
+ _print_(data, i);
bs_solve(data, salida, bs, &k, i);
/* XXX ACA SALIDA DEBERIA PASAR A LA SIGUIENTE ETAPA XXX */
if (argc == 3) {
- printf("BS : %s -> %ld\n", salida, k);
- bs_restore(orig, salida, k, i);
- printf("Orig : %s\n", orig);
+ printf("BS : %ld ", k);
+ _print_(salida+8, i);
+ bs_restore(orig, salida+sizeof(Uint32)*2, k, i);
+ printf("Orig : ");
+ _print_(orig, i);
} else
fwrite(salida, 1, i, stdout);
}
/****privadas*****/
int no_pertenece(char *z, char c, int len);
-void pop_front(char *z, int pos);
+void pop_front(char *z, unsigned int pos);
int get_pos(char *z, int len, char c);
/****fin privadas******/
return pos;
}
-char *jacu_mtf_inv(char *z, char *pos, int len)
+char *jacu_mtf_inv(char *z, unsigned char *pos, int len)
{
char *datos;
int i;
datos = (char*)malloc(sizeof(char)*len);
for(i=0; i<len; i++){
- datos[i] = z[(size_t)pos[i]];
- pop_front(z, pos[i]);
+ datos[i] = z[(unsigned int)pos[i]];
+ if (pos[i] != 0)
+ pop_front(z, (unsigned int)pos[i]);
}
return datos;
}
return -1;
}
-void pop_front(char *z, int pos)
+void pop_front(char *z, unsigned int pos)
{
char aux;
int i=0;
-
+
+ if (pos > 255) printf("pos > = %u\n", pos);
+ if (pos < 0u) printf("pos < = %d\n", pos);
aux = z[pos];
for(i=pos; i>0; i--)
z[i]=z[i-1];
char *jacu_mtf(char *datos, int len, char **_z, int *z_len);
-char *jacu_mtf_inv(char *z, char *pos, int len);
+char *jacu_mtf_inv(char *z, unsigned char *pos, int len);
char *jacu_buscar_z(char* datos, int len, int *size);