I have a question with hash_map and map in C++. I understand that map is in STL, but hash_map is not a standard. What’s the difference between the two?
I have a question with hash_map and map in C++. I understand that map
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.
They are implemented in very different ways.
hash_map(unordered_mapin TR1 and Boost; use those instead) use a hash table where the key is hashed to a slot in the table and the value is stored in a list tied to that key.mapis implemented as a balanced binary search tree (usually a red/black tree).An
unordered_mapshould give slightly better performance for accessing known elements of the collection, but amapwill have additional useful characteristics (e.g. it is stored in sorted order, which allows traversal from start to finish).unordered_mapwill be faster on insert and delete than amap.