本文介绍了hash_map 和 unordered_map 的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近发现C++中hash map的实现会叫unordered_map.

I recently discovered that the implementation of the hash map in C++ will be called unordered_map.

当我查看他们为什么不只是使用 hash_map 时,我发现显然 hash_map 的实现存在兼容性问题,即 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).

那个 wiki 页面没有提供更多信息,所以我想知道是否有人知道 unordered_map 解决的 hash_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.

推荐答案

由于C++标准库中没有定义哈希表,标准库的不同实现者会提供一个非标准的哈希表,通常命名为hash_map.因为这些实现不是按照标准编写的,所以它们在功能和性能保证方面都有细微的差别.

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++11 开始,已添加哈希表实现C++ 标准库标准.决定为该类使用替代名称,以防止与这些非标准实现发生冲突,并防止代码中包含 hash_table 的开发人员无意中使用新类.

Starting with C++11 a 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.

选择的备用名称是 unordered_map,它确实更具描述性,因为它暗示了类的地图界面及其元素的无序性质.

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.

这篇关于hash_map 和 unordered_map 的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 11:00