Skip to content

Commit

Permalink
Added typedef to array DA[0..n-1]
Browse files Browse the repository at this point in the history
  • Loading branch information
felipelouza committed Jun 28, 2018
1 parent e01c4fd commit 723ee0c
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 121 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ One can change to 64 bits integers adding -DM64=1 in the compilation or by chang

One can set the size (in bytes) of s\[0..n-1\] for integer alphabets: [link](https://github.com/felipelouza/gsa-is/blob/master/gsacak.h#L66)

**Document array:**

One can set the size (in bytes) of DA\[0..n-1\]: [link](https://github.com/felipelouza/gsa-is/blob/master/gsacak.h#L71)

## Citation

Please, if you use this tool in an academic setting cite the following paper:
Expand Down Expand Up @@ -147,4 +151,4 @@ Please, if you use this tool in an academic setting cite the following paper:

## Thanks

Thanks to Giovanni Manzini by helpful suggestions and debugging.
Thanks to [Giovanni Manzini](https://github.com/giovmanz) and [Giovanna Rosone](https://github.com/giovannarosone) by helpful suggestions and debugging.
4 changes: 2 additions & 2 deletions experiments/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CFLAGS += -Wall
#CFLAGS += -g -O0
CFLAGS += -D_FILE_OFFSET_BITS=64 -m64 -O3 -fomit-frame-pointer -Wno-char-subscripts

LFLAGS = -lm -lrt -ldl
LFLAGS = -lm -ldl

DIR = dataset/
INPUT = input-10000.txt
Expand Down Expand Up @@ -53,7 +53,7 @@ remove:
# $(CC) $(DEFINES) -c lib/utils.c -o lib/utils.o

compile: main.c ${LIBOBJ}
$(CC) $(CFLAGS) $(LFLAGS) -o gsais main.c ${LIBOBJ}
$(CC) -o gsais main.c ${LIBOBJ} $(CFLAGS) $(LFLAGS)

run:
./gsais $(DIR) $(INPUT) $(K) $(MODE) $(LCP_COMPUTE) $(DA_COMPUTE) $(BWT_COMPUTE) $(CHECK) $(OUTPUT)
Expand Down
87 changes: 49 additions & 38 deletions experiments/lib/document_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,32 @@ return 0;

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

int document_array_LF(unsigned char* T, int_t* SA, int_t* DA, uint_t n, unsigned int SIGMA, int cs, unsigned char separator, uint_t k){
int document_array_LF(unsigned char* T, int_t* SA, int_da* DA, uint_t n, unsigned int SIGMA, int cs, unsigned char separator, uint_t k){

uint_t tmp, i, j, count=k;
compute_LF_array(T, SA, DA, n, SIGMA, cs, separator, k);
uint_t i, j, tmp;
int_da count=k;

int_t* LF = (int_t*) malloc(n*sizeof(int_t));
for(i=0; i<n;i++) LF[i]=-1;
compute_LF_array(T, SA, LF, n, SIGMA, cs, separator, k);

#if DEBUG
if(!check_LF_array(SA, DA, n, separator)) printf("isNotLF!!\n");
if(!check_LF_array(SA, LF, n, separator)) printf("isNotLF!!\n");
else printf("isLF!!\n");
#endif

separator=1;
j=0;
for (i=0; i<n; i++){

tmp = DA[j];
tmp = LF[j];
if(chr(SA[j])==separator) count--;
DA[j]=count;
j=tmp;
}

free(LF);

#if DEBUG
document_array_print(T, SA, DA, min(20,n), cs);
#endif
Expand Down Expand Up @@ -125,26 +131,31 @@ return 0;

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

int document_array_LF_int(int_text* T, int_t* SA, int_t* DA, uint_t n, unsigned int SIGMA, int cs, unsigned char separator, uint_t k){
int document_array_LF_int(int_text* T, int_t* SA, int_da* DA, uint_t n, unsigned int SIGMA, int cs, unsigned char separator, uint_t k){

uint_t tmp, i, j, count=k;
compute_LF_array_int(T, SA, DA, n, SIGMA, cs, k);
uint_t i, j, tmp;
int_da count=k;
int_t* LF = (int_t*) malloc(n*sizeof(int_t)); //if int_da == int_t, LF = DA;
for(i=0; i<n;i++) LF[i]=-1;
compute_LF_array_int(T, SA, LF, n, SIGMA, cs, k);

#if DEBUG
if(!check_LF_array(SA, DA, n, separator)) printf("isNotLF!!\n");
if(!check_LF_array(SA, LF, n, separator)) printf("isNotLF!!\n");
else printf("isLF!!\n");
#endif

j=0;
for (i=0; i<n; i++){

tmp = DA[j];
tmp = LF[j];
if(chr(SA[j])<k) count--;
DA[j]=count;
j=tmp;
}
DA[0]=k;

free(LF);

#if DEBUG
document_array_print((unsigned char*)T, SA, DA, min(20,n), cs);
#endif
Expand All @@ -154,10 +165,11 @@ return 0;

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

int document_array_check(unsigned char *T, int_t *SA, int_t *DA, uint_t n, int cs, unsigned char separator, uint_t k){
int document_array_check(unsigned char *T, int_t *SA, int_da *DA, uint_t n, int cs, unsigned char separator, uint_t k){

uint_t i, count=k;
int_t* R = (int_t*) malloc(n*sizeof(int_t));
uint_t i;
int_da count=k;
int_da* R = (int_da*) malloc(n*sizeof(int_da));

for(i=n-1; i>0;i--){
if(chr(i)==separator) count--;
Expand All @@ -179,10 +191,11 @@ return 1;

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

int document_array_check_int(int_text *T, int_t *SA, int_t *DA, uint_t n, int cs, uint_t k){
int document_array_check_int(int_text *T, int_t *SA, int_da *DA, uint_t n, int cs, uint_t k){

uint_t i, count=k;
int_t* R = (int_t*) malloc(n*sizeof(int_t));
uint_t i;
int_da count=k;
int_da* R = (int_da*) malloc(n*sizeof(int_da));

for(i=n-1; i>0;i--){
if(chr(i)<k) count--;
Expand All @@ -203,36 +216,34 @@ return 1;
}
/*******************************************************************/

int document_array_print(unsigned char *T, int_t *SA, int_t *DA, size_t n, int cs){
int document_array_print(unsigned char *T, int_t *SA, int_da *DA, size_t n, int cs){

int_t i;
for(i=0; i<n; i++){
for(i=0; i<n; i++){

printf("%" PRIdN ") %" PRIdN "\t %" PRIdN " \t", i, SA[i], DA[i]);

int_t j=SA[i];
for(j=SA[i]; (j<SA[i]+10); j++)
printf("%" PRIdT " ", chr(j));
printf("\n");
}
printf("%" PRIdN ") %" PRIdN "\t %" PRIdN " \t", i, SA[i], DA[i]);
int_t j=SA[i];
for(j=SA[i]; (j<SA[i]+10); j++) printf("%" PRIdT " ", chr(j));
printf("\n");
}

return 1;
}

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

int document_array_write(int_t *DA, int_t n, char* c_file, const char* ext){
int document_array_write(int_da *DA, int_t n, char* c_file, const char* ext){

FILE *f_out;
char *c_out = malloc((strlen(c_file)+strlen(ext)+3)*sizeof(char));

sprintf(c_out, "%s.%s", c_file, ext);
f_out = file_open(c_out, "wb");

int_t i;
for(i=0; i<n; i++){//writes DA
fwrite(&DA[i], sizeof(int_t), 1, f_out);
}
int_t i;
for(i=0; i<n; i++){//writes DA
fwrite(&DA[i], sizeof(int_da), 1, f_out);
}

file_close(f_out);
free(c_out);
Expand All @@ -243,22 +254,22 @@ return 1;

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

int_t document_array_read(int_t** DA, char* c_file, const char* ext){
int_t document_array_read(int_da** DA, char* c_file, const char* ext){

FILE *f_in;
char *c_in = malloc((strlen(c_file)+strlen(ext))*sizeof(char));

sprintf(c_in, "%s.%s", c_file, ext);
f_in = file_open(c_in, "rb");

fseek(f_in, 0L, SEEK_END);
size_t size = ftell(f_in);
rewind(f_in);

int_t n = size/sizeof(int_t);
fseek(f_in, 0L, SEEK_END);
size_t size = ftell(f_in);
rewind(f_in);
int_t n = size/sizeof(int_da);

*DA = (int_t*) malloc(n*sizeof(int_t));
fread(*DA, sizeof(int_t), n, f_in);
*DA = (int_da*) malloc(n*sizeof(int_da));
fread(*DA, sizeof(int_da), n, f_in);

file_close(f_in);
free(c_in);
Expand Down
14 changes: 7 additions & 7 deletions experiments/lib/document_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
#define DEBUG 0
#endif

int document_array_LF(unsigned char* T, int_t* SA, int_t* DA, uint_t n, unsigned int SIGMA, int cs, unsigned char separator, uint_t k);
int document_array_LF_int(int_text* T, int_t* SA, int_t* DA, uint_t n, unsigned int SIGMA, int cs, unsigned char separator, uint_t k);
int document_array_LF(unsigned char* T, int_t* SA, int_da* DA, uint_t n, unsigned int SIGMA, int cs, unsigned char separator, uint_t k);
int document_array_LF_int(int_text* T, int_t* SA, int_da* DA, uint_t n, unsigned int SIGMA, int cs, unsigned char separator, uint_t k);

/**/

int document_array_check(unsigned char *T, int_t *SA, int_t *DA, uint_t n, int cs, unsigned char separator, uint_t k);
int document_array_check(unsigned char *T, int_t *SA, int_da *DA, uint_t n, int cs, unsigned char separator, uint_t k);

int document_array_check_int(int_text *T, int_t *SA, int_t *DA, uint_t n, int cs, uint_t k);
int document_array_check_int(int_text *T, int_t *SA, int_da *DA, uint_t n, int cs, uint_t k);

int document_array_print(unsigned char *T, int_t *SA, int_t *DA, size_t n, int cs);
int document_array_write(int_t *DA, int_t n, char* c_file, const char* ext);
int_t document_array_read(int_t** DA, char* c_file, const char* ext);
int document_array_print(unsigned char *T, int_t *SA, int_da *DA, size_t n, int cs);
int document_array_write(int_da *DA, int_t n, char* c_file, const char* ext);
int_t document_array_read(int_da** DA, char* c_file, const char* ext);

/**/

Expand Down
4 changes: 4 additions & 0 deletions experiments/lib/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
typedef uint32_t int_text; //4N bytes for s[0..n-1]
#define PRIdT PRIu32

/*! @option type for array DA
*/
typedef int_t int_da;

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

#define swap(a,b) do { typeof(a) aux_a_b = (a); (a) = (b); (b) = aux_a_b; } while (0)
Expand Down
16 changes: 12 additions & 4 deletions experiments/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <assert.h>


#include "lib/file.h"
#include "lib/suffix_array.h"
Expand Down Expand Up @@ -98,9 +100,12 @@ clock_t c_start=0, c_total=0;
printf("sizeof(int) = %zu bytes\n", sizeof(int_t));

if(MODE==1 || MODE==2){//sais or saca-k (int)
printf("sizeof(int_text) = %zu bytes\n", sizeof(int_text));
printf("sizeof(int_text) = %zu byte(s)\n", sizeof(int_text));
}

if(DA_COMPUTE)
printf("sizeof(int_da) = %zu byte(s)\n", sizeof(int_da));

#if DEBUG
printf("R:\n");
for(i=0; i<min(5,k); i++)
Expand All @@ -113,19 +118,22 @@ clock_t c_start=0, c_total=0;
free(R);

int_t *SA = (int_t*) malloc(n*sizeof(int_t));
assert(SA);
for(i=0; i<n; i++) SA[i]=0;
int_t depth=0;

int_t *LCP = NULL;
if(LCP_COMPUTE){
LCP = (int_t*) malloc(n*sizeof(int_t));
assert(LCP);
for(i=0; i<n; i++) LCP[i]=0;
}

int_t *DA = NULL;
int_da *DA = NULL;
if(DA_COMPUTE){
DA = (int_t*) malloc(n*sizeof(int_t));
for(i=0; i<n; i++) DA[i]=-1;
DA = (int_da*) malloc(n*sizeof(int_da));
assert(DA);
for(i=0; i<n; i++) DA[i]=-1;
}

time_start(&t_total, &c_total);
Expand Down
Loading

0 comments on commit 723ee0c

Please sign in to comment.