hash createHash (uint n, uint vbits, float factor)
- { hash H = malloc (sizeof(struct shash));
+ {
int i,N;
if (n == 0) return NULL;
+ hash H = malloc (sizeof(struct shash));
N = n*factor; if (N <= n) N = n+1;
H->size = (1 << bits(N-1)) - 1;
H->bits = vbits;
destroyTrie(T);
LZT = createLZTrie(parent,letters,Node,n,text_length);
+
+ free(Node); Node = 0;
return LZT;
}
destroyNodemap(T->Node);
destroyPosition(T->TPos);
free(T->boost);
+
free(T);
}
i = 1; // shortcut for first child of root
while (i != 2*T->n-1) { // shortcut for its closing parenthesis
T->boost[T->letters[i-rank(T->pdata->bdata,i)]] = i;
- // shortcut for leftrankLZTrie
+ // shortcut for leftrankLZTrie
i = findclose(T->pdata,i)+1;
}
#endif
// frees LZTrie structure, including the owned data
+#ifdef __cplusplus
+extern "C" {
+void destroyLZTrie (lztrie T);
+}
+#else
void destroyLZTrie (lztrie T);
+#endif
// stores lztrie T on file f
+#ifdef __cplusplus
+extern "C" {
+void saveLZTrie (lztrie T, FILE *f);
+}
+#else
void saveLZTrie (lztrie T, FILE *f);
+#endif
// loads lztrie T from file f
+#ifdef __cplusplus
+extern "C" {
lztrie loadLZTrie (FILE *f);
+}
+#else
+lztrie loadLZTrie (FILE *f);
+#endif
// letter by which node i descends
byte letterLZTrie (lztrie T, trieNode i);
// go down by letter c, if possible
-#FLAGS = -g -lm
+#FLAGS = -g
FLAGS = -O9 -fomit-frame-pointer -W -Wall -Winline -DDEBUG=0 -DNDEBUG=1
all: lztrie.a
if (!P) return;
free(P->SuperBlock);
free(P->Offset);
+ free(P);
}
exit(0);
}
+ free(newt);
+
+ FILE *fp = fopen("output.lz", "wb");
+ saveLZTrie(lz, fp);
+ fclose(fp);
+ destroyLZTrie(lz);
+
+ fp = fopen("output.lz", "rb");
+ lz = loadLZTrie(fp);
+ fclose(fp);
+
+ printf("extracting:\n");
+ extract(lz, 0, n, &newt, &l);
+ for (i = 0; i < n; ++i)
+ if (newt[i] != text[i]) {
+ printf("texts differ at %lu\n", i);
+ exit(0);
+ }
+
+ free(newt);
+
+ destroyLZTrie(lz);
return 0;
}