27 for(
size_t i = 0;
i <= str.size(); ++
i) {
28 const size_t start =
i > length ?
i - length : 0;
31 res[key].push_back(c);
39 for(std::vector<std::string>::const_iterator
i = items.begin();
i != items.end(); ++
i) {
47 size_t chain_size,
size_t max_len)
49 if(prefixes.empty() || chain_size == 0) {
65 std::vector<int> random(max_len);
67 for(; j < max_len; ++j) {
72 while(res.size() < max_len) {
73 const markov_prefix_map::const_iterator
i = prefixes.find(prefix);
74 if(i == prefixes.end() || i->second.empty()) {
78 const ucs4::char_t c = i->second[random[j++]%i->second.size()];
83 res.resize(res.size()+1);
84 res[res.size()-1] =
c;
85 prefix.resize(prefix.size()+1);
86 prefix[prefix.size()-1] =
c;
87 while(prefix.size() > chain_size) {
88 prefix.erase(prefix.begin());
102 while(!res.empty()) {
103 const int prefixLen = chain_size < res.size() ? chain_size : res.size();
104 prefix =
ucs4::string(res.end() - prefixLen, res.end());
106 const markov_prefix_map::const_iterator
i = prefixes.find(prefix);
107 if (i == prefixes.end() || i->second.empty()) {
111 != i->second.end()) {
128 , chain_size_(chain_size)
std::vector< char_t > string
rng * generator
This generator is automatically synced during synced context.
ucs4_convert_impl::enableif< TD, typename TS::value_type >::type unicode_cast(const TS &source)
const std::vector< std::string > items
GLuint GLsizei GLsizei * length
uint32_t next_random()
Provides the next random draw.
static markov_prefix_map markov_prefixes(const std::vector< std::string > &items, size_t length)
markov_generator(const std::vector< std::string > &items, size_t chain_size, size_t max_len)
markov_prefix_map prefixes_
GLuint const GLchar * name
bool find(E event, F functor)
Tests whether an event handler is available.
std::string generate() const override
static void add_prefixes(const ucs4::string &str, size_t length, markov_prefix_map &res)
static ucs4::string markov_generate_name(const markov_prefix_map &prefixes, size_t chain_size, size_t max_len)
GLsizei const GLcharARB ** string
std::map< ucs4::string, ucs4::string > markov_prefix_map