MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / makeMarkovSource

Method makeMarkovSource

source/game/StarNameGenerator.cpp:127–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125}
126
127MarkovSource PatternedNameGenerator::makeMarkovSource(size_t prefixSize, size_t endSize, StringList sourceNames) {
128 MarkovSource newSource;
129 newSource.prefixSize = prefixSize;
130 newSource.endSize = endSize;
131 for (auto sourceName : sourceNames) {
132 if (sourceName.length() < prefixSize || sourceName.length() < endSize)
133 continue;
134
135 sourceName = sourceName.toLower();
136 newSource.ends.add(sourceName.slice(sourceName.length() - endSize, sourceName.length()));
137 for (int i = 0; i + prefixSize <= sourceName.length(); ++i) {
138 auto prefix = sourceName.slice(i, i + prefixSize);
139 if (i == 0)
140 newSource.starts.append(prefix);
141
142 if (i + prefixSize < sourceName.length()) {
143 if (!newSource.chains.contains(prefix))
144 newSource.chains.insert(prefix, StringList());
145
146 newSource.chains.get(prefix).append(sourceName.slice(i + prefixSize, i + prefixSize + 1));
147 }
148 }
149 }
150 return newSource;
151}
152
153}

Callers

nothing calls this directly

Calls 9

StringListClass · 0.85
toLowerMethod · 0.80
lengthMethod · 0.45
addMethod · 0.45
sliceMethod · 0.45
appendMethod · 0.45
containsMethod · 0.45
insertMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected