Compare commits
2 Commits
6ba52ab73f
...
48283d0d76
Author | SHA1 | Date |
---|---|---|
mandlm | 48283d0d76 | |
mandlm | 7f18d0d6cc |
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -22,7 +22,8 @@ GroupedFinder::find_prefix(std::string_view search_term) const {
|
|||
const auto word_list = group->second;
|
||||
const auto word_list_size = word_list.size();
|
||||
|
||||
const auto thread_count = std::thread::hardware_concurrency();
|
||||
const auto thread_count =
|
||||
std::min<size_t>(std::thread::hardware_concurrency(), word_list_size);
|
||||
|
||||
forward_list<const string *> matching_words;
|
||||
mutex matching_words_mutex;
|
||||
|
|
|
@ -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 New Issue