gpt4 book ai didi

c++ - boost::unordered_multimap 是否调整大小

转载 作者:行者123 更新时间:2023-11-30 05:12:36 25 4
gpt4 key购买 nike

在初始化 boost::unordered_multimap 时,我们定义 HashMap 的大小。

explicit unordered_multimap(size_type n = implementation-defined, 
hasher const& hf = hasher(),
key_equal const& eq = key_equal(),
allocator_type const& a = allocator_type());

Constructs an empty container with at least n buckets, using hf as the hash function, eq as the key equality predicate, a as the allocator and a maximum load factor of 1.0.

当 hash map 快满时,它会调整大小吗?它似乎没有这样的API。它会自动执行吗?定义 unordered_multimap 大小的最佳做法是什么?

最佳答案

它会自动完成,as documented :

The number of buckets can be automatically increased by a call to insert, or as the result of calling rehash.

但请记住,收缩时它不会重新散列:Why does C++11/Boost `unordered_map` not rehash when erasing?

您可以通过手动强制降低负载系数并将最大负载系数设置得足够高(http://www.boost.org/doc/libs/1_64_0/doc/html/boost/unordered_map.html#idp776321712-bbhttp://www.boost.org/doc/libs/1_64_0/doc/html/boost/unordered_map.html#idp776318000-bb)来防止不必要的重新散列

关于c++ - boost::unordered_multimap 是否调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44449561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com