简体   繁体   English

clear() 是否影响 std::unordered_set 的桶数?

[英]Does clear() affect the bucket count of std::unordered_set?

There are plenty of answers with std::vector , but what about std::unordered_set ? std::vector有很多答案,但是std::unordered_set呢?

My real question (closely related) is this;我真正的问题(密切相关)是这样的; is it efficient to reuse the same unordered set by clearing it before each use, if I reserve what I know to be a reasonable size beforehand?如果我事先保留了我知道的合理大小,通过在每次使用前清除它来重用相同的无序集是否有效?

Formal answer is: it depends on implementation.正式的答案是:这取决于实现。

Informal answer is: unordered_set inside has an array (of some kind) of buckets, and most likely the implementation is consistent with vector , so this array won't be deleted when clear() is called.非正式的回答是: unordered_set里面有一个(某种)bucket 的数组,并且很可能实现与vector一致,因此调用clear()时不会删除这个数组。 So calling clear() most likely will give some benefit.所以调用clear()很可能会带来一些好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM