projects
/
SXSI
/
TextCollection.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f3f5b4a
)
Fixed a few mem leaks, and C++ compatibility
author
nvalimak
<nvalimak@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Fri, 29 May 2009 14:35:20 +0000
(14:35 +0000)
committer
nvalimak
<nvalimak@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Fri, 29 May 2009 14:35:20 +0000
(14:35 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/TextCollection@415
3cdefd35
-fc62-479d-8e8d-
bae585ffb9ca
lzindex/hash.c
patch
|
blob
|
history
lzindex/lztrie.c
patch
|
blob
|
history
lzindex/lztrie.h
patch
|
blob
|
history
lzindex/makefile
patch
|
blob
|
history
lzindex/position.c
patch
|
blob
|
history
lzindex/test.c
patch
|
blob
|
history
diff --git
a/lzindex/hash.c
b/lzindex/hash.c
index
272fbee
..
754f327
100644
(file)
--- a/
lzindex/hash.c
+++ b/
lzindex/hash.c
@@
-8,9
+8,10
@@
hash createHash (uint n, uint vbits, float factor)
hash createHash (uint n, uint vbits, float factor)
- {
hash H = malloc (sizeof(struct shash));
+ {
int i,N;
if (n == 0) return NULL;
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;
N = n*factor; if (N <= n) N = n+1;
H->size = (1 << bits(N-1)) - 1;
H->bits = vbits;
diff --git
a/lzindex/lztrie.c
b/lzindex/lztrie.c
index
0a4c56b
..
7e4453d
100644
(file)
--- a/
lzindex/lztrie.c
+++ b/
lzindex/lztrie.c
@@
-59,6
+59,8
@@
lztrie buildLZTrie(byte *text, byte s, uint text_length)
destroyTrie(T);
LZT = createLZTrie(parent,letters,Node,n,text_length);
destroyTrie(T);
LZT = createLZTrie(parent,letters,Node,n,text_length);
+
+ free(Node); Node = 0;
return LZT;
}
return LZT;
}
@@
-73,6
+75,7
@@
void destroyLZTrie(lztrie T)
destroyNodemap(T->Node);
destroyPosition(T->TPos);
free(T->boost);
destroyNodemap(T->Node);
destroyPosition(T->TPos);
free(T->boost);
+
free(T);
}
free(T);
}
@@
-132,7
+135,7
@@
lztrie loadLZTrie (FILE *f)
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;
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;
}
i = findclose(T->pdata,i)+1;
}
diff --git
a/lzindex/lztrie.h
b/lzindex/lztrie.h
index
691a2aa
..
f70c50e
100644
(file)
--- a/
lzindex/lztrie.h
+++ b/
lzindex/lztrie.h
@@
-45,11
+45,29
@@
extern "C" {
#endif
// frees LZTrie structure, including the owned data
#endif
// frees LZTrie structure, including the owned data
+#ifdef __cplusplus
+extern "C" {
+void destroyLZTrie (lztrie T);
+}
+#else
void destroyLZTrie (lztrie T);
void destroyLZTrie (lztrie T);
+#endif
// stores lztrie T on file f
// stores lztrie T on file f
+#ifdef __cplusplus
+extern "C" {
+void saveLZTrie (lztrie T, FILE *f);
+}
+#else
void saveLZTrie (lztrie T, FILE *f);
void saveLZTrie (lztrie T, FILE *f);
+#endif
// loads lztrie T from file f
// loads lztrie T from file f
+#ifdef __cplusplus
+extern "C" {
lztrie loadLZTrie (FILE *f);
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
// letter by which node i descends
byte letterLZTrie (lztrie T, trieNode i);
// go down by letter c, if possible
diff --git
a/lzindex/makefile
b/lzindex/makefile
index
c2d688b
..
c943bcd
100644
(file)
--- a/
lzindex/makefile
+++ b/
lzindex/makefile
@@
-1,4
+1,4
@@
-#FLAGS = -g
-lm
+#FLAGS = -g
FLAGS = -O9 -fomit-frame-pointer -W -Wall -Winline -DDEBUG=0 -DNDEBUG=1
all: lztrie.a
FLAGS = -O9 -fomit-frame-pointer -W -Wall -Winline -DDEBUG=0 -DNDEBUG=1
all: lztrie.a
diff --git
a/lzindex/position.c
b/lzindex/position.c
index
984a8d4
..
d9d552d
100644
(file)
--- a/
lzindex/position.c
+++ b/
lzindex/position.c
@@
-136,6
+136,7
@@
void destroyPosition(position P)
if (!P) return;
free(P->SuperBlock);
free(P->Offset);
if (!P) return;
free(P->SuperBlock);
free(P->Offset);
+ free(P);
}
}
diff --git
a/lzindex/test.c
b/lzindex/test.c
index
c0d2694
..
55ca075
100644
(file)
--- a/
lzindex/test.c
+++ b/
lzindex/test.c
@@
-20,5
+20,27
@@
int main()
exit(0);
}
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;
}
return 0;
}