People think that computer science is the art of geniuses but the actual reality is the opposite, just many people doing things that build on each other, like a wall of mini stones. Donald Knuth
unordered_multiset are equivalent to Unordered Set with one difference. It allows different elements to have equivalent values.
![]() |
Do not maintain the insertion order and organized into buckets. |
![]() |
The elements in an unordered_multiset cannot be modified. |
![]() |
Elements with equivalent values are grouped together in the same bucket. |
#include "stdafx.h" #include < iostream > #include < string > #include < unordered_set > using namespace std; using namespace stdext; int _tmain(int argc, _TCHAR* argv[]) { unordered_multiset < string > myums = { "father", "mother", "son", "daughter", "son", "son" }; cout << "Display items from unordered_multiset:{"; for (auto it = myums.begin(); it != myums.end(); ++it) cout << *it << " "; cout << "}" << endl << endl; cout << "unordered_multiset buckets contain:\n"; for (unsigned i = 0; i < myums.bucket_count(); ++i) { cout << "bucket #" << i << " contains:"; for (auto local_it = myums.begin(i); local_it != myums.end(i); ++local_it) cout << " " << *local_it; cout << endl; } return 0; }
Display items from unordered_multiset:{son son son father mother daughter } unordered_multiset buckets contain: bucket #0 contains: bucket #1 contains: daughter bucket #2 contains: mother bucket #3 contains: son son son father bucket #4 contains: bucket #5 contains: bucket #6 contains: bucket #7 contains:
unordered_multimap is based on a hash table, which uses hash and equality operations to organize the nodes without sorting them. When you want hash based implementation, you can use unordered_multimap.
0 Comments