有没有标准的 C++哈希容器?
我有很多教科书都指出,最初并没有将哈希容器合并到 STL 中,但大多数教科书也说大多数标准库实现确实具有某种形式的哈希容器,因为这是一个已知的缺陷。
这些书不一定是最新的,而且我在谷歌搜索时对什么是真正的“标准”有点困惑,所以:
在这个时候,大多数标准库实现是否提供了一个相当一致的哈希容器,并且如果是,它是否被视为 STL 的一部分?
该容器的“标准”标头是什么? (我猜它是#include
,但以防万一!)。
是否有单独定义一个哈希集和哈希图来使用?
I have a variety of textbooks that note that there wasn't a hash container originally incorporated into the STL, but most also say that most standard library implementations do have some form of hash container since it was a known shortfall.
These books aren't necessarily as up to date as possible, and I got a little confused about what was really "standard" when googling, so:
At this point in time, do most standard library implementations provide a fairly consistent hash container, and if so, is it considered a part of the STL?
What's the "standard" header for this container? (I'm guessing it's #include <hash>
, but just in case!).
Is there a hash set and hash map separately defined for use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
新的标准哈希映射容器称为
unordered_map
。您可以通过#include
将其包含在您的文件中。它是现已批准的标准 C++11 的一部分。在 C++11 之前,您拥有诸如
hash_map
之类的各种东西,这些东西受到一些供应商(广泛?)的支持,因此您可以使用它们,但如果您这样做,您的代码并不是真正可移植的,因为hash_map
不是标准的一部分。现在不应使用hash_map
以及哈希表结构的所有其他特定于供应商的版本。The new standard hash map container is called
unordered_map
. You can include it in your files by#include <unordered_map>
. It is part of the now-approved standard C++11.Before C++11, you had various things like
hash_map
which were (widely?) supported by some vendors so you could use them, but if you did, your code wasn't really portable becausehash_map
wasn't part of the standard.hash_map
and all the other vendor-specific versions of a hash table structure shouldn't be used now.请参阅 C++11 类型:
unordered_map
unordered_set
unordered_multimap
unordered_multiset
See C++11 types:
unordered_map
unordered_set
unordered_multimap
unordered_multiset
当前标准(03)中没有,您可以使用
boost::unordered_map
。在新标准中将有std::unordered_map
。Not in the current standard (03), you can use
boost::unordered_map
. In the new standard there will be,std::unordered_map
.新的 C++11 标准具有哈希等效容器。目前它们不在大多数实现中,但它们已经在标准库的 TR1 扩展中,并随一些实现一起提供。
The new C++11 standard has hash-equivalent containers. They are not in most implementations at this time, but they have been in TR1 extensions to the standard library, which are provided with some implementations.
TR1命名空间中有一些哈希容器。例如,请参阅此处的简短介绍:http://drdobbs.com/184402066
There are some hash containers in the TR1 namespace. See for example a short intro here: http://drdobbs.com/184402066