-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsb-tree-build.cpp
More file actions
81 lines (68 loc) · 1.81 KB
/
sb-tree-build.cpp
File metadata and controls
81 lines (68 loc) · 1.81 KB
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
81
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include "sb_tree.h"
typedef struct {
uint64_t B;
const char* sa;
const char* input;
const char* output;
} cmd_args_t;
void
print_usage(const char* program)
{
printf("USAGE: %s -i <input> -s <sa> -o <output.sbti> -B <disk page size>\n",program);
printf("WHERE:\n");
printf(" -i <input> : input file\n");
printf(" -s <sa> : already constructed suffix array (optional)\n");
printf(" -o <output> : output index file\n");
printf(" -B <disk page size> : disk page size in bytes\n\n");
}
cmd_args_t
parse_args(int argc,char** argv)
{
int op;
cmd_args_t args;
args.sa = args.input = args.output = NULL;
args.B = 0;
while ((op=getopt(argc,argv,"i:s:o:B:")) != -1) {
switch (op) {
case 'i':
args.input = optarg;
break;
case 's':
args.sa = optarg;
break;
case 'o':
args.output = optarg;
break;
case 'B':
args.B = atoll(optarg);
break;
case '?':
print_usage(argv[0]);
exit(EXIT_FAILURE);
}
}
if (args.input == NULL || args.output == NULL || args.B == 0) {
print_usage(argv[0]);
exit(EXIT_FAILURE);
}
return args;
}
int
main(int argc,char** argv)
{
sbtree_t* sbt;
cmd_args_t cargs = parse_args(argc,argv);
/* build */
if (cargs.sa != NULL) {
sbt = sbtree_build(cargs.sa,cargs.input,cargs.output,20,cargs.B);
} else {
sbt = sbtree_create(cargs.input,cargs.output,cargs.B);
}
/* free the index */
sbtree_free(sbt);
return EXIT_SUCCESS;
}