I have this piece of code:
unordered_multiset<int> t;
for (int i = 0; i < 1000000; i++) {
if (i % 10000 == 0)
cout << i << endl;
t.insert(10);
}
So it just puts a lot of equal elements in an unordered_multiset
. But I found out that the more elements I have in hash more slower this works? And I cannot realize the reason. In my opinion after applying the hash function and finding equal element's bucket (since all equal elements are grouped together) stl just put them at the end of bucket.
So what's wrong here?
Udp: I found the the description of unordered_multiset::insert function
Single element insertions: Average case: constant. Worst case: linear in container size.
So the question now can be rephrased as: "Why the worst case is linear"