tudocomp
– The TU Dortmund Compression Framework
RunRichGenerator.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <tudocomp/Generator.hpp>
4 
5 namespace tdc {
6 
9 class RunRichGenerator : public Generator {
10 
11 public:
12  inline static Meta meta() {
13  Meta m("generator", "run_rich", "Generates run-rich strings.");
14  m.option("n").dynamic();
15  return m;
16  }
17 
18  inline static std::string generate(size_t n) {
19  std::string t0 = "0110101101001011010",
20  t1 = "0110101101001",
21  t2 = "01101011010010110101101",
22  t3 = t2+t1;
23 
24  if(n==0) return t0;
25  if(n==1) return t1;
26  if(n==2) return t2;
27 
28  for(size_t i = 4; i < n; ++i) {
29  std::string tmp = (i % 3 == 0) ? (t3+t2) : (t3+t0);
30  t0=t1;
31  t1=t2;
32  t2=t3;
33  t3=tmp;
34  }
35 
36  return t3;
37  }
38 
39  using Generator::Generator;
40 
41  inline virtual std::string generate() override {
42  return generate(env().option("n").as_integer());
43  }
44 };
45 
46 } //ns
47 
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11
Provides meta information about an Algorithm.
Definition: Meta.hpp:34
Env & env()
Provides access to the environment that the algorithm works in.
Definition: Algorithm.hpp:51
Base for string generators.
Definition: Generator.hpp:13
Generates strings according to A Series of Run-Rich Strings (Wataru Matsubara et al.)
static std::string generate(size_t n)
OptionBuilder option(const std::string &name)
Declares an accepted option for this algorithm.
Definition: Meta.hpp:216
virtual std::string generate() override
Generates a string based on the environment settings.
void dynamic()
Declares that this option accepts values of a simple type that can be parsed from a string (e...
Definition: Meta.hpp:150