feat: add tree-finder

This commit is contained in:
Michael Mandl 2024-03-20 15:05:25 +01:00
parent 1ab711f81c
commit bdc720694f
Signed by: mandlm
GPG key ID: 4AA25D647AA54CC7
5 changed files with 123 additions and 6 deletions

View file

@ -1,6 +1,7 @@
#include "linear_finder.h"
#include "parallel_finder.h"
#include "timer.h"
#include "tree_finder.h"
#include "word_list_generator.h"
#include <cstdlib>
@ -26,9 +27,7 @@ vector<string> generate_word_list() {
void test_linear_finder(const vector<string> &word_list) {
cout << "\nrunning linear finder" << endl;
Timer constructor_timer;
LinearFinder linear_finder(word_list);
constructor_timer.stop();
Timer find_timer;
auto result = linear_finder.find_prefix("ABCD");
@ -46,9 +45,7 @@ void test_parallel_finder(const vector<string> &word_list) {
cout << "using " << thread_count << " threads" << endl;
Timer constructor_timer;
ParallelFinder parallel_finder(word_list, thread_count);
constructor_timer.stop();
Timer find_timer;
auto result = parallel_finder.find_prefix("ABCD");
@ -59,6 +56,24 @@ void test_parallel_finder(const vector<string> &word_list) {
<< " element(s) long" << endl;
}
void test_tree_finder(const vector<string> &word_list) {
cout << "\nrunning tree finder" << endl;
Timer constructor_timer;
TreeFinder tree_finder(word_list);
constructor_timer.stop();
cout << "tree finder constructor took " << constructor_timer << endl;
Timer find_timer;
auto result = tree_finder.find_prefix("ABCD");
find_timer.stop();
cout << "tree finder took " << find_timer << endl;
cout << "result list is " << std::distance(result.cbegin(), result.cend())
<< " element(s) long" << endl;
}
int main(int argc, char *argv[]) {
cout << "\n== VectorSearch ==" << endl;
@ -66,6 +81,7 @@ int main(int argc, char *argv[]) {
test_linear_finder(word_list);
test_parallel_finder(word_list);
test_tree_finder(word_list);
return EXIT_SUCCESS;
}