c++11 - 相当于 c++11 的 unordered_map 中的 hash_map::resize()

标签 c++11 hashmap unordered-map

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/

相关文章:

c++ - 动态数值系列

c++ - 通知线程退出

c++11 struct初始化编译错误

c++ - 使用存储在可变数据结构中的字段作为方法参数

c++ - unordered_map 的键

c++ - 整数对散列函数的错误

具有多个键的 Java Map

Java 8 遍历列表并存储在 Map 中

Java HashMap 和底层 values() 集合

c++ - unordered_map 使用什么位散列函数?