28 for(std::size_t
i = 0;
i <= str.size(); ++
i) {
29 const std::size_t
start =
i > length ?
i - length : 0;
30 const std::u32string key(str.begin() +
start, str.begin() +
i);
31 const char32_t
c =
i != str.size() ? str[
i] : 0;
32 res[key].push_back(
c);
40 for(std::vector<std::string>::const_iterator
i = items.begin();
i != items.end(); ++
i) {
48 std::size_t chain_size, std::size_t max_len)
50 if(prefixes.empty() || chain_size == 0) {
51 return std::u32string();
54 std::u32string prefix, res;
66 std::vector<int> random(max_len);
68 for(; j < max_len; ++j) {
73 while(res.size() < max_len) {
74 const markov_prefix_map::const_iterator
i = prefixes.find(prefix);
75 if(
i == prefixes.end() ||
i->second.empty()) {
79 const char32_t
c =
i->second[random[j++]%
i->second.size()];
84 res.resize(res.size()+1);
86 prefix.resize(prefix.size()+1);
88 while(prefix.size() > chain_size) {
89 prefix.erase(prefix.begin());
102 std::u32string originalRes = res;
103 while(!res.empty()) {
104 const int prefixLen = chain_size < res.size() ? chain_size : res.size();
105 prefix = std::u32string(res.end() - prefixLen, res.end());
107 const markov_prefix_map::const_iterator
i = prefixes.find(prefix);
108 if (
i == prefixes.end() ||
i->second.empty()) {
111 if (std::find(
i->second.begin(),
i->second.end(),
static_cast<char32_t
>(0))
112 !=
i->second.end()) {
129 , chain_size_(chain_size)
137 return unicode_cast<std::string>(name);
markov_generator(const std::vector< std::string > &items, std::size_t chain_size, std::size_t max_len)
markov_prefix_map prefixes_
std::string generate() const override
uint32_t next_random()
Provides the next random draw.
static markov_prefix_map markov_prefixes(const std::vector< std::string > &items, std::size_t length)
static void add_prefixes(const std::u32string &str, std::size_t length, markov_prefix_map &res)
static std::u32string markov_generate_name(const markov_prefix_map &prefixes, std::size_t chain_size, std::size_t max_len)
std::map< std::u32string, std::u32string > markov_prefix_map
EXIT_STATUS start(bool clear_id, const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
rng * generator
This generator is automatically synced during synced context.