Thrill  0.1
wavelet_tree3.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * examples/suffix_sorting/wavelet_tree3.cpp
3  *
4  * Part of Project Thrill - http://project-thrill.org
5  *
6  * Copyright (C) 2016 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
9  ******************************************************************************/
10 
12 
13 #include <thrill/api/generate.hpp>
16 #include <thrill/common/logger.hpp>
17 #include <tlx/cmdline_parser.hpp>
18 
19 #include <algorithm>
20 #include <limits>
21 #include <random>
22 #include <stdexcept>
23 #include <string>
24 #include <tuple>
25 #include <utility>
26 #include <vector>
27 
28 int main(int argc, char* argv[]) {
29 
30  using namespace thrill; // NOLINT
31  using namespace examples::suffix_sorting;
32 
34 
35  cp.set_author("Timo Bingmann <[email protected]>");
36 
37  std::string input_path;
38 
39  cp.add_opt_param_string("input", input_path,
40  "Path to input file.");
41 
42  if (!cp.process(argc, argv))
43  return -1;
44 
45  return Run(
46  [&](Context& ctx) {
47  ctx.enable_consume();
48 
49  if (input_path.size()) {
50  auto input_dia = ReadBinary<uint8_t>(ctx, input_path);
51  ConstructWaveletTree(input_dia, "wt-bin");
52  }
53  else {
54  std::string bwt = "aaaaaaaaaaabbbbaaaaaaaccccdddaacacaffatttttttttttyyyyaaaaa";
55  auto input_dia =
56  Generate(ctx, bwt.size(),
57  [&](size_t i) { return (uint8_t)bwt[i]; });
58  ConstructWaveletTree(input_dia, "wt-bin");
59  }
60  });
61 }
62 
63 /******************************************************************************/
int main(int argc, char *argv[])
auto Generate(Context &ctx, size_t size, const GenerateFunction &generate_function)
Generate is a Source-DOp, which creates a DIA of given size using a generator function.
Definition: generate.hpp:87
int Run(const std::function< void(Context &)> &job_startpoint)
Runs the given job startpoint with a Context instance.
Definition: context.cpp:947
void add_opt_param_string(const std::string &name, std::string &dest, const std::string &desc)
add optional string parameter [name] with description and store to dest
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220
Command line parser which automatically fills variables and prints nice usage messages.
void set_author(const std::string &author)
Set author of program, will be wrapped.
bool process(int argc, const char *const *argv, std::ostream &os)
auto ConstructWaveletTree(const InputDIA &input_dia)