Compare commits
No commits in common. "48283d0d7620b35eaab810db3929f9c9af88be47" and "6ba52ab73f7f0b2592daa50cf9d51724ec09cdcb" have entirely different histories.
48283d0d76
...
6ba52ab73f
@ -33,7 +33,7 @@ void MainWindow::setupAlgorithmSelector() {
|
|||||||
|
|
||||||
void MainWindow::generateWordList() {
|
void MainWindow::generateWordList() {
|
||||||
Timer timer;
|
Timer timer;
|
||||||
word_list_ = WordListGenerator::generate();
|
word_list_ = WordListGenerator().generate();
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
std::stringstream status_message;
|
std::stringstream status_message;
|
||||||
|
@ -8,6 +8,5 @@ private:
|
|||||||
static const std::string charset_;
|
static const std::string charset_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WordListGenerator() = delete;
|
std::vector<std::string> generate();
|
||||||
static std::vector<std::string> generate(const size_t multiplier = 1);
|
|
||||||
};
|
};
|
||||||
|
@ -22,8 +22,7 @@ GroupedFinder::find_prefix(std::string_view search_term) const {
|
|||||||
const auto word_list = group->second;
|
const auto word_list = group->second;
|
||||||
const auto word_list_size = word_list.size();
|
const auto word_list_size = word_list.size();
|
||||||
|
|
||||||
const auto thread_count =
|
const auto thread_count = std::thread::hardware_concurrency();
|
||||||
std::min<size_t>(std::thread::hardware_concurrency(), word_list_size);
|
|
||||||
|
|
||||||
forward_list<const string *> matching_words;
|
forward_list<const string *> matching_words;
|
||||||
mutex matching_words_mutex;
|
mutex matching_words_mutex;
|
||||||
|
@ -6,16 +6,18 @@
|
|||||||
|
|
||||||
const std::string WordListGenerator::charset_ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
const std::string WordListGenerator::charset_ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
|
||||||
std::vector<std::string> WordListGenerator::generate(const size_t multiplier) {
|
std::vector<std::string> WordListGenerator::generate() {
|
||||||
std::vector<std::string> word_list;
|
const size_t multiplier = 1;
|
||||||
word_list.reserve(multiplier * std::pow(charset_.length(), 4));
|
|
||||||
|
std::vector<std::string> result;
|
||||||
|
result.reserve(multiplier * std::pow(charset_.length(), 4));
|
||||||
|
|
||||||
for (auto char_1 : charset_) {
|
for (auto char_1 : charset_) {
|
||||||
for (auto char_2 : charset_) {
|
for (auto char_2 : charset_) {
|
||||||
for (auto char_3 : charset_) {
|
for (auto char_3 : charset_) {
|
||||||
for (auto char_4 : charset_) {
|
for (auto char_4 : charset_) {
|
||||||
for (auto i = 0; i < multiplier; ++i) {
|
for (auto i = 0; i < multiplier; ++i) {
|
||||||
word_list.emplace_back(
|
result.emplace_back(
|
||||||
std::initializer_list<char>({char_1, char_2, char_3, char_4}));
|
std::initializer_list<char>({char_1, char_2, char_3, char_4}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26,7 +28,7 @@ std::vector<std::string> WordListGenerator::generate(const size_t multiplier) {
|
|||||||
std::random_device random_device;
|
std::random_device random_device;
|
||||||
std::mt19937 random_number_generator(random_device());
|
std::mt19937 random_number_generator(random_device());
|
||||||
|
|
||||||
std::shuffle(word_list.begin(), word_list.end(), random_number_generator);
|
std::shuffle(result.begin(), result.end(), random_number_generator);
|
||||||
|
|
||||||
return word_list;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ vector<string> generate_word_list() {
|
|||||||
cout << "\ngenerating word list" << endl;
|
cout << "\ngenerating word list" << endl;
|
||||||
|
|
||||||
Timer generator_timer;
|
Timer generator_timer;
|
||||||
auto word_list = WordListGenerator::generate(5);
|
auto word_list = WordListGenerator().generate();
|
||||||
generator_timer.stop();
|
generator_timer.stop();
|
||||||
|
|
||||||
cout << "word list generator took " << generator_timer << endl;
|
cout << "word list generator took " << generator_timer << endl;
|
||||||
|
Reference in New Issue
Block a user