Skip to content

Commit

Permalink
Small changes (valgrind)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipelouza committed Jun 14, 2018
1 parent f69e448 commit dc30328
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 76 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,6 @@ Please, if you use this tool in an academic setting cite the following paper:

\[4\] Nong, G., Practical linear-time O(1)-workspace suffix sorting for constant alphabets, ACM Trans. Inform. Syst., vol. 31, no. 3, pp. 1–15, 2013

## Thanks:

Thanks to Giovanni Manzini by helpful suggestions and debugging.
4 changes: 2 additions & 2 deletions experiments/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CC = gcc
CFLAGS += -Wall
CFLAGS += -Wall
#CFLAGS += -g -O0
CFLAGS += -D_FILE_OFFSET_BITS=64 -m64 -O3 -fomit-frame-pointer -Wno-char-subscripts

Expand Down Expand Up @@ -59,4 +59,4 @@ run:
./gsais $(DIR) $(INPUT) $(K) $(MODE) $(LCP_COMPUTE) $(DA_COMPUTE) $(BWT_COMPUTE) $(CHECK) $(OUTPUT)

valgrind:
valgrind --tool=memcheck --leak-check=full --track-origins=yes ./gsais $(DIR) $(INPUT) $(K) $(MODE) $(LCP_COMPUTE) $(DA_COMPUTE) $(BWT_COMPUTE) $(CHECK) $(OUTPUT)
valgrind -q --tool=memcheck --leak-check=full --track-origins=yes --show-leak-kinds=all ./gsais $(DIR) $(INPUT) $(K) $(MODE) $(LCP_COMPUTE) $(DA_COMPUTE) $(BWT_COMPUTE) $(CHECK) $(OUTPUT)
6 changes: 3 additions & 3 deletions experiments/lib/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int_text* cat_int(unsigned char** R, int k, int_t *n){
}

