#ifndef PARALLELSEARCH_HPP #define PARALLELSEARCH_HPP #include #include "WordList.hpp" class ParallelSearch { public: // Iterator type used inside the class typedef WordList::const_iterator Iterator; // Type of the search result typedef std::vector ResultList; class SearchJob { public: // initially reserve n entries in result-list (to cut down number of reallocations) enum { INITIAL_RESERVE = 128 }; // Create partial search job for provided range SearchJob(Iterator begin, Iterator end, const std::string& pattern); // Destructor ~SearchJob() {} // run the search job and collect results internally void execute(); // return the result const ResultList& get_result() const { return result_; }; private: // pattern to search for std::string pattern_; // start of search range Iterator begin_; // end of search range Iterator end_; // result of the search ResultList result_; }; // construct parallel search by splitting the search range across SearchJob objects ParallelSearch(unsigned workerCount, Iterator begin, Iterator end, const std::string& pattern); // Destructor ~ParallelSearch() {} // run the search workers and collect results void run(); // return the result const ResultList& get_result() const { return result_; }; private: // jobs to execute std::vector jobList_; // result of the search ResultList result_; }; #endif