refactor: add WordList type

This commit is contained in:
Michael Mandl 2024-03-21 08:55:44 +01:00
parent dae5445efc
commit 48f05ddb4f
Signed by: mandlm
GPG key ID: 4AA25D647AA54CC7
18 changed files with 111 additions and 92 deletions

View file

@ -8,9 +8,7 @@
#include "sorted_linear_finder.h"
#include "timer.h"
#include "tree_finder.h"
#include "word_list_generator.h"
#include <fstream>
#include <sstream>
MainWindow::MainWindow(QWidget *parent)
@ -55,7 +53,9 @@ void MainWindow::setupWordList() {
void MainWindow::generateWordList() {
Timer timer;
word_list_ = WordListGenerator::generate(ui->wordListSizeSelector->value());
word_list_ = WordList::fourCaps()
.multiply(ui->wordListSizeSelector->value())
.shuffle();
timer.stop();
std::stringstream status_message;
@ -64,17 +64,10 @@ void MainWindow::generateWordList() {
}
void MainWindow::loadWordList(std::filesystem::path path) {
word_list_.clear();
Timer timer;
std::ifstream ifs(path);
std::string line;
while (std::getline(ifs, line)) {
for (auto i = 0; i < ui->wordListSizeSelector->value(); ++i) {
word_list_.emplace_back(line);
}
}
word_list_ = WordList::fromFile("words.txt")
.multiply(ui->wordListSizeSelector->value())
.shuffle();
timer.stop();
std::stringstream status_message;

View file

@ -2,6 +2,7 @@
#define MAINWINDOW_H
#include "finder.h"
#include "word_list.h"
#include <QMainWindow>
#include <QStandardItemModel>
#include <QStringListModel>
@ -17,7 +18,7 @@ class MainWindow : public QMainWindow {
Q_OBJECT
private:
std::vector<std::string> word_list_;
WordList word_list_;
QStringListModel result_model_;
QStandardItemModel search_algorithms_;
QStandardItemModel word_list_sources_;