I have a map with pair as its index. I found that it takes a lot of time to visit elements in it. I want to know whether there are some ways to accelerate the process? My code is as follow:
std::vector words;
...to generate a words vector...
std::map<std::pair<std::string, std::string>, int> wordCountMap;
wordsSize = words.size()
for(int i = 0; i < wordsSize; ++i){
for(int j = i + 1; j < min(i + e, wordsSize); ++j){
std::pair<std::string, std::string> pk = words[i] < words[j] ? std::make_pair(words[i], words[j]) : std::make_pair(words[j], words[i]);
wordPairCountMap[pk] = wordPairCountMap.find(pk) != wordPairCountMap.end() ? wordPairCountMap[pk] + 1 : 1;
}
}
I found that the construction of the pair indexed map cost a lot of time. How can I optimize it?