When should I choose one over the other?
Are there any pointers that you would recommend for using the right STL containers?
When should I choose one over the other? Are there any pointers that you
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
hash_setis an extension that is not part of the C++ standard. Lookups should be O(1) rather than O(log n) forset, so it will be faster in most circumstances.Another difference will be seen when you iterate through the containers.
setwill deliver the contents in sorted order, whilehash_setwill be essentially random (Thanks Lou Franco).Edit: The C++11 update to the C++ standard introduced
unordered_setwhich should be preferred instead ofhash_set. The performance will be similar and is guaranteed by the standard. The “unordered” in the name stresses that iterating it will produce results in no particular order.