Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Stats ExploreKeyWords(const KeyWords &key_words, istream &input) {
- vector<future<Stats>> futures;
- for (string line; getline(input, line);) {
- futures.push_back(async([key_words, line] {
- const auto words = Split(line);
- Stats stat;
- for (const auto &key: key_words) {
- stat.word_frequences[key] += std::count(std::execution::par, words.begin(), words.end(), key);
- }
- return stat;
- }));
- }
- Stats result;
- std::for_each(std::execution::par, futures.begin(), futures.end(), [&result](auto &f) { result += f.get(); });
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment