I am iterating through a std::unordered_map
std::unordered_map<int, char> mp;
mp[0] = 'a';
int i = 1;
for(auto it=mp.begin();it!=mp.end();it++)
{
cout<<it->second<<" ";
mp[i++] = (char)(97+i);
}
Output
a
Now as a new element is being added at the end of each iteration I assumed this would run into an infinite loop however as shown in the output it did not.
- By seeing this link I realized that the iteration of
std::unordered_map
occurs by iterating through the buckets. So does that mean that in my code, the new value inserted into my mappair<int,char>(1,'b')
was hashed to a bucket before the bucket of the valuepair<int,char>(0,'a')
" - If yes then what happens if load factor exceeds
max_load_factor
and the unordered_map rehashes? Does the whole unordered_map iterate again?