-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.c
81 lines (68 loc) · 1.59 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gsacak.h"
#include "experiments/external/malloc_count/malloc_count.h" //memory counter
#ifndef DEBUG
#define DEBUG 0
#endif
int main(int argc, char *argv[]){
#if DEBUG
printf("sizeof(int_t) = %zu bytes\n", sizeof(int_t));
#endif
unsigned char *Text;
uint_t n=0;
// intput data
if(argc>=2){
//concatenate all strings s_1, s_2, .., s_d in s_1$s_2$..%s_d$#
int i = 2, sum=0;
for(; i<= argc; i++){
sum += strlen((argv[i-1]))+1;
}
n = sum+1;
Text = malloc(n*sizeof(unsigned char));
sum=0;
for(i=2; i<= argc; i++){
sscanf(argv[i-1], "%s", &Text[sum]);
sum += strlen((argv[i-1]))+1;
Text[sum-1]=1;//separator
}
Text[n-1]=0;
printf("N = %d\n", n);
}
else{
fprintf(stderr, "Please, insert at least one string.\n");
exit(-1);
}
int i, j;
printf("T^{cat} = ");
for(i=0;i<n-1;i++){
if(Text[i]==1) printf("$");
else printf("%c", Text[i]);
}
printf("#\n");
// allocate
uint_t *SA = (uint_t *)malloc(n * sizeof(uint_t));
int_t *LCP = (int_t *)malloc(n * sizeof(int_t));
int_t *DA = (int_t *)malloc(n * sizeof(int_t));
// sort
gsacak((unsigned char *)Text, (uint_t*)SA, LCP, DA, n);
// output
printf("i\tSA\tDA\tLCP\tBWT\tsuffixes\n");
for(i = 0; i < n; ++i) {
char j = (SA[i])? Text[SA[i]-1]:'#';
if(j==1) j = '$';
printf("%d\t%d\t%d\t%d\t%c\t",i, SA[i], DA[i], LCP[i], j);
for(j = SA[i]; j < n; ++j) {
if(Text[j]==1) printf("$");
else printf("%c", Text[j]);
}
printf("#\n");
}
// deallocate
free(SA);
free(DA);
free(LCP);
free(Text);
return 0;
}