c++ - 如果有插入/删除/重新哈希操作,unordered_map 是否复制/释放包含的对象?

标签 c++ boost stl

我想在 unordered_map 中存储小对象,只是想知道如果有任何插入/删除/重新哈希操作,它是否可以复制/释放包含的对象?我认为 unordered_map 使用链接列表来存储键/值对,它不应该需要复制/释放像 vector 这样的对象来重新分配内存。

最佳答案

C++11 标准:§ 23.2.5/8

The elements of an unordered associative container are organized into buckets. Keys with the same hash code appear in the same bucket. The number of buckets is automatically increased as elements are added to an unordered associative container, so that the average number of elements per bucket is kept below a bound. Rehashing invalidates iterators, changes ordering between elements, and changes which buckets elements appear in, but does not invalidate pointers or references to elements. For unordered_multiset and unordered_multimap, rehashing preserves the relative ordering of equivalent elements.

unordered_map的简写,
如果是插入/删除操作,

  • 当重新散列发生时,所有迭代器都会失效,但引用不受影响。

关于c++ - 如果有插入/删除/重新哈希操作,unordered_map 是否复制/释放包含的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8664295/

相关文章:

c++ - 对我构建的类使用 STL sort() func

c++ - 使用 std::shared_ptr<std::vector> 而不是 boost::shared_array 有意义吗?

c++ - 聚合 ‘BIGNUM foo’ 类型不完整,无法定义

c++ - 创建第二个AppWindow并显示它

c++ - cppcms 大量未解析的外部符号

c++ - 使用 boost::spirit::qi 重新合成中间值

c++ - 使用Boost::Asio套接字读取500ms

c++ - 如何为 std::list 重载 std::remove ?

c++ - 将 asio 与 accepter.async_accept 一起使用时出现 boost::bind 错误

c++ - 将一串数字解析为整数 vector 的最快方法