In below codes,
std::map<Key,Int>::iterator p;
p = randomTable[chunk].find(value);
if (p != randomTable[chunk].end()) {
} else {
}
How does the p != randomTable[chunk].end() works?
Does this mean, for all elements in randomTable that is not the last (end()) element?
find(value) will return the same as end() if value is not in the map. So if value is in the map, you’ll go into the “if” branch, and if not, you’ll go into the “else” branch.
end() isn’t actually a member of the map – it points to the “element after the end”. This is a slightly odd idea, but it probably helps to think that the search has looked at all of the elements in the map and failed to find the one you’re looking for.