refactor: clean up word list generator
This commit is contained in:
parent
6ba52ab73f
commit
7f18d0d6cc
4 changed files with 10 additions and 11 deletions
|
@ -33,7 +33,7 @@ void MainWindow::setupAlgorithmSelector() {
|
|||
|
||||
void MainWindow::generateWordList() {
|
||||
Timer timer;
|
||||
word_list_ = WordListGenerator().generate();
|
||||
word_list_ = WordListGenerator::generate();
|
||||
timer.stop();
|
||||
|
||||
std::stringstream status_message;
|
||||
|
|
|
@ -8,5 +8,6 @@ private:
|
|||
static const std::string charset_;
|
||||
|
||||
public:
|
||||
std::vector<std::string> generate();
|
||||
WordListGenerator() = delete;
|
||||
static std::vector<std::string> generate(const size_t multiplier = 1);
|
||||
};
|
||||
|
|
|
@ -6,18 +6,16 @@
|
|||
|
||||
const std::string WordListGenerator::charset_ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
std::vector<std::string> WordListGenerator::generate() {
|
||||
const size_t multiplier = 1;
|
||||
|
||||
std::vector<std::string> result;
|
||||
result.reserve(multiplier * std::pow(charset_.length(), 4));
|
||||
std::vector<std::string> WordListGenerator::generate(const size_t multiplier) {
|
||||
std::vector<std::string> word_list;
|
||||
word_list.reserve(multiplier * std::pow(charset_.length(), 4));
|
||||
|
||||
for (auto char_1 : charset_) {
|
||||
for (auto char_2 : charset_) {
|
||||
for (auto char_3 : charset_) {
|
||||
for (auto char_4 : charset_) {
|
||||
for (auto i = 0; i < multiplier; ++i) {
|
||||
result.emplace_back(
|
||||
word_list.emplace_back(
|
||||
std::initializer_list<char>({char_1, char_2, char_3, char_4}));
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +26,7 @@ std::vector<std::string> WordListGenerator::generate() {
|
|||
std::random_device random_device;
|
||||
std::mt19937 random_number_generator(random_device());
|
||||
|
||||
std::shuffle(result.begin(), result.end(), random_number_generator);
|
||||
std::shuffle(word_list.begin(), word_list.end(), random_number_generator);
|
||||
|
||||
return result;
|
||||
return word_list;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ vector<string> generate_word_list() {
|
|||
cout << "\ngenerating word list" << endl;
|
||||
|
||||
Timer generator_timer;
|
||||
auto word_list = WordListGenerator().generate();
|
||||
auto word_list = WordListGenerator::generate(5);
|
||||
generator_timer.stop();
|
||||
|
||||
cout << "word list generator took " << generator_timer << endl;
|
||||
|
|
Loading…
Reference in a new issue