Skip to content

Commit

Permalink
Adapted construction of the examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
simongog committed Nov 8, 2012
1 parent c343584 commit ee39fff
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
16 changes: 8 additions & 8 deletions examples/csa_alphabet_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ using namespace sdsl;
using namespace std;

template<class Csa>
void csa_info(Csa &csa, string file_name, bool json){
cout << "file: " << file_name << endl;
construct_csa( file_name, csa );
void csa_info(Csa &csa, const char* file, bool json){
cout << "file: " << file << endl;
construct(csa, file, 1);
cout << "csa of type " << util::demangle(typeid(csa).name()) << endl;
cout << "size in bytes : " << util::get_size_in_bytes(csa) << endl;
if ( json ){
Expand All @@ -26,7 +26,7 @@ void csa_info(Csa &csa, string file_name, bool json){

int main(int argc, char* argv[]){
if ( argc < 2 ){
cout << "Usage: " << argv[0] << " file_name [json]" << endl;
cout << "Usage: " << argv[0] << " file [json]" << endl;
return 1;
}
bool json = false;
Expand All @@ -37,8 +37,8 @@ int main(int argc, char* argv[]){
csa_sada<enc_vector<>, 32, 32, sa_order_sa_sampling<>, int_vector<>, succinct_byte_alphabet_strategy<> > csa2;
csa_wt<wt_huff<>, 32, 32, sa_order_sa_sampling<>, int_vector<>, byte_alphabet_strategy> csa3;
csa_wt<wt_huff<>, 32, 32, sa_order_sa_sampling<>, int_vector<>, succinct_byte_alphabet_strategy<> > csa4;
csa_info(csa1, string(argv[1]), json);
csa_info(csa2, string(argv[1]), json);
csa_info(csa3, string(argv[1]), json);
csa_info(csa4, string(argv[1]), json);
csa_info(csa1, argv[1], json);
csa_info(csa2, argv[1], json);
csa_info(csa3, argv[1], json);
csa_info(csa4, argv[1], json);
}
7 changes: 3 additions & 4 deletions examples/cst_bfs_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ using namespace sdsl;


template<class tCst>
void test(string file)
{
void test(const char* file) {
std::cout << file << std::endl;
tCst cst;
// util::verbose = true;
construct_cst(file, cst);
construct(cst, file, 1);

typedef cst_bfs_iterator<tCst> iterator;
iterator begin = iterator(&cst, cst.root());
Expand All @@ -27,7 +26,7 @@ void test(string file)
int main(int argc, char* argv[])
{
if (argc < 2) {
cout << "usage: "<<argv[0]<< " file_name" << std::endl;
cout << "usage: "<<argv[0]<< " file" << std::endl;
} else {
test<cst_sct3<> >(argv[1]);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/hugepages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int main(int argc, char** argv){
// if( mapped ) mm::unmap_hp();

csa_wt<wt_huff<bit_vector_interleaved<> > > csa;
construct_csa(string(argv[1]), csa);
construct(csa, argv[1], 1);
do_something(csa); // before it is mapped
mapped = mm::map_hp();
do_something(csa); // while it is mapped
Expand Down
2 changes: 1 addition & 1 deletion examples/import_non_sdsl_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int main(int argc, char* argv[]){
}
int_vector<8> text;

util::load_from_plain_array<uint8_t>(text, argv[1]);
util::load_vector_from_file(text, argv[1], 1);

cout << "text.size() = " << text.size() << endl;
cout << "text =";
Expand Down
2 changes: 1 addition & 1 deletion examples/import_non_sdsl_data2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int main(int argc, char* argv[]){
}
int_vector<> v;

util::load_from_plain_array<uint32_t>(v, argv[1]);
util::load_vector_from_file(v, argv[1], 4);

cout << "v.size() = " << v.size() << endl;
cout << "v.get_int_width() = " << (int)v.get_int_width() << endl;
Expand Down
6 changes: 3 additions & 3 deletions examples/louds_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ void print_tree(const tTree& tree, const tNode& v, int depth, bit_vector& visite
}

template<class tCst>
void test(string file)
void test(const char* file)
{
std::cout << file << std::endl;
tCst cst;
// util::verbose = true;
construct_cst(file, cst);
construct(cst, file, 1);

typedef cst_bfs_iterator<tCst> iterator;
iterator begin = iterator(&cst, cst.root());
Expand All @@ -50,7 +50,7 @@ void test(string file)
int main(int argc, char* argv[])
{
if (argc < 2) {
cout << "usage: "<<argv[0]<< " file_name" << std::endl;
cout << "usage: "<<argv[0]<< " file" << std::endl;
} else {
test<cst_sct3<> >(argv[1]);
}
Expand Down
7 changes: 4 additions & 3 deletions examples/sigir_demo_fm_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ int main(int argc, char **argv){
if ( argc >= 5 ){ pre_context = atoi(argv[4]); }
string index_suffix = ".fm9";
string index_file = string(argv[1])+index_suffix;
csa_wt<wt_huff<rrr_vector<255> >, 512, 1024> fm_index;
csa_wt<wt_huff<rrr_vector<127> >, 512, 1024> fm_index;

if( !util::load_from_file(fm_index, index_file.c_str()) ){
ifstream in(argv[1]);
if( !in ){ cout << "ERROR: File " << argv[1] << " does not exist. Exit." << endl; return 1; }
cout << "No index "<<index_file<< " located. Building index now." << endl;
construct_csa(argv[1], fm_index); // generate index
construct(fm_index, argv[1], 1); // generate index
util::store_to_file(fm_index, index_file.c_str()); // save it
}
cout << "Index construction complete, index requires " << util::get_size_in_mega_bytes(fm_index) << " MiB." << endl;
Expand All @@ -44,14 +44,15 @@ int main(int argc, char **argv){
while ( getline(cin, query) ){
size_t m = query.size();
size_t occs = algorithm::count(fm_index, (const unsigned char*)query.c_str(), m);
cout << "# of occcurences: " << occs << endl;
cout << "# of occurrences: " << occs << endl;
if ( occs > 0 ){
cout << "Location and context of first occurrences: " << endl;
int_vector<> locations;
algorithm::locate(fm_index, (const unsigned char*)query.c_str(), m, locations);
sort(locations.begin(), locations.end());
for(size_t i = 0, pre_extract = pre_context, post_extract = post_context; i < min(occs, max_locations); ++i){
cout << setw(8) << locations[i] << ": ";
cout<<"("<<fm_index.sigma<<") ";
if( pre_extract > locations[i] ){ pre_extract = locations[i]; }
if( locations[i]+m+ post_extract > fm_index.size() ){ post_extract = fm_index.size()-locations[i]-m; }
string s = algorithm::extract(fm_index, locations[i]-pre_extract, locations[i]+m+ post_extract-1 );
Expand Down
8 changes: 4 additions & 4 deletions examples/sigir_demo_fm_rmq_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ int main(int argc, char** argv)
}
string index_suffix = ".fm9";
string index_file = string(argv[1])+index_suffix;
typedef csa_wt<wt_huff<rrr_vector<255> >, 512, 1024> fm_index_type;
typedef csa_wt<wt_huff<rrr_vector<127> >, 512, 1024> fm_index_type;
typedef fm_index_type::size_type size_type;
fm_index_type fm_index;
if (!util::load_from_file(fm_index, index_file.c_str())) {
ifstream in(argv[1]);
if( !in ){ cout << "ERROR: File " << argv[1] << " does not exist. Exit." << endl; return 1; }
cout << "No index "<<index_file<< " located. Building index now." << endl;
construct_csa(argv[1], fm_index); // generate index
construct(fm_index, argv[1], 1); // generate index
util::store_to_file(fm_index, index_file.c_str()); // save it
}
string rmq_suffix = ".rmq";
Expand All @@ -78,11 +78,11 @@ int main(int argc, char** argv)
ifstream in(argv[1]);
if( !in ){ cout << "ERROR: File " << argv[1] << " does not exist. Exit." << endl; return 1; }
cout << "No index "<<rmq_file<< " located. Building index now." << endl;
construct_csa(argv[1], tmp_csa);
construct(tmp_csa, argv[1], 1);
util::assign(rmq, rmq_succinct_sct<>(&tmp_csa));
util::store_to_file(rmq, rmq_file.c_str());
}
size_t index_size = util::get_size_in_mega_bytes(fm_index) + util::get_size_in_mega_bytes(rmq);
double index_size = util::get_size_in_mega_bytes(fm_index) + util::get_size_in_mega_bytes(rmq);
cout << "Index construction complete, index requires " << index_size << " MiB." << endl;
cout << "Input search terms and press Ctrl-D to exit." << endl;
string prompt = "\e[0;32m>\e[0m ";
Expand Down
2 changes: 1 addition & 1 deletion examples/text_statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main(int argc, char* argv[]){
cst_sct3<> cst;
typedef cst_sct3<>::size_type size_type;
typedef cst_sct3<>::char_type char_type;
construct_cst(argv[1], cst);
construct(cst, argv[1], 1);

long double red = 0;
long double lcp_mean = 0;
Expand Down

0 comments on commit ee39fff

Please sign in to comment.