+#include "bs.h"
+
/* Block Sorting Optimizado en memoria! */
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
+typedef struct _bs_decode_t_ {
+ char c;
+ unsigned long int pos;
+} t_BlockSortDecode;
+
+int _compare(const void *d1, const void *d2) {
+ t_BlockSortDecode *s1, *s2;
-typedef struct _bs_data_t_ {
- unsigned long int pos_inicial;
- unsigned long int pos_final;
- unsigned long int pos_orden;
- char ord; /* indice si esta ordenada */
-} t_BlockSortData;
+ s1 = (t_BlockSortDecode *)d1;
+ s2 = (t_BlockSortDecode *)d2;
-typedef struct _bs_t_ {
- t_BlockSortData *array;
- unsigned long int *ord;
- unsigned long int len;
-} t_BlockSort;
+ return (s1->c - s2->c);
+}
char es_menor(char *data, t_BlockSort *bs, int i, int j)
{
bs->len = l;
}
-t_BlockSort *bs_create(unsigned int len)
+void bs_restore(char *dst, char *c, unsigned long int k, unsigned long int len)
+{
+ unsigned long int i, current;
+ t_BlockSortDecode *in;
+
+ in = malloc(sizeof(t_BlockSortDecode)*len);
+
+ for(i=0; i<len; i++) {
+ in[i].c = c[i];
+ in[i].pos = i;
+ }
+
+ qsort(in, len, sizeof(t_BlockSortDecode), _compare);
+
+ current = k;
+ i=0;
+ do {
+ dst[i++] = in[current].c;
+ current = in[current].pos;
+ } while (current != k);
+ free(in);
+}
+
+t_BlockSort *bs_create(unsigned long int len)
{
t_BlockSort *tmp;
free(bs);
}
-int main(int argc, char *argv[])
-{
- char *data;
- char *salida;
- unsigned long int len, i, k;
- FILE *fp;
- char c;
- t_BlockSort *bs;
-
- if (argc != 3) {
- printf("Modo de uso : %s <archivo datos> <tamaƱo pagina>\n", argv[0]);
- return 0;
- }
-
- fp = fopen(argv[1], "r");
- len = atoi(argv[2]);
-
- data = malloc(sizeof(char)*len);
- salida = malloc(sizeof(char)*len);
-
- bs = bs_create(len);
-
- while ((c = fgetc(fp)) != EOF) {
- i = 0;
- while ((c!=EOF) && (i < len)) {
- data[i++] = c;
- c = fgetc(fp);
- }
- bs_solve(data, salida, bs, &k, i);
-
- /* XXX ACA SALIDA DEBERIA PASAR A LA SIGUIENTE ETAPA XXX */
- }
- fclose(fp);
- bs_destroy(bs);
-
- free(data);
- free(salida);
- return 0;
-}
-
-