feat: keep finder between searches

main
mandlm 2024-03-20 15:20:46 +01:00
parent bdc720694f
commit 9fd3062041
Signed by: mandlm
GPG Key ID: 4AA25D647AA54CC7
2 changed files with 11 additions and 7 deletions

View File

@ -48,8 +48,7 @@ void MainWindow::search(const QString &search_term) {
} }
Timer timer; Timer timer;
const auto finder = createSelectedFinder(); const auto results = finder_->find_prefix(search_term.toStdString());
const auto results = finder->find_prefix(search_term.toStdString());
timer.stop(); timer.stop();
std::stringstream status_message; std::stringstream status_message;
@ -60,18 +59,21 @@ void MainWindow::search(const QString &search_term) {
showResults(results); showResults(results);
} }
std::unique_ptr<Finder> MainWindow::createSelectedFinder() const { void MainWindow::createSelectedFinder() {
auto selectedFinder = ui->searchAlgorithmSelector->currentIndex(); auto selectedFinder = ui->searchAlgorithmSelector->currentIndex();
switch (selectedFinder) { switch (selectedFinder) {
case 0: case 0:
default: default:
return std::make_unique<LinearFinder>(word_list_); finder_ = std::make_unique<LinearFinder>(word_list_);
break;
case 1: case 1:
return std::make_unique<ParallelFinder>( finder_ = std::make_unique<ParallelFinder>(
word_list_, std::thread::hardware_concurrency()); word_list_, std::thread::hardware_concurrency());
break;
case 2: case 2:
return std::make_unique<TreeFinder>(word_list_); finder_ = std::make_unique<TreeFinder>(word_list_);
break;
} }
} }
@ -90,5 +92,6 @@ void MainWindow::on_searchInput_textChanged(const QString &search_term) {
} }
void MainWindow::on_searchAlgorithmSelector_currentIndexChanged(int) { void MainWindow::on_searchAlgorithmSelector_currentIndexChanged(int) {
createSelectedFinder();
search(ui->searchInput->displayText()); search(ui->searchInput->displayText());
} }

View File

@ -19,6 +19,7 @@ private:
std::vector<std::string> word_list_; std::vector<std::string> word_list_;
QStringListModel result_model_; QStringListModel result_model_;
QStandardItemModel search_algorithms_; QStandardItemModel search_algorithms_;
std::unique_ptr<Finder> finder_;
public: public:
MainWindow(QWidget *parent = nullptr); MainWindow(QWidget *parent = nullptr);
@ -28,7 +29,7 @@ private:
void setupAlgorithmSelector(); void setupAlgorithmSelector();
void generateWordList(); void generateWordList();
void search(const QString &search_term); void search(const QString &search_term);
std::unique_ptr<Finder> createSelectedFinder() const; void createSelectedFinder();
void showResults(const std::forward_list<const std::string *> &results); void showResults(const std::forward_list<const std::string *> &results);
private slots: private slots: