AlexSSH

Untitled

Feb 19th, 2023
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. Stats ExploreKeyWords(const KeyWords &key_words, istream &input) {
  2.     vector<future<Stats>> futures;
  3.     for (string line; getline(input, line);) {
  4.         futures.push_back(async([key_words, line] {
  5.             const auto words = Split(line);
  6.             Stats stat;
  7.             for (const auto &key: key_words) {
  8.                 stat.word_frequences[key] += std::count(std::execution::par, words.begin(), words.end(), key);
  9.             }
  10.             return stat;
  11.         }));
  12.     }
  13.     Stats result;
  14.     std::for_each(std::execution::par, futures.begin(), futures.end(), [&result](auto &f) { result += f.get(); });
  15.     return result;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment