我知道我们可以做到这一点std::unordered_map<key, value> my_map;
当我尝试查看它所说的大小zero以及当我尝试查看 bucket_count 时,它给出了11.
我想做的是这样的 std::unordered_map<key, value> my_map(1000);
但我得到错误 expected identifier before numeric constant
我想设置哈希表的大小,以便在向量重新分配内存(从旧内存位置(小)到新内存位置(较大)的值的副本)时不会遇到相同的问题。 Since I have large data of specific size (~100,000) that I want to hash, this motivates me to do preallocation
当我在cppreference 中看到 unordered_map 构造函数时,它需要分配器、散列函数等。我们真的需要提供这么多信息来将散列映射设置为特定大小吗?
与 一样vector,您可以使用reserve():http : //en.cppreference.com/w/cpp/container/unordered_map/reserve
| 归档时间: |
|
| 查看次数: |
5052 次 |
| 最近记录: |