feat: keep finder between searches
parent
bdc720694f
commit
9fd3062041
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue