C++ hash_map 和 unordered_map 的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1646266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between hash_map and unordered_map?
提问by kidnamedlox
I recently discovered that the implementation of the hash map in C++ will be called unordered_map
.
我最近发现在 C++ 中哈希映射的实现会被调用unordered_map
。
When I looked up why they weren't just using hash_map
, I discovered that apparently there are compatibility issues with the implementation of hash_map
that unordered_map
resolves (more about it here).
当我抬起头,为什么他们不只是使用hash_map
,我发现,显然有与实施的兼容性问题hash_map
是unordered_map
做出决议(更多关于它在这里)。
That wiki page doesn't give much more information so I wondering if anyone knew some of the issues with hash_map
that unordered_map
resolves.
该 wiki 页面没有提供更多信息,所以我想知道是否有人知道hash_map
该unordered_map
解决方案的一些问题。
回答by Stef
Since there was no hash table defined in the C++ standard library, different implementors of the standard libraries would provide a non-standard hash table often named hash_map
. Because these implementations were not written following a standard they all had subtle differences in functionality and performance guarantees.
由于 C++ 标准库中没有定义哈希表,标准库的不同实现者会提供一个非标准的哈希表,通常命名为hash_map
. 因为这些实现不是按照标准编写的,所以它们在功能和性能保证上都有细微的差别。
Starting with C++11a hash table implementation has been added to the C++ standard library standard. It was decided to use an alternate name for the class to prevent collisions with these non-standard implementations and to prevent inadvertent use of the new class by developers who had hash_table
in their code.
从C++11开始,哈希表实现已添加到 C++ 标准库标准中。决定为该类使用一个替代名称,以防止与这些非标准实现发生冲突,并防止开发人员hash_table
在其代码中无意中使用新类。
The chosen alternate name is unordered_map
which really is more descriptive as it hints at the class's map interface and the unordered nature of its elements.
所选择的替代名称unordered_map
确实更具描述性,因为它暗示了类的地图界面及其元素的无序性质。