Advertisement
PaulPaulAga

Untitled

Apr 9th, 2020
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1.  
  2. void SearchServer::AddQueriesStreamMultiThread(istream &query_input,
  3.                                                ostream &search_results_output)
  4. {
  5.     vector<future<vector<string>>> compute_query;
  6.     vector<string> current_batch;
  7.     const size_t batch_size = 1500;
  8.     size_t current_batch_size = 0;
  9.     for (string current_query; getline(query_input, current_query);)
  10.     {
  11.         current_batch.push_back(current_query);
  12.         ++current_batch_size;
  13.         if (current_batch_size == batch_size)
  14.         {
  15.             compute_query.push_back(async([this, current_batch]() {
  16.                 return this->handleQueryVector(current_batch);
  17.             }));
  18.             current_batch.clear();
  19.             current_batch_size = 0;
  20.         }
  21.     }
  22.     if (current_batch_size != 0)
  23.         compute_query.push_back(async([this, &current_batch]() {
  24.             return this->handleQueryVector(current_batch);
  25.         }));
  26.  
  27.     for (auto &thread: compute_query)
  28.         for (const auto &result: thread.get())
  29.             search_results_output << result << endl;
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement