From 1441a869c2388eca1b7e073c97947e962d1d5c2a Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sat, 23 Mar 2024 12:22:53 +0100 Subject: [PATCH] refactor: clean up --- lib_vector_search/src/bucket_finder.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib_vector_search/src/bucket_finder.cpp b/lib_vector_search/src/bucket_finder.cpp index 03949e1..bb53a0c 100644 --- a/lib_vector_search/src/bucket_finder.cpp +++ b/lib_vector_search/src/bucket_finder.cpp @@ -7,6 +7,8 @@ #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) { @@ -31,6 +33,8 @@ 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) { @@ -47,7 +51,7 @@ void BucketFinder::insert(const WordList &word_list) { std::vector insert_threads; for (auto bucket_index = 0; bucket_index < bucket_count; ++bucket_index) { - auto &bucket = buckets_[bucket_index]; + auto &thread_bucket = buckets_[bucket_index]; const bool is_last_bucket = bucket_index == bucket_count - 1; const size_t first_word_index = bucket_index * bucket_size; @@ -55,7 +59,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] { - bucket.insert(word_list, first_word_index, last_word_index); + thread_bucket.insert(word_list, first_word_index, last_word_index); }); } @@ -68,9 +72,9 @@ WordRefList BucketFinder::find_prefix(std::string_view search_term) const { WordRefList search_results; std::mutex search_results_mutex; - std::vector threads; + std::vector search_threads; for (const auto &bucket : buckets_) { - threads.emplace_back([&] { + search_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); @@ -80,7 +84,7 @@ WordRefList BucketFinder::find_prefix(std::string_view search_term) const { }); } - for (auto &thread : threads) { + for (auto &thread : search_threads) { thread.join(); }