str_int[l++]=0;
if(*n>l){
if(*n>l){
str_int = (int_text*) realloc(str_int, (l)*sizeof(int_text));
printf("N = %" PRIdN "\n", l);
}
Expand Down Expand Up @@ -152,8 +152,8 @@ unsigned char* cat_char(unsigned char** R, int k, int_t *n){
}

str[l++]=0;
if(*n>l){
str = (unsigned char*) realloc(str, (l)*sizeof(unsigned char));
if(*n>l){
str = (unsigned char*) realloc(str, (l+1)*sizeof(unsigned char));
printf("N = %" PRIdN "\n", l);
}
*n = l;
Expand Down
62 changes: 32 additions & 30 deletions gsacak.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
const uint_t EMPTY_k=((uint_t)1)<<(sizeof(uint_t)*8-1);

// get s[i] at a certain level

//#if M64 && LARGE_ALPHABET==0
#define chr(i) (cs==sizeof(int_t)?((int_t*)s)[i]:(cs==sizeof(int_text)?((int_text*)s)[i]:((unsigned char *)s)[i]))
//define chr(i) (cs==sizeof(int_t)?((int_t*)s)[i]:((unsigned char *)s)[i])

#define true 1
#define false 0
Expand Down Expand Up @@ -638,7 +635,7 @@ void induceSAl0_generalized_LCP_DA(uint_t *SA, int_t *LCP, int_t *DA,

if(LCP[i]==I_MIN){ //is a L/S-seam position
int_t l=0;
if(SA[bkt[chr(SA[i])]-1]<n-1)
if(SA[bkt[chr(SA[i])]-1]<n-1)
while(chr(SA[i]+l)==chr(SA[bkt[chr(SA[i])]-1]+l))++l;
LCP[i]=l;
}
Expand Down Expand Up @@ -755,44 +752,44 @@ void induceSAs0_generalized_LCP_DA(uint_t *SA, int_t* LCP, int_t* DA,
if(SA[i]>0) {
j=SA[i]-1;
if(chr(j)<=chr(j+1) && bkt[chr(j)]<i)// induce S-type
if(chr(j)!=separator){
SA[bkt[chr(j)]]=j;
DA[bkt[chr(j)]]=DA[i];
if(chr(j)!=separator){
SA[bkt[chr(j)]]=j;
DA[bkt[chr(j)]]=DA[i];

#if RMQ_S == 1
#if RMQ_S == 1
if(LCP[bkt[chr(j)]+1]>=0)
LCP[bkt[chr(j)]+1]=M[chr(j)]+1;

if(LCP[bkt[chr(j)]]>0)
LCP[bkt[chr(j)]]=I_MAX;

#elif RMQ_S == 2
int_t min = I_MAX, end = top-1;
#elif RMQ_S == 2
int_t min = I_MAX, end = top-1;

int_t last=last_occ[chr(j)];
while(STACK[end].idx<=last) end--;
int_t last=last_occ[chr(j)];
while(STACK[end].idx<=last) end--;

min=STACK[(end+1)].lcp;
last_occ[chr(j)] = i;
min=STACK[(end+1)].lcp;
last_occ[chr(j)] = i;

if(LCP[bkt[chr(j)]+1]>=0)
LCP[bkt[chr(j)]+1]=min+1;
#endif
if(LCP[bkt[chr(j)]+1]>=0)
LCP[bkt[chr(j)]+1]=min+1;
#endif


#if RMQ_S == 1
M[chr(j)] = I_MAX;
#endif
#if RMQ_S == 1
M[chr(j)] = I_MAX;
#endif

bkt[chr(j)]--;
bkt[chr(j)]--;

if(SA[bkt[chr(j)]]!=U_MAX) {//L/S-seam
int_t l=0;
while(chr(SA[bkt[chr(j)]+1]+l)==chr(SA[bkt[chr(j)]]+l))++l;
LCP[bkt[chr(j)]+1]=l;
}
}
}
if(SA[bkt[chr(j)]]!=U_MAX) {//L/S-seam
int_t l=0;
while(chr(SA[bkt[chr(j)]+1]+l)==chr(SA[bkt[chr(j)]]+l))++l;
LCP[bkt[chr(j)]+1]=l;
}
}
}

if(LCP[i]<0) LCP[i]=0;
#if RMQ_S == 1
Expand Down Expand Up @@ -2505,8 +2502,10 @@ int sacak_int(int_text *s, uint_t *SA, uint_t n, uint_t k){
int gsacak(unsigned char *s, uint_t *SA, int_t *LCP, int_t *DA, uint_t n){
if((s == NULL) || (SA == NULL) || (n < 0)) return -1;

int i;
for(i=0; i<n; i++) SA[i]=LCP[i]=DA[i]=0;

#if EMPTY_STRING
int i;
for(i=0; i<n-1; i++) if(s[i]==1 && s[i+1]==1) return -2;
#endif

Expand All @@ -2523,6 +2522,9 @@ int gsacak(unsigned char *s, uint_t *SA, int_t *LCP, int_t *DA, uint_t n){
int gsacak_int(int_text *s, uint_t *SA, int_t *LCP, int_t *DA, uint_t n, uint_t k){
if((s == NULL) || (SA == NULL) || (n < 0)) return -1;

int i;
for(i=0; i<n; i++) SA[i]=LCP[i]=DA[i]=0;

if((LCP == NULL) && (DA == NULL))
return gSACA_K((uint_t*)s, SA, n, k, sizeof(int_text), 1, 0);
else if (DA == NULL)
Expand Down
44 changes: 20 additions & 24 deletions gsacak.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,60 +51,56 @@
#define I_MAX INT64_MAX
#define I_MIN INT64_MIN
#else
typedef int32_t int_t;
typedef uint32_t uint_t;
typedef int32_t int_t;
typedef uint32_t uint_t;
#define PRIdN PRId32
#define U_MAX UINT32_MAX
#define I_MAX INT32_MAX
#define I_MIN INT32_MIN
#endif

/*! @option type of s[0,n-1] for integer alphabets
* @constraint sizeof(int_t) >= sizeof(int_text)
*
* @constraint sizeof(int_t) >= sizeof(int_text)
*/
typedef uint32_t int_text; //4N bytes for s[0..n-1]
typedef uint32_t int_text; //4N bytes for s[0..n-1]
#define PRIdT PRIu32

/******************************************************************************/

/** @brief computes the suffix array of string s[0..n-1]
*
* @param s input string with s[n-1]=0
* @param SA suffix array
* @param n string length
* @return -1 if an error occured, otherwise the depth of the recursive calls.
* @param s input string with s[n-1]=0
* @param SA suffix array
* @param n string length
* @return -1 if an error occured, otherwise the depth of the recursive calls.
*/
int sacak(unsigned char *s, uint_t *SA, uint_t n);

/** @brief computes the suffix array of string s[0..n-1]
* @param k alphabet size
*
* @param k alphabet size
*/
int sacak_int(int_text *s, uint_t *SA, uint_t n, uint_t k);

/******************************************************************************/

/** @brief Computes the suffix array SA (LCP, DA) of T^cat in s[0..n-1]
*
* @param s input concatenated string, using separators s[i]=1 and with s[n-1]=0
* @param SA suffix array
* @param LCP LCP array
* @param DA Document array
* @param n string length
*
* @return depth of the recursive calls.
* @param s input concatenated string, using separators s[i]=1 and with s[n-1]=0
* @param SA suffix array
* @param LCP LCP array
* @param DA Document array
* @param n string length
*
* @return depth of the recursive calls.
*/
int gsacak(unsigned char *s, uint_t *SA, int_t *LCP, int_t *DA, uint_t n);

/** @brief Computes the suffix array SA (LCP, DA) of T^cat in s[0..n-1]
*
* @param s input concatenated string, using separators s[i]=1 and with s[n-1]=0
* @param SA suffix array
* @param LCP LCP array
* @param DA Document array
* @param n string length
* @param K alphabet size
*
* @return depth of the recursive calls.
* @param s input concatenated string, with s[n-1]=0
* @param K alphabet size
*/
int gsacak_int(int_text *s, uint_t *SA, int_t *LCP, int_t *DA, uint_t n, uint_t k);

Expand Down
3 changes: 1 addition & 2 deletions gsais.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "gsais.h"

//#if M64 && LARGE_ALPHABET==0
// get s[i] at a certain level
#define chr(i) (cs==sizeof(int_t)?((int_t*)s)[i]:(cs==sizeof(int_text)?((int_text*)s)[i]:((unsigned char *)s)[i]))
//#define chr(i) (cs==sizeof(int_t)?((int_t*)s)[i]:((unsigned char *)s)[i])

#define tget(i) ( (t[(i)/8]&mask[(i)%8]) ? 1 : 0 )
#define tset(i, b) t[(i)/8]=(b) ? (mask[(i)%8]|t[(i)/8]) : ((~mask[(i)%8])&t[(i)/8])
Expand Down
25 changes: 10 additions & 15 deletions gsais.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@
#endif

#if M64
typedef int64_t int_t;
typedef uint64_t uint_t;
typedef int64_t int_t;
typedef uint64_t uint_t;
#define PRIdN PRId64
#define U_MAX UINT64_MAX
#define I_MAX INT64_MAX
#define I_MIN INT64_MIN
#else
typedef int32_t int_t;
typedef uint32_t uint_t;
typedef int32_t int_t;
typedef uint32_t uint_t;
#define PRIdN PRId32
#define U_MAX UINT32_MAX
#define I_MAX INT32_MAX
#define I_MIN INT32_MIN
#endif


/*! @option type of s[0,n-1] for integer alphabets
* @constraint sizeof(int_t) >= sizeof(int_text)
*
* @constraint sizeof(int_t) >= sizeof(int_text)
*/
typedef uint32_t int_text; //4N bytes for s[0..n-1]
typedef uint32_t int_text; //4N bytes for s[0..n-1]
#define PRIdT PRIu32

/******************************************************************************/
Expand All @@ -78,6 +78,7 @@ typedef uint32_t int_text; //4N bytes for s[0..n-1]
int sais(unsigned char *s, uint_t *SA, uint_t n);

/** @brief computes the suffix array of string s[0..n-1]
*
* @param k alphabet size
*/
int sais_int(int_text *s, uint_t *SA, uint_t n, uint_t k);
Expand All @@ -91,21 +92,15 @@ int sais_int(int_text *s, uint_t *SA, uint_t n, uint_t k);
* @param LCP LCP array
* @param DA Document array
* @param n string length
*
*
* @return depth of the recursive calls.
*/
int gsais(unsigned char *s, uint_t *SA, int_t *LCP, int_t *DA, uint_t n);

/** @brief Computes the suffix array SA (LCP, DA) of T^cat in s[0..n-1]
*
* @param s input concatenated string, using separators s[i]=1 and with s[n-1]=0
* @param SA suffix array
* @param LCP LCP array
* @param DA Document array
* @param n string length
* @param s input concatenated string, with s[n-1]=0
* @param K alphabet size
*
* @return depth of the recursive calls.
*/
int gsais_int(int_text *s, uint_t *SA, int_t *LCP, int_t *DA, uint_t n, uint_t k);

Expand Down

0 comments on commit dc30328

Please sign in to comment.