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;
const auto finder = createSelectedFinder();
const auto results = finder->find_prefix(search_term.toStdString());
const auto results = finder_->find_prefix(search_term.toStdString());
timer.stop();
std::stringstream status_message;
@ -60,18 +59,21 @@ void MainWindow::search(const QString &search_term) {
showResults(results);
}
std::unique_ptr<Finder> MainWindow::createSelectedFinder() const {
void MainWindow::createSelectedFinder() {
auto selectedFinder = ui->searchAlgorithmSelector->currentIndex();
switch (selectedFinder) {
case 0:
default:
return std::make_unique<LinearFinder>(word_list_);
finder_ = std::make_unique<LinearFinder>(word_list_);
break;
case 1:
return std::make_unique<ParallelFinder>(
finder_ = std::make_unique<ParallelFinder>(
word_list_, std::thread::hardware_concurrency());
break;
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) {
createSelectedFinder();
search(ui->searchInput->displayText());
}

View File

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