c++11 的 unordered_map
中的 hash_map::resize(n)
等价于什么?早期的 hash_map 大小调整用于支持:void resize(size_type n)
,将存储桶计数增加到至少 n。
最佳答案
相当于 rehash :
Sets the number of buckets in the container to n or more.
rehash 指定桶的数量,而保留如docs :
Sets the number of buckets in the container (bucket_count) to the most appropriate to contain at least n elements..
在 SGI 文档中 hash_map::resize我读到它改变了存储桶的数量,因此 IMO 重新哈希是合适的。但 hash_map 不是标准的,因此不同的实现可能会以不同的方式实现它。
另一件事是,reserve 实际上是使用 rehash 实现的,在 gcc 5.3 中它看起来如下:
void
reserve(std::size_t __n)
{
__hashtable* __this = static_cast<__hashtable*>(this);
__this->rehash(__builtin_ceil(__n / max_load_factor()));
}
关于c++11 - 相当于 c++11 的 unordered_map 中的 hash_map::resize(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36688283/