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);
}
int __compare(const void *d1, const void *d2) {
t_BlockSortData *s1, *s2;
+ char i;
s1 = (t_BlockSortData *)d1;
s2 = (t_BlockSortData *)d2;
- return es_menor(s1->bs->data, s1->bs, s1->pos_inicial, s2->pos_inicial);
+ 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;
}
char es_menor(char *data, t_BlockSort *bs, int i, int j)
}
/* Son iguales! */
+ /* Hack */
return 0;
}
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;
- current = in[current].pos;
+ 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)
free(z);
}
- printf("Total Bytes read = %ld\n", total);
/* Limpiando */
fclose(fp);
fclose(fp_out);
block_size = 0;
fread(&block_size, sizeof(Uint32), 1, fp_in);
if (block_size > 0) {
- printf("PageSize = %ld\n", block_size);
fread(&z_len, sizeof(int), 1, fp_in);
z = malloc(sizeof(char)*z_len);
fread(z, z_len, sizeof(char), fp_in);
free(block);
free(orig);
free(mtf);
+ free(z);
}
}
fclose(fp_in);