-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.c
50 lines (41 loc) · 1 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sacak-lcp.h"
#include "experiments/external/malloc_count.h" //memory counter
int main(int argc, char *argv[]){
printf("sizeof(int_t) = %zu bytes\n", sizeof(int_t));
unsigned char *Text;
// intput data
if(argc==2){
Text = malloc((strlen(argv[1])+1)*sizeof(unsigned char));
sscanf(argv[1], "%s", Text);
}
else{
Text = "banaananaanana";
}
printf("Text = %s$\n", Text);
int n = strlen(Text)+1;
int i, j;
// allocate
uint_t *SA = (uint_t *)malloc(n * sizeof(uint_t));
int_t *LCP = (int_t *)malloc(n * sizeof(int_t));
// sort
sacak_lcp((unsigned char *)Text, (uint_t*)SA, LCP, n);
// output
printf("i\tSA\tLCP\tBWT\tsuffixes\n");
for(i = 0; i < n; ++i) {
char j = (SA[i])? Text[SA[i]-1]:'$';
printf("%d\t%d\t%d\t%c\t",i, SA[i],LCP[i],j);
for(j = SA[i]; j < n; ++j) {
printf("%c", Text[j]);
}
printf("$\n");
}
/**/
// deallocate
free(SA);
free(LCP);
if(argc==2) free(Text);
return 0;
}