Skip to content

Commit

Permalink
realloc y with tvsbs-w*
Browse files Browse the repository at this point in the history
still fail though
  • Loading branch information
rurban committed Nov 26, 2024
1 parent ee4f22c commit d52e634
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
4 changes: 2 additions & 2 deletions source/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@ const struct algo ALGOS[] = {
[_TSA_Q2] = {_TSA_Q2, FAIL, "tsa-q2", "word-wise popcount q=2", 2, 0}, // 2<=m<64
[_TSO5] = {_TSO5, OK, "tso5", "optimized word-wise popcount", 2, 0}, // 2<=m<64
[_TUNEDBM] = {_TUNEDBM, OK, "tunedbm", "Tuned Boyer-Moore", 0, 0},
[_TVSBS_W2] = {_TVSBS_W2, RNDCRASH, "tvsbs-w2", "TVSBS with Multiple Sliding Windows", 0, 0},
[_TVSBS_W2] = {_TVSBS_W2, FAIL, "tvsbs-w2", "TVSBS with Multiple Sliding Windows", 0, 0},
[_TVSBS_W4] = {_TVSBS_W4, FAIL, "tvsbs-w4", "TVSBS with Multiple Sliding Windows", 2, 0}, // n>=m+2
[_TVSBS_W6] = {_TVSBS_W6, FAIL, "tvsbs-w6", "TVSBS with Multiple Sliding Windows", 2, 0}, // n>=m+2
[_TVSBS_W6] = {_TVSBS_W6, RNDCRASH, "tvsbs-w6", "TVSBS with Multiple Sliding Windows", 2, 0}, // n>=m+2
[_TVSBS_W8] = {_TVSBS_W8, FAIL, "tvsbs-w8", "TVSBS with Multiple Sliding Windows", 2, 0}, // n>=m+2
[_WFR] = {_WFR, OK, "wfr", "Weak Factor Recognizer", 0, 0},
[_WFR2] = {_WFR2, OK, "wfr2", "Weak Factor Recognizer (m>=2)", 2, 0},
Expand Down
8 changes: 6 additions & 2 deletions source/algos/tvsbs-w2.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* download the tool at: http://www.dmi.unict.it/~faro/smart/
*
* Optimized TVSBS algorithm.
* Requires 2m space after y.
*/

//#define MIN_M 2
Expand All @@ -37,14 +38,16 @@ void TVSBSpreBrBc(unsigned char *x, int m, int brBc[SIGMA][SIGMA]) {
brBc[x[m - 1]][a] = 1;
}

int search(unsigned char *x, int m, unsigned char *y, int n) {
int search(unsigned char *x, int m, unsigned char *_y, int n) {
int count, i, s1, s2;
int BrBcR[SIGMA][SIGMA], BrBcL[SIGMA][SIGMA];
unsigned char firstch, lastch;
if (m >= XSIZE)
return search_large(x, m, y, n);
return search_large(x, m, _y, n);

BEGIN_PREPROCESSING
unsigned char *y = malloc(n + 2*m);
memcpy(y, _y, n);
unsigned char xr[XSIZE];
for (i = 0; i < m; i++)
xr[i] = x[m - 1 - i];
Expand Down Expand Up @@ -81,6 +84,7 @@ int search(unsigned char *x, int m, unsigned char *y, int n) {
s1 += BrBcR[y[s1 + m]][y[s1 + mp1]];
s2 -= BrBcL[y[s2 - 1]][y[s2 - 2]];
}
free(y);
END_SEARCHING
return count;
}
12 changes: 8 additions & 4 deletions source/algos/tvsbs-w4.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
* Note: Broken!
* Constraints: requires n >= m + 2, and m>=2
* Requires 2m space after y.
*/

#define MIN_M 2
Expand All @@ -40,20 +41,22 @@ void TVSBSpreBrBc(unsigned char *x, int m, int brBc[SIGMA][SIGMA]) {
brBc[x[m - 1]][a] = 1;
}

int search(unsigned char *x, int m, unsigned char *y, int n) {
int search(unsigned char *x, int m, unsigned char *_y, int n) {
int count, i, s1, s2, s3, s4;
int l1, l2, l3, l4;
int BrBcR[SIGMA][SIGMA], BrBcL[SIGMA][SIGMA];
unsigned char firstch, lastch;
unsigned char xr[XSIZE];
if (n < m + 2)
return search_small(x, m, y, n);
return search_small(x, m, _y, n);
if (m < 2)
return search_small(x, m, y, n);
return search_small(x, m, _y, n);
if (m >= XSIZE)
return search_large(x, m, y, n);
return search_large(x, m, _y, n);

BEGIN_PREPROCESSING
unsigned char *y = malloc(n + 2*m);
memcpy(y, _y, n);
assert(m < XSIZE);
for (i = 0; i < m; i++)
xr[i] = x[m - 1 - i];
Expand Down Expand Up @@ -109,6 +112,7 @@ int search(unsigned char *x, int m, unsigned char *y, int n) {
s3 += BrBcR[y[s3 + m]][y[s3 + mp1]];
s4 -= BrBcL[y[s4 - 1]][y[s4 - 2]];
}
free(y);
END_SEARCHING
//y[n] = '\0';
return count;
Expand Down
12 changes: 8 additions & 4 deletions source/algos/tvsbs-w6.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
* Note: Broken!
* Constraints: requires n >= m + 2, and m>=2
* Requires 2m space after y.
*/

#define MIN_M 2
Expand All @@ -40,19 +41,21 @@ void TVSBSpreBrBc(unsigned char *x, int m, int brBc[SIGMA][SIGMA]) {
brBc[x[m - 1]][a] = 1;
}

int search(unsigned char *x, int m, unsigned char *y, int n) {
int search(unsigned char *x, int m, unsigned char *_y, int n) {
int count, i, s1, s2, s3, s4, s5, s6;
int l1, l2, l3, l4, l5, l6;
int BrBcR[SIGMA][SIGMA], BrBcL[SIGMA][SIGMA];

if (n < m + 2)
return search_small(x, m, y, n);
return search_small(x, m, _y, n);
if (m < 2)
return search_small(x, m, y, n);
return search_small(x, m, _y, n);
if (m >= XSIZE)
return search_large(x, m, y, n);
return search_large(x, m, _y, n);

BEGIN_PREPROCESSING
unsigned char *y = malloc(n + 2*m);
memcpy(y, _y, n);
unsigned char xr[XSIZE];
unsigned char c, lastch, firstch;
assert(m < XSIZE);
Expand Down Expand Up @@ -142,6 +145,7 @@ int search(unsigned char *x, int m, unsigned char *y, int n) {
s6 -= BrBcL[y[s6 - 1]][y[s6 - 2]];
}
//y[n] = '\0';
free(y);
END_SEARCHING
return count;
}
12 changes: 8 additions & 4 deletions source/algos/tvsbs-w8.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
* Note: Flaky tests with m=32,n=64 (off-by-one count)
* Constraints: requires n >= m + 2, and m>=2 and m<XSIZE
* Requires 2m space after y.
*/

#define MIN_M 2
Expand All @@ -40,13 +41,13 @@ void TVSBSpreBrBc(unsigned char *x, int m, int brBc[SIGMA][SIGMA]) {
brBc[x[m - 1]][a] = 1;
}

int search(unsigned char *x, int m, unsigned char *y, int n) {
int search(unsigned char *x, int m, unsigned char *_y, int n) {
if (n < m + 2)
return search_small(x, m, y, n);
return search_small(x, m, _y, n);
if (m < 2)
return search_small(x, m, y, n);
return search_small(x, m, _y, n);
if (m >= XSIZE)
return search_large(x, m, y, n);
return search_large(x, m, _y, n);

int count, i, s1, s2, s3, s4, s5, s6, s7, s8;
int l1, l2, l3, l4, l5, l6, l7, l8;
Expand All @@ -55,6 +56,8 @@ int search(unsigned char *x, int m, unsigned char *y, int n) {
unsigned char c;

BEGIN_PREPROCESSING
unsigned char *y = malloc(n + 2*m);
memcpy(y, _y, n);
assert(m < XSIZE);
for (i = 0; i < m; i++)
xr[i] = x[m - 1 - i];
Expand Down Expand Up @@ -141,6 +144,7 @@ int search(unsigned char *x, int m, unsigned char *y, int n) {
s7 += BrBcR[y[s7 + m]][y[s7 + mPlus1]];
s8 -= BrBcL[y[s8 - 1]][y[s8 - 2]];
}
free(y);
END_SEARCHING
return count;
}

0 comments on commit d52e634

Please sign in to comment.