unordered_map的副本是否具有完全相同的存储桶 [英] Does copy of unordered_map will have exactly same buckets

查看:99
本文介绍了unordered_map的副本是否具有完全相同的存储桶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,unordered_map中的存储桶数量在填充unordered_map时意外增加.

As far as I understand, amount of buckets in unordered_map increases accidentally while filling of unordered_map.

如果我执行unordered_map的副本(复制到另一个unordered_map),则可以保证完全相同.但是它们会在同一个桶中吗?桶的数量会一样吗?

If I perform copy of unordered_map (to another unordered_map) it is guaranteed there will be exactly same pairs. But will they be in the same buckets? Will amount of buckets will be the same?

我不知道存储桶的创建机制,也没有找到简短的解释,说明如何在标准中实现它.但是,如果存储桶的数量可能取决于插入,分配等的顺序,那么在复制后,我们可能会获得不同数量的存储桶或其中的存储空间不同(即使项目相同).是真的吗对于boost的实施还是gcc的标准实施?

I don't know bucket's creation mechanism, and didn't find short explanation, how it have to be implemented in standard. But if buckets amount may rely on sequence of insertions, allocation and etc, then after copying we may get different amount of buckets, or different distribution in there (even if items will be the same). Is it true? Both for boost's implementation and for gcc's standard implementation?

推荐答案

在复制unordered_map时,要复制的是最大负载系数,而不是当前"负载系数.

The max load factor, but not the "current" load factor are specified as being copied when an unordered_map is copied.

用于复制构造和复制分配的条目都包括以下内容

Both the entry for copy construction and copy assignment include the following

除了表64的要求外,还复制哈希函数, 谓词和最大负载因子.

In addition to the requirements of Table 64, copies the hash function, predicate, and maximum load factor.

[unord.req]

通常,这意味着存储桶的数量可能不同,因此副本中存储桶中元素的分布也不同.

In general this means there may be a different count of buckets, and thus a different distribution of elements into buckets in a copy.

这篇关于unordered_map的副本是否具有完全相同的存储桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