map vs. hash_map in C++

前端 未结 6 646
一生所求
一生所求 2020-12-07 07:37

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

6条回答
  •  一整个雨季
    2020-12-07 07:50

    The C++ spec doesn't say exactly what algorithm you must use for the STL containers. It does, however, put certain constraints on their performance, which rules out the use of hash tables for map and other associative containers. (They're most commonly implemented with red/black trees.) These constraints require better worst-case performance for these containers than hash tables can deliver.

    Many people really do want hash tables, however, so hash-based STL associative containers have been a common extension for years. Consequently, they added unordered_map and such to later versions of the C++ standard.

提交回复
热议问题