等价于 c++11 的 unordered_map 中的 hash_map::resize()
Equivalent of hash_map::resize() in c++11's 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..
在 hash_map::resize 的 SGI 文档中,我读到它会更改桶的数量,因此 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()));
}
使用rehash
更改桶数。
使用 reserve
容纳与散列 table 的 负载因子 相关的桶数。来自 docs of reserve:
Effectively calls rehash(std::ceil(count / max_load_factor()))
.
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..
在 hash_map::resize 的 SGI 文档中,我读到它会更改桶的数量,因此 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()));
}
使用rehash
更改桶数。
使用 reserve
容纳与散列 table 的 负载因子 相关的桶数。来自 docs of reserve:
Effectively calls
rehash(std::ceil(count / max_load_factor()))
.