BOOST :: UNOREDED_MAP-需要为哈希std :: set< int'指定自定义哈希功能?
我想使用boost :: unordered_map< key,value>
,其中key
是std :: set&lt< int>
。由于一组整数不是内置类型,所以我以为我必须提供自己的哈希功能(或者,我正在考虑使用 boost的hash_range )。
但是,现在我尝试初始化这样的哈希地图,既不提供哈希功能也不是平等谓词 - 而GCC并未抱怨。这里发生了什么? Boost是否足够聪明,可以单独使用Hash STL容器?这会比我使用自定义哈希功能的情况慢吗?如何使用boost :: Hash_range
?
提前致谢。
I'd like use boost::unordered_map<key,value>
, where key
is a std::set<int>
. Since a set of integers is no built-in type, I assumed I had to supply my own hash function (or, rather, I was thinking of using boost's hash_range).
However, now I tried initializing a hash map like this, neither supplying a hash function nor an equality predicate -- and gcc didn't complain. What is happening here? Is boost clever enough to hash STL containers all on its own? Is this going to be slower than if I used a custom hash function? What about using boost::hash_range
?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 Boost 文档:
并且,根据 的文档Boost.Hash,为标准容器提供了默认的哈希函数。因此,已经有一个为
std::set
编写的哈希函数。 Boost 哈希容器不够智能,无法知道如何自动对集合进行哈希处理,但它们足够智能,可以使用已提供的实现。希望这有帮助!
According to the Boost documentation:
And, according to the documentation for Boost.Hash, default hash functions are provided for the standard containers. Consequently, there is already a hash function written for
std::set
. The Boost hash containers aren't smart enough to know how to hash sets automatically, but they are smart enough to use the implementation that's already provided.Hope this helps!
默认
boost :: hash&lt;键&gt;
函数正在选择。根据其文档http://www.boost.org/doc/doc/html/hash.html
/www.boost.org/doc/html/hash.html 哈希STL容器。除非您知道
set
的特定用例,否则我怀疑提供自己的哈希功能是否有任何意义。The default
boost::hash< Key >
function is being chosen. According to its documentationhttp://www.boost.org/doc/html/hash.html
So yes, boost is clever enough to hash STL containers. Unless you know something specific of your particular use case of
set
, I doubt there is any point in providing your own hash function.