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);
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);
}
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)
qsort(bs->array, bs->len, sizeof(t_BlockSortData), __compare);
}
-void print_(char *data, Uint32 pos, Uint32 len)
-{
- Uint32 i;
-
- for(i=0; i<len; i++)
- printf("%c", data[(pos+i)%len]);
- printf("\n");
-}
-
int generar_salida(char *data, t_BlockSort *bs, char *salida)
{
Uint32 i, k;
k=-1;
for(i=0; i<bs->len; 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;
}
/* Guardo el k y el tamaƱo en el array */
memcpy(out, &leido, sizeof(Uint32));
memcpy(out+sizeof(Uint32), k, sizeof(Uint32));
- printf("%ld -> %ld\n", *k, *(Uint32 *)(out+sizeof(Uint32)));
bs->len = l;
}
for(i=0; i<len; i++) {
in[i].c = c[i];
- in[i].pos = i;
+ in[i].sig = i;
}
qsort(in, len, sizeof(t_BlockSortDecode), _compare);
i=0;
do {
dst[i++] = in[current].c;
- printf("(%c)", dst[i-1]);
- current = in[current].pos;
- printf("[%d]", current);
+ current = in[current].sig;
} while (current != k);
- printf("\n");
free(in);
}