Skip to content

Commit

Permalink
SuffixArray passes rudimentary test
Browse files Browse the repository at this point in the history
  • Loading branch information
dgboy2000 committed Feb 16, 2012
1 parent a68f1bc commit 750d145
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion compress.cpp
Expand Up @@ -467,9 +467,20 @@ class SuffixArray {
SuffixArray(int *data, int n);
~SuffixArray() { free(sa); free(s); }

void print();

int *getSuffixArray();
};

void SuffixArray::print() {
for (int i=0; i<(n+3); ++i) {
printf("s[%d] = %d\n", i, s[i]);
}
for (int i=0; i<n; ++i) {
printf("sa[%d] = %d\n", i, sa[i]);
}
}

SuffixArray::SuffixArray(vector<int> data) {
n = data.size();

Expand All @@ -489,7 +500,7 @@ SuffixArray::SuffixArray(int *data, int _n) {
n = _n;

s = (int *) calloc(n + 3, sizeof(int));
memcpy(s, data, n);
memcpy(s, data, n * (sizeof(int)));

prepareSuffixArray();
}
Expand Down Expand Up @@ -590,8 +601,10 @@ void test_suffix_arrays() {
int true_suffixes[] = {8, 0, 7, 1, 6, 2, 5, 3, 4};

SuffixArray sa(word, len);
sa.print();
int *suffixes = sa.getSuffixArray();


for (int i=0; i<len; ++i) {
if (suffixes[i] == true_suffixes[i]) printf("CORRECT: True suffix SA[%d] = %d\n", i, suffixes[i]);
else printf("ERROR: True suffix SA[%d] is %d but found %d\n", i, true_suffixes[i], suffixes[i]);
Expand Down

0 comments on commit 750d145

Please sign in to comment.