Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void SearchServer::AddQueriesStreamMultiThread(istream &query_input,
- ostream &search_results_output)
- {
- vector<future<vector<string>>> compute_query;
- vector<string> current_batch;
- const size_t batch_size = 1500;
- size_t current_batch_size = 0;
- for (string current_query; getline(query_input, current_query);)
- {
- current_batch.push_back(current_query);
- ++current_batch_size;
- if (current_batch_size == batch_size)
- {
- compute_query.push_back(async([this, current_batch]() {
- return this->handleQueryVector(current_batch);
- }));
- current_batch.clear();
- current_batch_size = 0;
- }
- }
- if (current_batch_size != 0)
- compute_query.push_back(async([this, ¤t_batch]() {
- return this->handleQueryVector(current_batch);
- }));
- for (auto &thread: compute_query)
- for (const auto &result: thread.get())
- search_results_output << result << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement