diff --git a/lib_vector_search/include/bucket_finder.h b/lib_vector_search/include/bucket_finder.h index 784705e..b97ecbc 100644 --- a/lib_vector_search/include/bucket_finder.h +++ b/lib_vector_search/include/bucket_finder.h @@ -5,12 +5,6 @@ #include -/** A Bucket contains a partial WordRefList, split-up and (hash-)mapped by their - * first characters. - * - * It's meant to be read and written by a single thread without the need for - * synchronization. - */ class Bucket { private: std::unordered_map directory_; diff --git a/lib_vector_search/src/bucket_finder.cpp b/lib_vector_search/src/bucket_finder.cpp index bb53a0c..03949e1 100644 --- a/lib_vector_search/src/bucket_finder.cpp +++ b/lib_vector_search/src/bucket_finder.cpp @@ -7,8 +7,6 @@ #include #include -// class Bucket - void Bucket::insert(const WordList &word_list, size_t first_index, size_t last_index) { for (auto index = first_index; index < last_index; ++index) { @@ -33,8 +31,6 @@ WordRefList Bucket::find_prefix(std::string_view search_term) const { return result; } -// class BucketFinder - BucketFinder::BucketFinder(const WordList &word_list) { insert(word_list); } void BucketFinder::insert(const WordList &word_list) { @@ -51,7 +47,7 @@ void BucketFinder::insert(const WordList &word_list) { std::vector insert_threads; for (auto bucket_index = 0; bucket_index < bucket_count; ++bucket_index) { - auto &thread_bucket = buckets_[bucket_index]; + auto &bucket = buckets_[bucket_index]; const bool is_last_bucket = bucket_index == bucket_count - 1; const size_t first_word_index = bucket_index * bucket_size; @@ -59,7 +55,7 @@ void BucketFinder::insert(const WordList &word_list) { is_last_bucket ? word_list_size : first_word_index + bucket_size; insert_threads.emplace_back([&, first_word_index, last_word_index] { - thread_bucket.insert(word_list, first_word_index, last_word_index); + bucket.insert(word_list, first_word_index, last_word_index); }); } @@ -72,9 +68,9 @@ WordRefList BucketFinder::find_prefix(std::string_view search_term) const { WordRefList search_results; std::mutex search_results_mutex; - std::vector search_threads; + std::vector threads; for (const auto &bucket : buckets_) { - search_threads.emplace_back([&] { + threads.emplace_back([&] { auto thread_search_results = bucket.find_prefix(search_term); if (!thread_search_results.empty()) { const std::lock_guard result_lock(search_results_mutex); @@ -84,7 +80,7 @@ WordRefList BucketFinder::find_prefix(std::string_view search_term) const { }); } - for (auto &thread : search_threads) { + for (auto &thread : threads) { thread.join(); }